-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathembedder.spec.js
86 lines (76 loc) · 2.59 KB
/
embedder.spec.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require('isomorphic-fetch');
require('mocha');
const {assert} = require('chai');
const rimraf = require("rimraf");
const ecc = require('eosjs-ecc');
const fs = require('fs');
const Embedder = require('./embedder');
// const HOST = 'http://10.0.0.3:8091';
const HOST = 'http://staging.embed.get-scatter.com';
const PROOFS = ['EOS57fs1Mi7RrMChZ9GsxsCYqG22y9PjnmCnakLMALuA8qM3qKcwG'];
const FILES = {
getDefaultPath: async () => './test_data',
getFilesForDirectory: async (path) => {
return fs.readdirSync(path);
},
saveFile: async (path, name, data, encoding = 'utf-8') => {
return new Promise(resolve => {
try { fs.writeFileSync(`${path}/${name}`, data, encoding); resolve(true); }
catch(e) { console.error('Error saving file', e); resolve(false); }
})
},
openFile: async (path, encoding = 'utf-8') => {
return new Promise(resolve => {
try { fs.readFile(path, encoding, (err, data) => { if(err) return resolve(null); resolve(data); }); }
catch(e) { console.error('Error opening file', e); resolve(null); }
})
},
existsOrMkdir: async (path) => {
if(!fs.existsSync(path)) fs.mkdirSync(path, { recursive: true });
return true;
},
exists: async path => {
return fs.existsSync(path);
}
};
const NOTIFIER = (title, text) => console.log('Got notification of', title, text);
const PROMPTER = async (title, text) => {
console.log('Got prompt for', title, text);
return true;
};
const SIGNATURE_CHECKER = (hashed, signed) => PROOFS[0];
const HASHER = x => ecc.sha256(x);
const PROGRESS_EVENT = (msg) => console.log(msg);
describe('embedder', () => {
it('should clean up any previous test data', done => {
new Promise(async () => {
await new Promise(r => rimraf('./test_data', () => r(true)))
assert(!await FILES.exists('./test_data'), "Test data was not removed");
done();
})
})
it('should instantiate properly', done => {
new Promise(async () => {
Embedder.init('12.0.0', 'Bridge', PROOFS, FILES, HASHER, NOTIFIER, PROMPTER, SIGNATURE_CHECKER, PROGRESS_EVENT);
done();
})
})
it('should check if there is a local version [fail test]', done => {
new Promise(async () => {
assert(!await Embedder.hasLocalVersion(), 'There was a local version when there should NOT have been.')
done();
})
})
it('should cache files locally', done => {
new Promise(async () => {
assert(await Embedder.check(), 'There was an error caching local files.');
done();
})
});
it('should check if there is a local version', done => {
new Promise(async () => {
assert(await Embedder.hasLocalVersion(), 'There was NOT a local version when there should have been.')
done();
})
})
});