aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/migrator-test.js
blob: ece95b9f6963214ae8e013e52b62a51561af7e1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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)
  })
})