@@ -4,106 +4,116 @@ import { MsvcUtil } from '../../utils/msvc.util';
44describe ( 'MsvcUtil' , ( ) => {
55
66 describe ( 'transformPatternToRoute' , ( ) => {
7- it ( `use 'string' value` , ( ) => {
8- const testPattern1 = `pattern1` ;
9- const testPattern2 = 'PaTteRn2' ;
10- const testPattern3 = '3PaTteRn' ;
7+ describe ( `gets 'string' value` , ( ) => {
8+ it ( `should return the same string` , ( ) => {
9+ const testPattern1 = `pattern1` ;
10+ const testPattern2 = 'PaTteRn2' ;
11+ const testPattern3 = '3PaTteRn' ;
1112
12- const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
13- const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
14- const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
13+ const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
14+ const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
15+ const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
1516
16- expect ( testData1 ) . to . be . equal ( testPattern1 ) ;
17- expect ( testData2 ) . to . be . equal ( testPattern2 ) ;
18- expect ( testData3 ) . to . be . equal ( testPattern3 ) ;
17+ expect ( testData1 ) . to . be . equal ( testPattern1 ) ;
18+ expect ( testData2 ) . to . be . equal ( testPattern2 ) ;
19+ expect ( testData3 ) . to . be . equal ( testPattern3 ) ;
20+ } ) ;
1921 } ) ;
2022
21- it ( `use 'JSON' value without nested JSON (1 level)` , ( ) => {
22- const testPattern1 = {
23- controller : 'app' ,
24- use : 'getHello'
25- } ;
26- const testPattern2 = {
27- use : 'getHello' ,
28- controller : 'app'
29- } ;
30- const testPattern3 = {
31- service : 'one' ,
32- use : 'getHello' ,
33- controller : 'app'
34- } ;
23+ describe ( `gets 'JSON' value` , ( ) => {
24+ describe ( `without nested JSON (1 level)` , ( ) => {
25+ it ( `should return correct route` , ( ) => {
26+ const testPattern1 = {
27+ controller : 'app' ,
28+ use : 'getHello'
29+ } ;
30+ const testPattern2 = {
31+ use : 'getHello' ,
32+ controller : 'app'
33+ } ;
34+ const testPattern3 = {
35+ service : 'one' ,
36+ use : 'getHello' ,
37+ controller : 'app'
38+ } ;
3539
36- const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
37- const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
38- const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
40+ const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
41+ const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
42+ const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
3943
40- expect ( testData1 ) . to . be . equal ( `{controller:app/use:getHello}` ) ;
41- expect ( testData2 ) . to . be . equal ( `{controller:app/use:getHello}` ) ;
42- expect ( testData3 ) . to . be . equal ( `{controller:app/service:one/use:getHello}` ) ;
43- } ) ;
44-
45- it ( `use 'JSON' value with nested JSON (2 levels)` , ( ) => {
46- const testPattern1 = {
47- controller : 'app' ,
48- use : { p1 : 'path1' , p2 : 'path2' }
49- } ;
50- const testPattern2 = {
51- use : { p1 : 'path1' , p2 : 'path2' } ,
52- controller : 'app'
53- } ;
54- const testPattern3 = {
55- service : 'one' ,
56- use : { p1 : 'path1' , p2 : 'path2' } ,
57- controller : 'app'
58- } ;
44+ expect ( testData1 ) . to . be . equal ( `{controller:app/use:getHello}` ) ;
45+ expect ( testData2 ) . to . be . equal ( `{controller:app/use:getHello}` ) ;
46+ expect ( testData3 ) . to . be . equal ( `{controller:app/service:one/use:getHello}` ) ;
47+ } ) ;
48+ } ) ;
49+ describe ( `use 'JSON' value with nested JSON (2 levels)` , ( ) => {
50+ it ( `should return correct route` , ( ) => {
51+ const testPattern1 = {
52+ controller : 'app' ,
53+ use : { p1 : 'path1' , p2 : 'path2' }
54+ } ;
55+ const testPattern2 = {
56+ use : { p1 : 'path1' , p2 : 'path2' } ,
57+ controller : 'app'
58+ } ;
59+ const testPattern3 = {
60+ service : 'one' ,
61+ use : { p1 : 'path1' , p2 : 'path2' } ,
62+ controller : 'app'
63+ } ;
5964
60- const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
61- const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
62- const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
63-
64- expect ( testData1 ) . to . be . equal ( `{controller:app/use:{p1:path1/p2:path2}}` ) ;
65- expect ( testData2 ) . to . be . equal ( `{controller:app/use:{p1:path1/p2:path2}}` ) ;
66- expect ( testData3 ) . to . be . equal ( `{controller:app/service:one/use:{p1:path1/p2:path2}}` ) ;
67- } ) ;
65+ const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
66+ const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
67+ const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
6868
69- it ( `use 'JSON' value with nested JSON (3 levels)` , ( ) => {
70- const testPattern1 = {
71- controller : 'app' ,
72- use : { p1 : 'path1' , p2 : { pp1 : 'ppath1' } }
73- } ;
74- const testPattern2 = {
75- use : { p1 : 'path1' } ,
76- controller : { p2 : 'path2' } ,
77- } ;
78- const testPattern3 = {
79- service : 'one' ,
80- use : { p1 : 'path1' , p2 : { pp1 : 'ppath1' } } ,
81- controller : { p1 : { pp1 : 'ppath1' } }
82- } ;
69+ expect ( testData1 ) . to . be . equal ( `{controller:app/use:{p1:path1/p2:path2}}` ) ;
70+ expect ( testData2 ) . to . be . equal ( `{controller:app/use:{p1:path1/p2:path2}}` ) ;
71+ expect ( testData3 ) . to . be . equal ( `{controller:app/service:one/use:{p1:path1/p2:path2}}` ) ;
72+ } ) ;
73+ } ) ;
74+ describe ( `use 'JSON' value with nested JSON (3 levels)` , ( ) => {
75+ it ( `should return correct route` , ( ) => {
76+ const testPattern1 = {
77+ controller : 'app' ,
78+ use : { p1 : 'path1' , p2 : { pp1 : 'ppath1' } }
79+ } ;
80+ const testPattern2 = {
81+ use : { p1 : 'path1' } ,
82+ controller : { p2 : 'path2' } ,
83+ } ;
84+ const testPattern3 = {
85+ service : 'one' ,
86+ use : { p1 : 'path1' , p2 : { pp1 : 'ppath1' } } ,
87+ controller : { p1 : { pp1 : 'ppath1' } }
88+ } ;
8389
84- const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
85- const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
86- const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
90+ const testData1 = MsvcUtil . transformPatternToRoute ( testPattern1 ) ;
91+ const testData2 = MsvcUtil . transformPatternToRoute ( testPattern2 ) ;
92+ const testData3 = MsvcUtil . transformPatternToRoute ( testPattern3 ) ;
8793
88- expect ( testData1 )
89- . to . be . equal ( `{controller:app/use:{p1:path1/p2:{pp1:ppath1}}}` ) ;
90- expect ( testData2 )
91- . to . be . equal ( `{controller:{p2:path2}/use:{p1:path1}}` ) ;
92- expect ( testData3 )
93- . to . be . equal ( `{controller:{p1:{pp1:ppath1}}/service:one/use:{p1:path1/p2:{pp1:ppath1}}}` ) ;
94+ expect ( testData1 )
95+ . to . be . equal ( `{controller:app/use:{p1:path1/p2:{pp1:ppath1}}}` ) ;
96+ expect ( testData2 )
97+ . to . be . equal ( `{controller:{p2:path2}/use:{p1:path1}}` ) ;
98+ expect ( testData3 )
99+ . to . be . equal ( `{controller:{p1:{pp1:ppath1}}/service:one/use:{p1:path1/p2:{pp1:ppath1}}}` ) ;
100+ } ) ;
101+ } ) ;
94102 } ) ;
95103
96- it ( `throw error if pattern has an incorrect type (no string/JSON)` , ( ) => {
97- const testPattern1 = 150 ;
98- const testPattern2 = null ;
99- const testPattern3 = undefined ;
100- const testPattern4 = Symbol ( 213 ) ;
101- const errMsg = `The pattern must be of type 'string' or 'object'!` ;
104+ describe ( `gets value with incorrect type (no string/JSON)` , ( ) => {
105+ it ( `should throw error` , ( ) => {
106+ const testPattern1 = 150 ;
107+ const testPattern2 = null ;
108+ const testPattern3 = undefined ;
109+ const testPattern4 = Symbol ( 213 ) ;
110+ const errMsg = `The pattern must be of type 'string' or 'object'!` ;
102111
103- expect ( MsvcUtil . transformPatternToRoute . bind ( null , testPattern1 ) ) . to . throw ( errMsg ) ;
104- expect ( MsvcUtil . transformPatternToRoute . bind ( null , testPattern2 ) ) . to . throw ( errMsg ) ;
105- expect ( MsvcUtil . transformPatternToRoute . bind ( null , testPattern3 ) ) . to . throw ( errMsg ) ;
106- expect ( MsvcUtil . transformPatternToRoute . bind ( null , testPattern4 ) ) . to . throw ( errMsg ) ;
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 ) ;
116+ } ) ;
107117 } ) ;
108118 } ) ;
109119} ) ;
0 commit comments