-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore_test.js
70 lines (60 loc) · 2.7 KB
/
restore_test.js
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
66
67
68
69
70
const unitJS = require('unit.js')
const { v4 } = require('uuid')
const { ExtraPayload } = require('./types')
const { EventTypes } = require('./event')
const EventTransaction = require('./eventTransaction')
const { NewVirtualPathWatcher } = require('./watcherVirtual')
const { CreateFileNodeWithTransactions, RestoreWatcherWithTransactions } = require('./restore')
const generateTransactionsBytes = () => {
const uUIDs = [v4(), v4(), v4(), v4(), v4()],
eTxnS = [
new EventTransaction('test-1', EventTypes.Create, uUIDs[0]),
new EventTransaction('s-test-1', EventTypes.Create, uUIDs[1], uUIDs[0]),
new EventTransaction('ss-test-1', EventTypes.Create, uUIDs[2], uUIDs[1]),
new EventTransaction('s-test-2', EventTypes.Create, uUIDs[3], uUIDs[0]),
new EventTransaction('s-test-2-rename', EventTypes.Rename, uUIDs[3], uUIDs[0]),
new EventTransaction('s-test-2-rename', EventTypes.Move, uUIDs[3], uUIDs[0]),
new EventTransaction('s-test-3', EventTypes.Create, uUIDs[4], uUIDs[0]),
new EventTransaction('s-test-3', EventTypes.Remove, uUIDs[4], uUIDs[0])
],
encodedTxnS = []
for (let i = 0; i < eTxnS.length; i++) {
const { encoded } = eTxnS[i].Encode()
encodedTxnS.push(encoded)
}
return encodedTxnS
}
describe('Restore Tests', () => {
it('CreateFileNodeWithTransactions', () => {
const txnS = generateTransactionsBytes()
const { fileNode, error } = CreateFileNodeWithTransactions(txnS)
unitJS.value(error).isNull()
unitJS.assert.equal('test-1', fileNode.Name)
unitJS.assert.equal('s-test-1', fileNode.Subs[0].Name)
})
it('Should be error CreateFileNodeWithTransactions is invalid transactions', () => {
const { fileNode, error } = CreateFileNodeWithTransactions(['tx1', 'tx2'])
unitJS.value(error).isInstanceOf(Error)
unitJS.value(fileNode).isNull()
})
it('RestoreWatcherWithTransactions', () => {
const root = 'fs-shadow',
rootUUID = v4(),
txnS = generateTransactionsBytes()
const { watcher, error } = NewVirtualPathWatcher(rootUUID, root, new ExtraPayload(v4(), true))
unitJS.value(error).isNull()
const err = RestoreWatcherWithTransactions(txnS, watcher)
unitJS.value(err).isNull()
unitJS.assert.equal('test-1', watcher.FileTree.Name)
unitJS.assert.equal('s-test-1', watcher.FileTree.Subs[0].Name)
})
it('Should be error RestoreWatcherWithTransactions is invalid transactions', () => {
const root = 'fs-shadow',
rootUUID = v4(),
txnS = ['tx1']
const { watcher, error } = NewVirtualPathWatcher('', root, new ExtraPayload(v4(), true))
unitJS.value(error).isNull()
const err = RestoreWatcherWithTransactions(txnS, watcher)
unitJS.value(err).isInstanceOf(Error)
})
})