modems.js
6.24 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* eslint-disable no-console */
/* global describe it */
const should = require('should');
const modems = require('../lib/modems');
describe('#modems', () => {
describe('#enabledModems', () => {
it('should return correctly', () => {
const test1 = modems.enabledModems([
{
name: 'SENDER-AS13',
disabled: false,
outgoing: true,
imsi: null,
prefix: [],
},
]);
test1.should.ok();
});
});
describe('#prefixes', () => {
it('should return correctly', () => {
const config = [
{
name: 'XL1',
outgoing: true,
prefix: ['0818', '081'],
},
{
name: 'TSEL1',
outgoing: true,
prefix: ['0812', '0811'],
},
{
name: 'TSEL2',
outgoing: true,
prefix: ['0812', '0811'],
},
{
name: 'ISAT1',
outgoing: true,
prefix: ['0815', '0816'],
},
];
const prefixes = modems.prefixes(config);
prefixes[0].prefix.should.equal('62811');
prefixes[1].prefix.should.equal('62812');
prefixes[2].prefix.should.equal('62815');
prefixes[3].prefix.should.equal('62816');
prefixes[4].prefix.should.equal('62818');
prefixes[5].prefix.should.equal('6281');
prefixes[0].modems[0].should.equal('TSEL1');
prefixes[0].modems[1].should.equal('TSEL2');
prefixes[1].modems[0].should.equal('TSEL1');
prefixes[1].modems[1].should.equal('TSEL2');
prefixes[2].modems[0].should.equal('ISAT1');
prefixes[3].modems[0].should.equal('ISAT1');
prefixes[4].modems[0].should.equal('XL1');
prefixes[5].modems[0].should.equal('XL1');
});
});
describe('#findPrefixForNumber', () => {
it('should return correct prefix', () => {
const config = [
{
name: 'XL1',
outgoing: true,
prefix: ['0818', '081'],
},
{
name: 'TSEL1',
outgoing: true,
prefix: ['0812', '0811'],
},
{
name: 'TSEL2',
outgoing: true,
prefix: ['0812', '0811'],
},
{
name: 'ISAT1',
outgoing: true,
prefix: ['0815', '0816'],
},
{
name: 'FREE1',
outgoing: true,
prefix: [],
},
{
name: 'FREE2',
outgoing: true,
prefix: [],
},
];
const prefixes = modems.prefixes(config);
modems.findPrefixForNumber('628188188', prefixes).prefix.should.equal('62818');
modems.findPrefixForNumber('08188188', prefixes).prefix.should.equal('62818');
modems.findPrefixForNumber('62812812', prefixes).prefix.should.equal('62812');
modems.findPrefixForNumber('62810810', prefixes).prefix.should.equal('6281');
should.not.exists(modems.findPrefixForNumber('6221212121', prefixes));
});
});
describe('#randomModemByPrefix', () => {
const config = [
{
name: 'XL1',
outgoing: true,
prefix: ['0818', '081'],
},
{
name: 'TSEL1',
outgoing: true,
prefix: ['0812', '0811'],
},
{
name: 'TSEL2',
outgoing: true,
prefix: ['0812', '0811'],
},
{
name: 'ISAT1',
outgoing: true,
prefix: ['0815', '0816'],
},
{
name: 'ISAT2',
outgoing: false,
prefix: ['0815', '0816'],
},
{
name: 'FREE1',
outgoing: true,
prefix: [],
},
{
name: 'FREE2',
outgoing: true,
prefix: [],
},
];
const loopCount = 100;
it('should return correctly for XL', () => {
for (let i = 0; i < loopCount; i += 1) {
modems.randomModemByPrefix('6281881818', config).name.should.equal('XL1');
}
});
it('should return correctly for TSEL', () => {
for (let i = 0; i < loopCount; i += 1) {
modems.randomModemByPrefix('62812812', config).name.should.equalOneOf('TSEL1', 'TSEL2');
}
});
it('should return correctly for INDOSAT', () => {
for (let i = 0; i < loopCount; i += 1) {
modems.randomModemByPrefix('62815815', config).name.should.equal('ISAT1');
}
});
it('should return correctly for UNKNOWN PREFIX', () => {
for (let i = 0; i < loopCount; i += 1) {
modems.randomModemByPrefix('628888888', config).name.should.equalOneOf('FREE1', 'FREE2');
}
});
it('should handle UNKNOWN PREFIX without free modem', () => {
// eslint-disable-next-line no-shadow
const config = [
{
name: 'XL1',
outgoing: true,
prefix: ['0818', '081'],
},
{
name: 'FREE1',
outgoing: false,
prefix: [],
},
{
name: 'FREE2',
outgoing: false,
prefix: [],
},
];
should.not.exists(modems.randomModemByPrefix('628888888', config));
});
});
});