test.js
1.95 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
66
67
68
69
70
71
72
73
74
75
'use strict';
const seenreq = require('../../');
const expect = require('chai').expect;
describe('seenreq integration testing', ()=>{
let ctx = require('../fixtures/test_case.json');
let seen;
describe('basic usage', ()=>{
beforeEach((done)=>{
seen = new seenreq();
seen.initialize().then(done()).catch( (e) => {
console.error(e);
done();
});
});
it('should normalize and find duplicate requests ',(done)=>{
//url to be normalized
expect(seen.normalize(ctx.opts[0])).to.eql({
sign: 'GET http://www.google.com/\r\n',
options: {}
});
//request options to be normalized
expect(seen.normalize(ctx.opts[1])).to.eql({
sign: 'GET http://www.google.com/\r\n',
options: {rupdate: false}
});
seen.initialize()
.then( ()=> seen.exists(ctx.opts[0]) )
.then( (rst)=>{
//false if ask for a `request` never see
expect(rst).to.be.false;
return seen.exists(ctx.opts[1]);
}).then( (rst)=>{
//true if got same `request`
expect(rst).to.be.true;
//true if ask for a duplicate `request`
return seen.exists(ctx.opts[0]);
}).then( (rst)=>{
expect(rst).to.be.true;
return seen.exists(ctx.opts[2]);
}).then( (rst)=>{
expect(rst).to.be.false;
return seen.exists(ctx.opts[3]);
}).then( (rst)=>{
expect(rst).to.be.false;
return seen.exists(ctx.opts[4]);
}).then( (rst)=>{
expect(rst).to.be.false;
return seen.exists(ctx.opts[6]);
}).then( (rst)=>{
expect(rst).to.be.false;
return seen.exists(ctx.opts[5]);
}).then( (rst)=>{
expect(rst).to.be.true;
return seen.exists(ctx.opts[4]);
}).then((rst) => {
expect(rst).to.be.true;
return seen.exists([ctx.opts[0], ctx.opts[3], ctx.opts[6], ctx.opts[4]]);
}).then((rst)=>{
expect(rst).to.eqls([true, true, true, true]);
done();
}).catch(function (e){
console.error(e);
expect(e).to.be.false;
done();
});
});
});
});