Skip to content

Commit

Permalink
Migration 033 to delete NoticeController from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
tmashuang committed Apr 1, 2019
1 parent d6efee2 commit 1553ffd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/scripts/migrations/033.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// next version number
const version = 33

/*
Cleans up notices and assocated notice controller code
*/

const clone = require('clone')

module.exports = {
version,

migrate: async function (originalVersionedData) {
const versionedData = clone(originalVersionedData)
versionedData.meta.version = version
const state = versionedData.data
const newState = transformState(state)
versionedData.data = newState
return versionedData
},
}

function transformState (state) {
const newState = state
// transform state here
if (state.NoticeController) {
delete newState.NoticeController
}
return newState
}
2 changes: 2 additions & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ module.exports = [
require('./029'),
require('./030'),
require('./031'),
require('./032'),
require('./033'),
]
40 changes: 40 additions & 0 deletions test/unit/migrations/033-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const assert = require('assert')
const migration33 = require('../../../app/scripts/migrations/033')

describe('Migration to delete notice controller', () => {
const oldStorage = {
'meta': {},
'data': {
'NoticeController': {
'noticesList': [
{
id: 0,
read: false,
date: 'Thu Feb 09 2017',
title: 'Terms of Use',
body: 'notice body',
},
{
id: 2,
read: false,
title: 'Privacy Notice',
body: 'notice body',
},
{
id: 4,
read: false,
title: 'Phishing Warning',
body: 'notice body',
},
],
},
},
}

it('removes notice controller from state', () => {
migration33.migrate(oldStorage)
.then(newStorage => {
assert.equal(newStorage.data.NoticeController, undefined)
})
})
})

0 comments on commit 1553ffd

Please sign in to comment.