Skip to content

Commit 5763e2f

Browse files
committed
refactor(microservices): use equalTest function instead of repeated tests
1 parent ed18eac commit 5763e2f

1 file changed

Lines changed: 78 additions & 80 deletions

File tree

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

Lines changed: 78 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -25,99 +25,97 @@ describe('MsvcUtil', () => {
2525
});
2626
});
2727

28-
describe(`gets 'string' value`, () => {
28+
describe(`when gets 'string' value`, () => {
2929
it(`should return the same string`, () => {
30-
const testPattern1 = `pattern1`;
31-
const testPattern2 = 'PaTteRn2';
32-
const testPattern3 = '3PaTteRn';
33-
34-
const testData1 = MsvcUtil.transformPatternToRoute(testPattern1);
35-
const testData2 = MsvcUtil.transformPatternToRoute(testPattern2);
36-
const testData3 = MsvcUtil.transformPatternToRoute(testPattern3);
30+
const testPatterns = [
31+
`pattern1`, 'PaTteRn2', '3PaTteRn',
32+
];
3733

38-
expect(testData1).to.be.equal(testPattern1);
39-
expect(testData2).to.be.equal(testPattern2);
40-
expect(testData3).to.be.equal(testPattern3);
34+
equalTest(testPatterns, testPatterns);
4135
});
4236
});
4337

44-
describe(`gets 'JSON' value`, () => {
38+
describe(`when gets 'JSON' value`, () => {
4539
describe(`without nested JSON (1 level)`, () => {
4640
it(`should return correct route`, () => {
47-
const testPattern1 = {
48-
controller: 'app',
49-
use: 'getHello'
50-
};
51-
const testPattern2 = {
52-
use: 'getHello',
53-
controller: 'app'
54-
};
55-
const testPattern3 = {
56-
service: 'one',
57-
use: 'getHello',
58-
controller: 'app'
59-
};
60-
61-
const testData1 = MsvcUtil.transformPatternToRoute(testPattern1);
62-
const testData2 = MsvcUtil.transformPatternToRoute(testPattern2);
63-
const testData3 = MsvcUtil.transformPatternToRoute(testPattern3);
64-
65-
expect(testData1).to.be.equal(`{controller:app/use:getHello}`);
66-
expect(testData2).to.be.equal(`{controller:app/use:getHello}`);
67-
expect(testData3).to.be.equal(`{controller:app/service:one/use:getHello}`);
41+
const testPatterns = [
42+
{
43+
controller: 'app',
44+
use: 'getHello',
45+
},
46+
{
47+
use: 'getHello',
48+
controller: 'app',
49+
},
50+
{
51+
service: 'one',
52+
use: 'getHello',
53+
controller: 'app',
54+
id: 150,
55+
},
56+
];
57+
58+
const expectedResults = [
59+
`{controller:app/use:getHello}`,
60+
`{controller:app/use:getHello}`,
61+
`{controller:app/id:150/service:one/use:getHello}`,
62+
];
63+
64+
equalTest(testPatterns, expectedResults);
6865
});
6966
});
70-
describe(`use 'JSON' value with nested JSON (2 levels)`, () => {
67+
describe(`with nested JSON (2 levels)`, () => {
7168
it(`should return correct route`, () => {
72-
const testPattern1 = {
73-
controller: 'app',
74-
use: { p1: 'path1', p2: 'path2' }
75-
};
76-
const testPattern2 = {
77-
use: { p1: 'path1', p2: 'path2' },
78-
controller: 'app'
79-
};
80-
const testPattern3 = {
81-
service: 'one',
82-
use: { p1: 'path1', p2: 'path2' },
83-
controller: 'app'
84-
};
85-
86-
const testData1 = MsvcUtil.transformPatternToRoute(testPattern1);
87-
const testData2 = MsvcUtil.transformPatternToRoute(testPattern2);
88-
const testData3 = MsvcUtil.transformPatternToRoute(testPattern3);
89-
90-
expect(testData1).to.be.equal(`{controller:app/use:{p1:path1/p2:path2}}`);
91-
expect(testData2).to.be.equal(`{controller:app/use:{p1:path1/p2:path2}}`);
92-
expect(testData3).to.be.equal(`{controller:app/service:one/use:{p1:path1/p2:path2}}`);
69+
const testPatterns = [
70+
{
71+
controller: 'app',
72+
use: { p1: 'path1', p2: 'path2' },
73+
},
74+
{
75+
use: { p1: 'path1', p2: 'path2' },
76+
controller: 'app',
77+
},
78+
{
79+
service: 'one',
80+
use: { p1: 'path1', p2: 'path2', id: 160 },
81+
controller: 'app',
82+
},
83+
];
84+
85+
const expectedResults = [
86+
`{controller:app/use:{p1:path1/p2:path2}}`,
87+
`{controller:app/use:{p1:path1/p2:path2}}`,
88+
`{controller:app/service:one/use:{id:160/p1:path1/p2:path2}}`,
89+
];
90+
91+
equalTest(testPatterns, expectedResults);
9392
});
9493
});
95-
describe(`use 'JSON' value with nested JSON (3 levels)`, () => {
94+
describe(`with nested JSON (3 levels)`, () => {
9695
it(`should return correct route`, () => {
97-
const testPattern1 = {
98-
controller: 'app',
99-
use: { p1: 'path1', p2: { pp1: 'ppath1' } }
100-
};
101-
const testPattern2 = {
102-
use: { p1: 'path1' },
103-
controller: { p2: 'path2' },
104-
};
105-
const testPattern3 = {
106-
service: 'one',
107-
use: { p1: 'path1', p2: { pp1: 'ppath1' } },
108-
controller: { p1: { pp1: 'ppath1' } }
109-
};
110-
111-
const testData1 = MsvcUtil.transformPatternToRoute(testPattern1);
112-
const testData2 = MsvcUtil.transformPatternToRoute(testPattern2);
113-
const testData3 = MsvcUtil.transformPatternToRoute(testPattern3);
114-
115-
expect(testData1)
116-
.to.be.equal(`{controller:app/use:{p1:path1/p2:{pp1:ppath1}}}`);
117-
expect(testData2)
118-
.to.be.equal(`{controller:{p2:path2}/use:{p1:path1}}`);
119-
expect(testData3)
120-
.to.be.equal(`{controller:{p1:{pp1:ppath1}}/service:one/use:{p1:path1/p2:{pp1:ppath1}}}`);
96+
const testPatterns = [
97+
{
98+
controller: 'app',
99+
use: { p1: 'path1', p2: { pp1: 'ppath1' } },
100+
},
101+
{
102+
use: { p1: 'path1' },
103+
controller: { p2: 'path2' },
104+
},
105+
{
106+
service: 'one',
107+
use: { p1: 'path1', p2: { pp1: 'ppath1' } },
108+
controller: { p1: { pp1: 'ppath1', id: 180 } },
109+
},
110+
];
111+
112+
const expectedResults = [
113+
`{controller:app/use:{p1:path1/p2:{pp1:ppath1}}}`,
114+
`{controller:{p2:path2}/use:{p1:path1}}`,
115+
`{controller:{p1:{id:180/pp1:ppath1}}/service:one/use:{p1:path1/p2:{pp1:ppath1}}}`,
116+
];
117+
118+
equalTest(testPatterns, expectedResults);
121119
});
122120
});
123121
});

0 commit comments

Comments
 (0)