Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Starting to add tests for the migration code
Browse files Browse the repository at this point in the history
- search engine migration
- autofill
- stub out remaining items

Auditors: @NejcZdovc
  • Loading branch information
bsclifton committed Aug 28, 2017
1 parent 51b68e7 commit c7a2b0f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ module.exports.runPreMigrations = (data) => {
})
data.autofill.creditCards = creditCards
}
if (data.autofill.addresses.guid) {
if (data.autofill.addresses && data.autofill.addresses.guid) {
let guids = []
data.autofill.addresses.guid.forEach((guid) => {
if (typeof guid === 'object') {
Expand All @@ -500,7 +500,7 @@ module.exports.runPreMigrations = (data) => {
})
data.autofill.addresses.guid = guids
}
if (data.autofill.creditCards.guid) {
if (data.autofill.creditCards && data.autofill.creditCards.guid) {
let guids = []
data.autofill.creditCards.guid.forEach((guid) => {
if (typeof guid === 'object') {
Expand Down
72 changes: 72 additions & 0 deletions test/unit/app/sessionStoreTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ describe('sessionStore unit tests', function () {
return new Promise((resolve, reject) => {
resolve()
})
},
translation: (token) => {
return token
}
}

Expand Down Expand Up @@ -963,6 +966,75 @@ describe('sessionStore unit tests', function () {
})
})

describe('runPreMigrations', function () {
let data
let runPreMigrations

before(function () {
const defaultAppState = sessionStore.defaultAppState()
// NOTE: it's important that this merges similar to loadAppState
// It's immutable since runPreMigrations does delete values
data = Immutable.fromJS(Object.assign({}, defaultAppState, {
autofill: {
addresses: ['guid1', 'guid2'],
creditCards: ['guid1', 'guid2']
},
settings: {
[settings.DEFAULT_SEARCH_ENGINE]: 'content/search/google.xml'
}
}))
runPreMigrations = sessionStore.runPreMigrations(data.toJS())
})

describe('when `data.autofill` exists', function () {
describe('migrate `data.autofill.addresses` from array to map', function () {
it('copies the values into a field called guid', function () {
const oldValue = data.getIn(['autofill', 'addresses'])
const newValue = runPreMigrations.autofill.addresses.guid
assert.deepEqual(newValue, oldValue.toJS())
})
it('converts the value to a map', function () {
assert.equal(Array.isArray(runPreMigrations.autofill.addresses), false)
})
})

describe('migrate `data.autofill.creditCards` from array to map', function () {
it('copies the values into a field called guid', function () {
const oldValue = data.getIn(['autofill', 'creditCards'])
const newValue = runPreMigrations.autofill.creditCards.guid
assert.deepEqual(newValue, oldValue.toJS())
})
it('converts the value to a map', function () {
assert.equal(Array.isArray(runPreMigrations.autofill.creditCards), false)
})
})

describe('updates guids in `data.autofill.addresses.guid` if they are an object', function () {
// TODO:
})

describe('updates guids in `data.autofill.creditCards.guid` if they are an object', function () {
// TODO:
})
})

describe('when `data.settings` exists', function () {
describe('migrate search engine settings', function () {
it('updates settings.DEFAULT_SEARCH_ENGINE if set to google.xml', function () {
const newValue = runPreMigrations.settings[settings.DEFAULT_SEARCH_ENGINE]
assert.equal(newValue, 'Google')
})
it('updates settings.DEFAULT_SEARCH_ENGINE if set to duckduckgo.xml', function () {
// this one has to run a second time, since it modifies the same value as test before
const dataCopy = data.setIn(['settings', settings.DEFAULT_SEARCH_ENGINE], 'content/search/duckduckgo.xml')
const output = sessionStore.runPreMigrations(dataCopy.toJS())
const newValue = output.settings[settings.DEFAULT_SEARCH_ENGINE]
assert.equal(newValue, 'DuckDuckGo')
})
})
})
})

describe('runPostMigrations', function () {
describe('sites trailing slash migration', function () {
it('site with trailing slash', function () {
Expand Down

1 comment on commit c7a2b0f

@NejcZdovc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.