-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
65 lines (57 loc) · 1.55 KB
/
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
'use strict';
var request = require('supertest');
var should = require('should');
var app = require('./app.js');
var crypto = require('crypto');
var loki = require('lokijs');
app.db = new loki('test-db.json');
describe('hkvstore', () => {
before(function(done) {
app.db.loadDatabase({}, done);
});
beforeEach(function() {
app.db
.getCollection('hashes')
.removeWhere(() => {return true;}); // Clear the db
});
it('should get the correct json for a value that is set', (done) => {
var json = {
'This is': 'JSON'
};
var hash = crypto.createHash('sha256')
.update(JSON.stringify(json))
.digest('hex');
// Let's set the JSON
request(app)
.post('/')
.send(json)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(201, {
'hash': hash
}, (err) => {
should.not.exist(err);
// Let's confirm that it is there
request(app)
.get('/' + hash)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, json, done);
});
});
it('should not get any data for a value that is not set', (done) => {
var json = {
'This is': 'JSON'
};
var hash = crypto.createHash('sha256')
.update(JSON.stringify(json))
.digest('hex');
request(app)
.get('/' + hash)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(404, {
'description': 'Hash-JSON pair not found.'
}, done);
});
});