base.test.js
3.13 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import expect from 'expect.js';
import muk from 'muk';
import Base from '../../src/lib/directive/base';
import rewire from 'rewire';
describe('base.js', function() {
describe('init', function() {
it('init expect have reproc & proc', function() {
let base = new Base()
expect(base.reproc).to.eql({});
expect(base.proc).to.eql({});
});
});
describe('send', function() {
it('input find expect OK', function(done) {
let base = new Base();
base.reproc.test = function(callback) {
callback('test');
return 'test';
};
let connect = {
send: function(order) {
return order;
},
client: {
remoteAddress: '1.1.1.1'
}
};
base.send(connect, {
input: 'test'
}, function(order) {
expect(order).to.be('test');
done();
})
});
});
describe('receive', function() {
it('input "" expect undefined ', function() {
let base = new Base();
expect(base.receive('', '')).to.be(undefined);
});
it('input [] epxect undefined', function() {
let base = new Base();
expect(base.receive('', [])).to.be(undefined);
});
it('input [111] expect ok', function() {
let base = new Base();
base.proc.test = function() {
return 'test';
}
Base.__set__('locateOrder', function() {
return {
name: 'test'
}
});
Base.__set__('returnProc', function() {
return 'test';
});
Base.__set__('orders', {
'test': {
output: 'test'
}
});
expect(base.receive('', [111])).to.be('test');
});
it('input [111] expect ok', function() {
let base = new Base();
Base.__set__('locateOrder', function() {
return {
name: 'test'
}
});
Base.__set__('returnProc', function() {
return 'test';
});
Base.__set__('orders', {
'test': {
output: 'test'
}
});
expect(base.receive('', [111])).to.be('test');
});
});
describe('procFunc', function() {
it('input "" client test expect test', function() {
let base = new Base();
Base.__set__('returnProc', function() {
return 'test';
});
Base.__set__('orders', {
'test': {
output: 'test'
}
});
expect(base.procFunc('', {
remoteAddress: '1.1.1.1'
}, 'test')).to.be('test');
});
});
});