Skip to content

Commit

Permalink
Add some simple tests
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Colley <[email protected]>
  • Loading branch information
hannalaakso and NickColley committed Nov 25, 2019
1 parent 399dd8e commit fb8a221
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
76 changes: 76 additions & 0 deletions __tests__/spec/data-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-env jest */
const request = require('supertest')
const app = require('../../server.js')
const path = require('path')
const fs = require('fs')
const utils = require('../../lib/utils.js')

jest.setTimeout(30000)

function readFile (pathFromRoot) {
return fs.readFileSync(path.join(__dirname, '../../' + pathFromRoot), 'utf8')
}
/**
*
*/
describe('The data storage', () => {
// check session-data defaults file exists

it.skip('file should exist', (done) => {
const sessionDataDefaultsFile = readFile('app/data/session-data-defaults.js')

request(app)
.get(sessionDataDefaultsFile)
.expect('Content-Type', /application\/javascript; charset=UTF-8/)
// .expect(200)
.end(function (err, res) {
if (err) {
done(err)
} else {
done()
}
})
})

describe('storeData function', () => {
it('should add input data into session data', async () => {
let initialSessionData = {
'driver-name': 'Dr Emmett Brown'
}

const inputData = {
'vehicle-registration': 'OUTATIME'
}

utils.storeData(inputData, initialSessionData)

expect(initialSessionData).toEqual({
'driver-name': 'Dr Emmett Brown',
'vehicle-registration': 'OUTATIME'
})
})

it('should merge object into object', async () => {
let initialSessionData = {
vehicle: {
'driver-name': 'Dr Emmett Brown'
}
}

const inputData = {
vehicle: {
registration: 'OUTATIME'
}
}

utils.storeData(inputData, initialSessionData)

expect(initialSessionData).toEqual({
vehicle: {
'driver-name': 'Dr Emmett Brown',
registration: 'OUTATIME'
}
})
})
})
})
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ exports.matchMdRoutes = function (req, res) {
}

// Store data from POST body or GET query in session
var storeData = function (input, data) {
function storeData (input, data) {
// Value we store to indicate unchecked checkboxes. See `auto-store-data.js`
var uncheckedValue = '_unchecked'

Expand Down Expand Up @@ -257,6 +257,8 @@ var storeData = function (input, data) {
}
}

exports.storeData = storeData

// Get session default data from file
let sessionDataDefaults = {}

Expand Down

0 comments on commit fb8a221

Please sign in to comment.