command-parser.js
2.22 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
"use strict";
/* global describe it */
const should = require('should');
const commandParser = require('../lib/command-parser');
describe('#command-parser', function() {
describe('#splitToken', function() {
it('should return correct tokens', function() {
commandParser.splitToken('SAL.1234')[0].should.equal('SAL');
commandParser.splitToken('SAL')[0].should.equal('SAL');
commandParser.splitToken('SAL.1234')[1].should.equal('1234');
commandParser.splitToken('SAL 1234')[1].should.equal('1234');
})
it('should handle repeating splitter', function() {
commandParser.splitToken('SAL 1234')[1].should.equal('1234');
})
it('should handle empty message', function() {
should.not.exists(commandParser.splitToken(''));
should.not.exists(commandParser.splitToken());
})
})
describe('#extractCommand', function() {
it('should handle array of token as input', function() {
commandParser.extractCommand(['SAL', '1234']).should.equal('SAL');
})
it('should handle message string as input', function() {
commandParser.extractCommand('SAL.1234').should.equal('SAL');
commandParser.extractCommand('SAL 1234').should.equal('SAL');
commandParser.extractCommand('SAL 1234').should.equal('SAL');
})
it('should handle empty message', function() {
should.not.exists(commandParser.extractCommand(''));
should.not.exists(commandParser.extractCommand());
})
})
describe('#extractCommandGroup', function() {
it('should return correct command group from a message string', function() {
commandParser.extractCommandGroup('SAL.1234').should.equal('balance');
})
it('should return correct command group from an array of tokens', function() {
commandParser.extractCommandGroup(['SAL', '1234']).should.equal('balance');
})
it('should handle invalid message', function() {
should.not.exists(commandParser.extractCommandGroup());
should.not.exists(commandParser.extractCommandGroup(''));
})
})
})