From 7c593c23ff4dfca36b6dd6030f769113cf6805cb Mon Sep 17 00:00:00 2001 From: Leo Baschy Date: Mon, 4 Jun 2018 15:57:46 -0700 Subject: [PATCH] Add tests --- .../DomainLockNodeTemplate.spec.ts | 60 ++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts b/test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts index afc297b9..bc41c081 100644 --- a/test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts +++ b/test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts @@ -20,12 +20,14 @@ import { InversifyContainerFacade } from '../../../../src/container/InversifyCon * @param currentDomain * @returns {Function} */ -function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string, currentDomain: string) { +function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string, currentDomain: string, hostname = false) { const domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData); return Function(` document = { - domain: '${currentDomain}' + ${ !hostname ? + `domain: '${currentDomain}'` : + `location: { hostname: '${currentDomain}' }` } }; var ${callsControllerFunctionName} = (function(){ @@ -315,4 +317,58 @@ describe('DomainLockNodeTemplate', () => { }); }); }); + + describe('Variant #6: 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, true); + }); + + it('should correctly run code inside template', () => { + assert.doesNotThrow(testFunc); + }); + }); + + describe('Variant #5: 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, true); + }); + + it('should throw an error', () => { + assert.throws(testFunc); + }); + }); + }); });