forked from BoostIO/BoostNote-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrateFromV6Storage-test.js
More file actions
64 lines (56 loc) · 2.16 KB
/
Copy pathmigrateFromV6Storage-test.js
File metadata and controls
64 lines (56 loc) · 2.16 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const test = require('ava')
const migrateFromV6Storage = require('browser/main/lib/dataApi/migrateFromV6Storage')
global.document = require('jsdom').jsdom('<body></body>')
global.window = document.defaultView
global.navigator = window.navigator
const Storage = require('dom-storage')
const localStorage = window.localStorage = global.localStorage = new Storage(null, { strict: true })
const path = require('path')
const TestDummy = require('../fixtures/TestDummy')
const sander = require('sander')
const CSON = require('@rokt33r/season')
const _ = require('lodash')
const os = require('os')
const dummyStoragePath = path.join(os.tmpdir(), 'test/migrate-test-storage')
test.beforeEach((t) => {
let dummyData = t.context.dummyData = TestDummy.dummyLegacyStorage(dummyStoragePath)
console.log('init count', dummyData.notes.length)
localStorage.setItem('storages', JSON.stringify([dummyData.cache]))
})
test.serial('Migrate legacy storage into v1 storage', (t) => {
return Promise.resolve()
.then(function test () {
return migrateFromV6Storage(dummyStoragePath)
})
.then(function assert (data) {
// Check the result. It must be true if succeed.
t.true(data)
// Check all notes migrated.
let dummyData = t.context.dummyData
let noteDirPath = path.join(dummyStoragePath, 'notes')
let fileList = sander.readdirSync(noteDirPath)
t.is(dummyData.notes.length, fileList.length)
let noteMap = fileList
.map((filePath) => {
return CSON.readFileSync(path.join(noteDirPath, filePath))
})
dummyData.notes
.forEach(function (targetNote) {
t.true(_.find(noteMap, {title: targetNote.title, folder: targetNote.folder}) != null)
})
// Check legacy folder directory is removed
dummyData.json.folders
.forEach(function (folder) {
try {
sander.statSync(dummyStoragePath, folder.key)
t.fail('Folder still remains. ENOENT error must be occured.')
} catch (err) {
t.is(err.code, 'ENOENT')
}
})
})
})
test.after.always(function () {
localStorage.clear()
sander.rimrafSync(dummyStoragePath)
})