mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Require migration tests from 33 on (#8121)
This commit is contained in:
parent
cf85f56989
commit
f5f6f7b2d5
54
test/unit/migrations/040-test.js
Normal file
54
test/unit/migrations/040-test.js
Normal file
@ -0,0 +1,54 @@
|
||||
import assert from 'assert'
|
||||
import migration40 from '../../../app/scripts/migrations/040'
|
||||
|
||||
describe('migration #40', function () {
|
||||
|
||||
it('should update the version metadata', function (done) {
|
||||
const oldStorage = {
|
||||
'meta': {
|
||||
'version': 39,
|
||||
},
|
||||
'data': {},
|
||||
}
|
||||
|
||||
migration40.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.meta, {
|
||||
'version': 40,
|
||||
})
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
|
||||
it('should delete ProviderApprovalController storage key', function (done) {
|
||||
const oldStorage = {
|
||||
'meta': {},
|
||||
'data': {
|
||||
'ProviderApprovalController': {},
|
||||
'foo': 'bar',
|
||||
},
|
||||
}
|
||||
|
||||
migration40.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.data, { foo: 'bar' })
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
|
||||
it('should do nothing if no ProviderApprovalController storage key', function (done) {
|
||||
const oldStorage = {
|
||||
'meta': {},
|
||||
'data': { foo: 'bar' },
|
||||
}
|
||||
|
||||
migration40.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.data, { foo: 'bar' })
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
})
|
97
test/unit/migrations/041-test.js
Normal file
97
test/unit/migrations/041-test.js
Normal file
@ -0,0 +1,97 @@
|
||||
import assert from 'assert'
|
||||
import migration41 from '../../../app/scripts/migrations/041'
|
||||
|
||||
describe('migration #41', function () {
|
||||
|
||||
it('should update the version metadata', function (done) {
|
||||
const oldStorage = {
|
||||
'meta': {
|
||||
'version': 40,
|
||||
},
|
||||
'data': {},
|
||||
}
|
||||
|
||||
migration41.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.meta, {
|
||||
'version': 41,
|
||||
})
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
|
||||
it('should rename autoLogoutTimeLimit storage key', function (done) {
|
||||
const oldStorage = {
|
||||
meta: {},
|
||||
data: {
|
||||
PreferencesController: {
|
||||
preferences: {
|
||||
autoLogoutTimeLimit: 42,
|
||||
fizz: 'buzz',
|
||||
},
|
||||
bar: 'baz',
|
||||
},
|
||||
foo: 'bar',
|
||||
},
|
||||
}
|
||||
|
||||
migration41.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.data, {
|
||||
PreferencesController: {
|
||||
preferences: {
|
||||
autoLockTimeLimit: 42,
|
||||
fizz: 'buzz',
|
||||
},
|
||||
bar: 'baz',
|
||||
},
|
||||
foo: 'bar',
|
||||
})
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
|
||||
it('should do nothing if no PreferencesController key', function (done) {
|
||||
const oldStorage = {
|
||||
meta: {},
|
||||
data: {
|
||||
foo: 'bar',
|
||||
},
|
||||
}
|
||||
|
||||
migration41.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.data, {
|
||||
foo: 'bar',
|
||||
})
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
|
||||
it('should do nothing if no preferences key', function (done) {
|
||||
const oldStorage = {
|
||||
meta: {},
|
||||
data: {
|
||||
PreferencesController: {
|
||||
bar: 'baz',
|
||||
},
|
||||
foo: 'bar',
|
||||
},
|
||||
}
|
||||
|
||||
migration41.migrate(oldStorage)
|
||||
.then((newStorage) => {
|
||||
assert.deepEqual(newStorage.data, {
|
||||
PreferencesController: {
|
||||
bar: 'baz',
|
||||
},
|
||||
foo: 'bar',
|
||||
})
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
})
|
@ -1,7 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import assert from 'assert'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import pify from 'pify'
|
||||
import Migrator from '../../../app/scripts/lib/migrator'
|
||||
import liveMigrations from '../../../app/scripts/migrations'
|
||||
|
||||
@ -43,19 +42,45 @@ const firstTimeState = {
|
||||
|
||||
describe('migrations', function () {
|
||||
describe('liveMigrations require list', function () {
|
||||
it('should include all the migrations', async function () {
|
||||
const fileNames = await pify((cb) => fs.readdir('./app/scripts/migrations/', cb))()
|
||||
const migrationNumbers = fileNames.reduce((agg, filename) => {
|
||||
const name = filename.split('.')[0]
|
||||
if (/^\d+$/.test(name)) {
|
||||
agg.push(name)
|
||||
}
|
||||
return agg
|
||||
}, []).map((num) => parseInt(num))
|
||||
|
||||
let migrationNumbers
|
||||
|
||||
before(function () {
|
||||
const fileNames = fs.readdirSync('./app/scripts/migrations/')
|
||||
migrationNumbers = fileNames
|
||||
.reduce((acc, filename) => {
|
||||
const name = filename.split('.')[0]
|
||||
if (/^\d+$/.test(name)) {
|
||||
acc.push(name)
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
.map((num) => parseInt(num))
|
||||
})
|
||||
|
||||
it('should include all migrations', function () {
|
||||
migrationNumbers.forEach((num) => {
|
||||
const migration = liveMigrations.find((m) => m.version === num)
|
||||
assert(migration, `migration should be include in the index missing migration ${num}`)
|
||||
assert(migration, `migration not included in 'migrations/index.js': ${num}`)
|
||||
})
|
||||
})
|
||||
|
||||
it('should have tests for all migrations', function () {
|
||||
const fileNames = fs.readdirSync('./test/unit/migrations/')
|
||||
const testNumbers = fileNames
|
||||
.reduce((acc, filename) => {
|
||||
const name = filename.split('-test.')[0]
|
||||
if (/^\d+$/.test(name)) {
|
||||
acc.push(name)
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
.map((num) => parseInt(num))
|
||||
|
||||
migrationNumbers.forEach((num) => {
|
||||
if (num >= 33) {
|
||||
assert.ok(testNumbers.includes(num), `no test found for migration: ${num}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user