|
@@ -18,14 +18,18 @@ import { InversifyContainerFacade } from '../../../../src/container/InversifyCon
|
|
|
* @param templateData
|
|
|
* @param callsControllerFunctionName
|
|
|
* @param currentDomain
|
|
|
+ * @param withoutDomain
|
|
|
* @returns {Function}
|
|
|
*/
|
|
|
-function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string, currentDomain: string) {
|
|
|
+function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string, currentDomain: string, domainIsPresent = true) {
|
|
|
const domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
|
|
|
|
|
|
return Function(`
|
|
|
document = {
|
|
|
- domain: '${currentDomain}'
|
|
|
+ ${ domainIsPresent ?`domain: '${currentDomain}',` : `` }
|
|
|
+ location: {
|
|
|
+ hostname: '${currentDomain}'
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
var ${callsControllerFunctionName} = (function(){
|
|
@@ -315,4 +319,58 @@ describe('DomainLockNodeTemplate', () => {
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ describe('Variant #5: current hostname matches with `domainsString`', () => {
|
|
|
+ const domainsString: string = ['www.example.com'].join(';');
|
|
|
+ const currentDomain: string = 'www.example.com';
|
|
|
+
|
|
|
+ let testFunc: () => void;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const [
|
|
|
+ hiddenDomainsString,
|
|
|
+ diff
|
|
|
+ ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
|
|
|
+
|
|
|
+ testFunc = () => getFunctionFromTemplate({
|
|
|
+ domainLockFunctionName: 'domainLockFunction',
|
|
|
+ diff: diff,
|
|
|
+ domains: hiddenDomainsString,
|
|
|
+ globalVariableTemplate: GlobalVariableTemplate1(),
|
|
|
+ singleNodeCallControllerFunctionName
|
|
|
+ }, singleNodeCallControllerFunctionName, currentDomain, false);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should correctly run code inside template', () => {
|
|
|
+ assert.doesNotThrow(testFunc);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('Variant #6: current hostname doesn\'t match with `domainsString`', () => {
|
|
|
+ describe('Variant #1', () => {
|
|
|
+ const domainsString: string = ['www.example.com'].join(';');
|
|
|
+ const currentDomain: string = 'www.test.com';
|
|
|
+
|
|
|
+ let testFunc: () => void;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const [
|
|
|
+ hiddenDomainsString,
|
|
|
+ diff
|
|
|
+ ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
|
|
|
+
|
|
|
+ testFunc = () => getFunctionFromTemplate({
|
|
|
+ domainLockFunctionName: 'domainLockFunction',
|
|
|
+ diff: diff,
|
|
|
+ domains: hiddenDomainsString,
|
|
|
+ globalVariableTemplate: GlobalVariableTemplate1(),
|
|
|
+ singleNodeCallControllerFunctionName
|
|
|
+ }, singleNodeCallControllerFunctionName, currentDomain, false);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should throw an error', () => {
|
|
|
+ assert.throws(testFunc);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|