1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Create test for Migrator

This commit is contained in:
frankiebee 2017-05-11 19:47:58 +02:00
parent 6c01b26845
commit 8421cf9cce

View File

@ -0,0 +1,41 @@
const assert = require('assert')
const clone = require('clone')
const Migrator = require('../../app/scripts/lib/migrator/')
const migrations = [
{
version: 1,
migrate: (data) => {
// clone the data just like we do in migrations
const clonedData = clone(data)
clonedData.meta.version = 1
return Promise.resolve(clonedData)
},
},
{
version: 2,
migrate: (data) => {
const clonedData = clone(data)
clonedData.meta.version = 2
return Promise.resolve(clonedData)
},
},
{
version: 3,
migrate: (data) => {
const clonedData = clone(data)
clonedData.meta.version = 3
return Promise.resolve(clonedData)
},
},
]
const versionedData = {meta: {version: 0}, data:{hello:'world'}}
describe('Migrator', () => {
const migrator = new Migrator({ migrations })
it('migratedData version should be version 3', (done) => {
migrator.migrateData(versionedData)
.then((migratedData) => {
assert.equal(migratedData.meta.version, migrations[2].version)
done()
}).catch(done)
})
})