Skip to content

Commit ed18eac

Browse files
committed
test(microservices): rework tests for number values
1 parent 2faca66 commit ed18eac

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

packages/microservices/test/utils/msvc.util.spec.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
import * as Interfaces from './../../interfaces';
12
import { expect } from 'chai';
23
import { MsvcUtil } from '../../utils/msvc.util';
34

5+
function equalTest<R>(testPatterns: Interfaces.MsPattern[], expectedResults: R[]) {
6+
testPatterns.forEach((testPattern: Interfaces.MsPattern, index: number) => {
7+
const testData = MsvcUtil.transformPatternToRoute(testPattern);
8+
expect(testData).to.be.equal(expectedResults[index]);
9+
});
10+
}
11+
412
describe('MsvcUtil', () => {
513

614
describe('transformPatternToRoute', () => {
15+
describe(`when gets 'number' value`, () => {
16+
it(`should return the 'number' what is wrapped in a string`, () => {
17+
const testPatterns = [
18+
1, 150, 12345,
19+
];
20+
const expectedResults = [
21+
`1`, `150`, `12345`,
22+
];
23+
24+
equalTest(testPatterns, expectedResults);
25+
});
26+
});
27+
728
describe(`gets 'string' value`, () => {
829
it(`should return the same string`, () => {
930
const testPattern1 = `pattern1`;
@@ -101,18 +122,18 @@ describe('MsvcUtil', () => {
101122
});
102123
});
103124

104-
describe(`gets value with incorrect type (no string/JSON)`, () => {
125+
describe(`when gets value with incorrect type (no string/number/JSON)`, () => {
105126
it(`should throw error`, () => {
106-
const testPattern1 = 150;
107-
const testPattern2 = null;
108-
const testPattern3 = undefined;
109-
const testPattern4 = Symbol(213);
127+
const testPatterns = [
128+
null,
129+
undefined,
130+
Symbol(213),
131+
];
110132
const errMsg = `The pattern must be of type 'string' or 'object'!`;
111133

112-
expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern1)).to.throw(errMsg);
113-
expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern2)).to.throw(errMsg);
114-
expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern3)).to.throw(errMsg);
115-
expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern4)).to.throw(errMsg);
134+
testPatterns.forEach((testPattern: any) => {
135+
expect(MsvcUtil.transformPatternToRoute.bind(null, testPattern)).to.throw(errMsg);
136+
});
116137
});
117138
});
118139
});

0 commit comments

Comments
 (0)