@@ -13,7 +13,7 @@ import { CryptUtils } from '../../../../../src/utils/CryptUtils';
13
13
* @returns {Function }
14
14
*/
15
15
function getFunctionFromTemplate ( templateData : any , callsControllerFunctionName : string , currentDomain : string ) {
16
- let domainLockTemplate : string = format ( DomainLockNodeTemplate ( ) , templateData ) ;
16
+ const domainLockTemplate : string = format ( DomainLockNodeTemplate ( ) , templateData ) ;
17
17
18
18
return Function ( `
19
19
document = {
@@ -33,57 +33,80 @@ function getFunctionFromTemplate (templateData: any, callsControllerFunctionName
33
33
}
34
34
35
35
describe ( 'DomainLockNodeTemplate (): string' , ( ) => {
36
- let domainsString : string ,
37
- currentDomain : string ,
38
- hiddenDomainsString : string ,
39
- diff : string ,
40
- singleNodeCallControllerFunctionName : string = 'callsController' ;
41
-
42
- it ( 'should correctly runs code inside template if current domain matches with `domainsString`' , ( ) => {
43
- domainsString = [ 'www.example.com' ] . join ( ';' ) ;
44
- currentDomain = 'www.example.com' ;
45
- [
46
- hiddenDomainsString ,
47
- diff
48
- ] = CryptUtils . hideString ( domainsString , domainsString . length * 3 ) ;
49
-
50
- assert . doesNotThrow ( ( ) => getFunctionFromTemplate ( {
51
- domainLockFunctionName : 'domainLockFunction' ,
52
- diff : diff ,
53
- domains : hiddenDomainsString ,
54
- singleNodeCallControllerFunctionName
55
- } , singleNodeCallControllerFunctionName , currentDomain ) ) ;
36
+ const singleNodeCallControllerFunctionName : string = 'callsController' ;
37
+
38
+ describe ( 'variant #1: current domain matches with `domainsString`' , ( ) => {
39
+ const domainsString : string = [ 'www.example.com' ] . join ( ';' ) ;
40
+ const currentDomain : string = 'www.example.com' ;
41
+
42
+ let testFunc : ( ) => void ;
43
+
44
+ before ( ( ) => {
45
+ const [
46
+ hiddenDomainsString ,
47
+ diff
48
+ ] = CryptUtils . hideString ( domainsString , domainsString . length * 3 ) ;
49
+
50
+ testFunc = ( ) => getFunctionFromTemplate ( {
51
+ domainLockFunctionName : 'domainLockFunction' ,
52
+ diff : diff ,
53
+ domains : hiddenDomainsString ,
54
+ singleNodeCallControllerFunctionName
55
+ } , singleNodeCallControllerFunctionName , currentDomain ) ;
56
+ } ) ;
57
+
58
+ it ( 'should correctly runs code inside template' , ( ) => {
59
+ assert . doesNotThrow ( testFunc ) ;
60
+ } ) ;
56
61
} ) ;
57
62
58
- it ( 'should correctly runs code inside template if current domain matches with base domain of `domainsString` item' , ( ) => {
59
- domainsString = [ 'www.test.com' , '.example.com' ] . join ( ';' ) ;
60
- currentDomain = 'subdomain.example.com' ;
61
- [
62
- hiddenDomainsString ,
63
- diff
64
- ] = CryptUtils . hideString ( domainsString , domainsString . length * 3 ) ;
65
-
66
- assert . doesNotThrow ( ( ) => getFunctionFromTemplate ( {
67
- domainLockFunctionName : 'domainLockFunction' ,
68
- diff : diff ,
69
- domains : hiddenDomainsString ,
70
- singleNodeCallControllerFunctionName
71
- } , singleNodeCallControllerFunctionName , currentDomain ) ) ;
63
+ describe ( 'variant #2: urrent domain matches with base domain of `domainsString` item' , ( ) => {
64
+ const domainsString : string = [ 'www.test.com' , '.example.com' ] . join ( ';' ) ;
65
+ const currentDomain : string = 'subdomain.example.com' ;
66
+
67
+ let testFunc : ( ) => void ;
68
+
69
+ before ( ( ) => {
70
+ const [
71
+ hiddenDomainsString ,
72
+ diff
73
+ ] = CryptUtils . hideString ( domainsString , domainsString . length * 3 ) ;
74
+
75
+ testFunc = ( ) => getFunctionFromTemplate ( {
76
+ domainLockFunctionName : 'domainLockFunction' ,
77
+ diff : diff ,
78
+ domains : hiddenDomainsString ,
79
+ singleNodeCallControllerFunctionName
80
+ } , singleNodeCallControllerFunctionName , currentDomain ) ;
81
+ } ) ;
82
+
83
+ it ( 'should correctly runs code inside template' , ( ) => {
84
+ assert . doesNotThrow ( testFunc ) ;
85
+ } ) ;
72
86
} ) ;
73
87
74
- it ( 'should throw an error if current domain doesn\'t match with `domainsString`' , ( ) => {
75
- domainsString = [ 'www.example.com' ] . join ( ';' ) ;
76
- currentDomain = 'www.test.com' ;
77
- [
78
- hiddenDomainsString ,
79
- diff
80
- ] = CryptUtils . hideString ( domainsString , domainsString . length * 3 ) ;
81
-
82
- assert . throws ( ( ) => getFunctionFromTemplate ( {
83
- domainLockFunctionName : 'domainLockFunction' ,
84
- diff : diff ,
85
- domains : hiddenDomainsString ,
86
- singleNodeCallControllerFunctionName
87
- } , singleNodeCallControllerFunctionName , currentDomain ) ) ;
88
+ describe ( 'variant #3: current domain doesn\'t match with `domainsString`' , ( ) => {
89
+ const domainsString : string = [ 'www.example.com' ] . join ( ';' ) ;
90
+ const currentDomain : string = 'www.test.com' ;
91
+
92
+ let testFunc : ( ) => void ;
93
+
94
+ before ( ( ) => {
95
+ const [
96
+ hiddenDomainsString ,
97
+ diff
98
+ ] = CryptUtils . hideString ( domainsString , domainsString . length * 3 ) ;
99
+
100
+ testFunc = ( ) => getFunctionFromTemplate ( {
101
+ domainLockFunctionName : 'domainLockFunction' ,
102
+ diff : diff ,
103
+ domains : hiddenDomainsString ,
104
+ singleNodeCallControllerFunctionName
105
+ } , singleNodeCallControllerFunctionName , currentDomain ) ;
106
+ } ) ;
107
+
108
+ it ( 'should throw an error' , ( ) => {
109
+ assert . throws ( testFunc ) ;
110
+ } ) ;
88
111
} ) ;
89
112
} ) ;
0 commit comments