-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration 033 to delete NoticeController from storage
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,6 @@ module.exports = [ | |
require('./029'), | ||
require('./030'), | ||
require('./031'), | ||
require('./032'), | ||
require('./033'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
}) |