forked from BoostIO/BoostNote-Legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveNote-test.js
More file actions
65 lines (55 loc) · 2.23 KB
/
Copy pathmoveNote-test.js
File metadata and controls
65 lines (55 loc) · 2.23 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
65
const test = require('ava')
const moveNote = require('browser/main/lib/dataApi/moveNote')
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 os = require('os')
const CSON = require('@rokt33r/season')
const storagePath = path.join(os.tmpdir(), 'test/move-note')
const storagePath2 = path.join(os.tmpdir(), 'test/move-note2')
test.beforeEach((t) => {
t.context.storage1 = TestDummy.dummyStorage(storagePath)
t.context.storage2 = TestDummy.dummyStorage(storagePath2)
localStorage.setItem('storages', JSON.stringify([t.context.storage1.cache, t.context.storage2.cache]))
})
test.serial('Move a note', (t) => {
const storageKey1 = t.context.storage1.cache.key
const folderKey1 = t.context.storage1.json.folders[0].key
const note1 = t.context.storage1.notes[0]
const note2 = t.context.storage1.notes[1]
const storageKey2 = t.context.storage2.cache.key
const folderKey2 = t.context.storage2.json.folders[0].key
return Promise.resolve()
.then(function doTest () {
return Promise.all([
moveNote(storageKey1, note1.key, storageKey1, folderKey1),
moveNote(storageKey1, note2.key, storageKey2, folderKey2)
])
})
.then(function assert (data) {
let data1 = data[0]
let data2 = data[1]
let jsonData1 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
t.is(jsonData1.folder, folderKey1)
t.is(jsonData1.title, note1.title)
let jsonData2 = CSON.readFileSync(path.join(storagePath2, 'notes', data2.key + '.cson'))
t.is(jsonData2.folder, folderKey2)
t.is(jsonData2.title, note2.title)
try {
CSON.readFileSync(path.join(storagePath, 'notes', note2.key + '.cson'))
t.fail('The old note should be deleted.')
} catch (err) {
t.is(err.code, 'ENOENT')
}
})
})
test.after(function after () {
localStorage.clear()
sander.rimrafSync(storagePath)
sander.rimrafSync(storagePath2)
})