-
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.
Adding migration for support notification removal
- Loading branch information
Showing
5 changed files
with
116 additions
and
22 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
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,30 @@ | ||
import { cloneDeep } from 'lodash'; | ||
|
||
const version = 60; | ||
const SUPPORT_NOTIFICATION_KEY = 2; | ||
const SUPPORT_NOTIFICATION_DATE = '2020-08-31'; | ||
|
||
/** | ||
* Removes the support survey notification | ||
*/ | ||
export default { | ||
version, | ||
async migrate(originalVersionedData) { | ||
const versionedData = cloneDeep(originalVersionedData); | ||
versionedData.meta.version = version; | ||
const state = versionedData.data; | ||
const newState = transformState(state); | ||
versionedData.data = newState; | ||
return versionedData; | ||
}, | ||
}; | ||
|
||
function transformState(state) { | ||
if ( | ||
state?.NotificationController?.notifications[SUPPORT_NOTIFICATION_KEY] | ||
.date === SUPPORT_NOTIFICATION_DATE | ||
) { | ||
delete state.NotificationController.notifications[SUPPORT_NOTIFICATION_KEY]; | ||
} | ||
return state; | ||
} |
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,75 @@ | ||
import { strict as assert } from 'assert'; | ||
import migration60 from './060'; | ||
|
||
describe('migration #60', function () { | ||
it('should update the version metadata', function (done) { | ||
const oldStorage = { | ||
meta: { | ||
version: 59, | ||
}, | ||
data: {}, | ||
}; | ||
|
||
migration60 | ||
.migrate(oldStorage) | ||
.then((newStorage) => { | ||
assert.deepEqual(newStorage.meta, { | ||
version: 60, | ||
}); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
|
||
it('prunes the support notification', function (done) { | ||
const oldStorage = { | ||
meta: {}, | ||
data: { | ||
NotificationController: { | ||
notifications: { | ||
1: { | ||
id: 1, | ||
date: '2021-03-17', | ||
image: { | ||
src: 'images/mobile-link-qr.svg', | ||
height: '230px', | ||
width: '230px', | ||
placeImageBelowDescription: true, | ||
}, | ||
}, | ||
2: { | ||
id: 2, | ||
date: '2020-08-31', | ||
}, | ||
3: { | ||
id: 3, | ||
date: '2021-03-08', | ||
}, | ||
4: { | ||
id: 4, | ||
date: '2021-05-11', | ||
image: { | ||
src: 'images/source-logos-bsc.svg', | ||
width: '100%', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
migration60 | ||
.migrate(oldStorage) | ||
.then((newStorage) => { | ||
const { notifications } = newStorage.data.NotificationController; | ||
const notificationKeys = Object.keys(notifications); | ||
// Assert support notification is removed | ||
assert.equal(notificationKeys.length, 3); | ||
notificationKeys.forEach((key) => { | ||
assert.notEqual(notifications[key].date, '2020-08-31'); | ||
}); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); |
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
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