12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- import * as format from 'string-template';
- import { DomainLockNodeTemplate } from '../../../../../src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
- import { Utils } from '../../../../../src/Utils';
- const assert: Chai.AssertStatic = require('chai').assert;
- /**
- * @param templateData
- * @param callsControllerFunctionName
- * @param currentDomain
- * @returns {Function}
- */
- function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string, currentDomain: string) {
- let domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
- return Function(`
- document = {
- domain: '${currentDomain}'
- };
- var ${callsControllerFunctionName} = (function(){
- return function (context, fn){
- return function () {
- return fn.apply(context, arguments);
- };
- }
- })();
- ${domainLockTemplate}
- `)();
- }
- describe('DomainLockNodeTemplate (): string', () => {
- let domainsString: string,
- currentDomain: string,
- hiddenDomainsString: string,
- diff: string,
- singleNodeCallControllerFunctionName: string = 'callsController';
- it('should correctly runs code inside template if current domain matches with `domainsString`', () => {
- domainsString = ['www.example.com'].join(';');
- currentDomain = 'www.example.com';
- [
- hiddenDomainsString,
- diff
- ] = Utils.hideString(domainsString, domainsString.length * 3);
- assert.doesNotThrow(() => getFunctionFromTemplate({
- domainLockFunctionName: 'domainLockFunction',
- diff: diff,
- domains: hiddenDomainsString,
- singleNodeCallControllerFunctionName
- }, singleNodeCallControllerFunctionName, currentDomain));
- });
- it('should correctly runs code inside template if current domain matches with base domain of `domainsString` item', () => {
- domainsString = ['www.test.com', '.example.com'].join(';');
- currentDomain = 'subdomain.example.com';
- [
- hiddenDomainsString,
- diff
- ] = Utils.hideString(domainsString, domainsString.length * 3);
- assert.doesNotThrow(() => getFunctionFromTemplate({
- domainLockFunctionName: 'domainLockFunction',
- diff: diff,
- domains: hiddenDomainsString,
- singleNodeCallControllerFunctionName
- }, singleNodeCallControllerFunctionName, currentDomain));
- });
- it('should throw an error if current domain doesn\'t match with `domainsString`', () => {
- domainsString = ['www.example.com'].join(';');
- currentDomain = 'www.test.com';
- [
- hiddenDomainsString,
- diff
- ] = Utils.hideString(domainsString, domainsString.length * 3);
- assert.throws(() => getFunctionFromTemplate({
- domainLockFunctionName: 'domainLockFunction',
- diff: diff,
- domains: hiddenDomainsString,
- singleNodeCallControllerFunctionName
- }, singleNodeCallControllerFunctionName, currentDomain));
- });
- afterEach(() => {
- delete (<any>global).promisePolyfillActivationFlag;
- });
- });
|