mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 01:39:44 +01:00
meta - create a migration template
This commit is contained in:
parent
79932b7e17
commit
b9243cd8b9
29
app/scripts/migrations/template.js
Normal file
29
app/scripts/migrations/template.js
Normal file
@ -0,0 +1,29 @@
|
||||
// next version number
|
||||
const version = 0
|
||||
|
||||
/*
|
||||
|
||||
description of migration and what it does
|
||||
|
||||
*/
|
||||
|
||||
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
|
||||
return newState
|
||||
}
|
17
test/unit/migrations/template-test.js
Normal file
17
test/unit/migrations/template-test.js
Normal file
@ -0,0 +1,17 @@
|
||||
const assert = require('assert')
|
||||
const migrationTemplate = require('../../../app/scripts/migrations/template')
|
||||
const properTime = (new Date()).getTime()
|
||||
const storage = {
|
||||
meta: {},
|
||||
data: {},
|
||||
}
|
||||
|
||||
describe('storage is migrated successfully', () => {
|
||||
it('should work', (done) => {
|
||||
migrationTemplate.migrate(storage)
|
||||
.then((migratedData) => {
|
||||
assert.equal(migratedData.meta.version, 0)
|
||||
done()
|
||||
}).catch(done)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user