UNPKG

firmament-bash

Version:

Firmament module for interpreting commands in JSON files using bash

165 lines 7.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("reflect-metadata"); const inversify_config_1 = require("../inversify.config"); const chai_1 = require("chai"); const mocha = require("mocha"); const path = require("path"); describe('Testing ExecutionGraphResolver Creation/Force Error', () => { let executionGraphResolver; beforeEach(() => { executionGraphResolver = inversify_config_1.default.get('ExecutionGraphResolver'); }); afterEach(() => { executionGraphResolver.forceError = false; }); mocha.it('use mocha instance to avoid linter warning', (done) => { done(); }); it('should be created by kernel', (done) => { chai_1.expect(executionGraphResolver).to.exist; done(); }); it('should have callback with error', (done) => { executionGraphResolver.forceError = true; executionGraphResolver.getFullResourcePath(null, null, (err, fullResourcePath) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal('force error: ExecutionGraphResolverImpl.getFullResourcePath'); chai_1.expect(fullResourcePath).to.not.exist; executionGraphResolver.resolveExecutionGraphFromCatalogEntry(null, (err, executionGraph) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal('force error: ExecutionGraphResolverImpl.resolveExecutionGraphFromCatalogEntry'); chai_1.expect(executionGraph).to.not.exist; executionGraphResolver.resolveExecutionGraph(null, (err, executionGraph) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal('force error: ExecutionGraphResolverImpl.resolveExecutionGraph'); chai_1.expect(executionGraph).to.not.exist; done(); }); }); }); }); }); describe('Testing ExecutionGraphResolver.getFullResourcePath', () => { let executionGraphResolver; beforeEach(() => { executionGraphResolver = inversify_config_1.default.get('ExecutionGraphResolver'); }); it('should return an error if url is undefined', (done) => { let undefinedUrl; executionGraphResolver.getFullResourcePath(undefinedUrl, null, (err, fullResourcePath) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Parameter "url" must be a string, not undefined`); chai_1.expect(fullResourcePath).to.not.exist; done(); }); }); it('should return an error if url is null', (done) => { const nullUrl = null; executionGraphResolver.getFullResourcePath(nullUrl, null, (err, fullResourcePath) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Parameter "url" must be a string, not object`); chai_1.expect(fullResourcePath).to.not.exist; done(); }); }); it('should return an error if url is stupid', (done) => { const stupidUrl = '*-*'; executionGraphResolver.getFullResourcePath(stupidUrl, null, (err, fullResourcePath) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Parameter "url" must be a string, not object`); chai_1.expect(fullResourcePath).to.not.exist; done(); }); }); it('should return full web path if passed full web path', (done) => { const webUrl = 'http://www.yahoo.com/kimberly/clark.jpg'; executionGraphResolver.getFullResourcePath(webUrl, null, (err, fullResourcePath) => { chai_1.expect(err).to.not.exist; chai_1.expect(fullResourcePath).to.equal(webUrl); done(); }); }); it('should return full filesystem path if passed full filesystem path', (done) => { const filesystemUrl = '/var/local/ledbetter/grim.jpg'; executionGraphResolver.getFullResourcePath(filesystemUrl, null, (err, fullResourcePath) => { chai_1.expect(err).to.not.exist; chai_1.expect(fullResourcePath).to.equal(filesystemUrl); done(); }); }); it('should return an error if url is valid partial but parentUrl is undefined', (done) => { const partialUrl = 'svegney/blotter.jpg'; let undefinedParentUrl; executionGraphResolver.getFullResourcePath(partialUrl, undefinedParentUrl, (err, fullResourcePath) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Parameter "url" must be a string, not undefined`); chai_1.expect(fullResourcePath).to.not.exist; done(); }); }); it('should return an error if url is valid partial but parentUrl is null', (done) => { const partialUrl = 'svegney/blotter.jpg'; let nullParentUrl = null; executionGraphResolver.getFullResourcePath(partialUrl, nullParentUrl, (err, fullResourcePath) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Parameter "url" must be a string, not object`); chai_1.expect(fullResourcePath).to.not.exist; done(); }); }); it('should return full web path if url is valid partial and parentUrl is valid web url', (done) => { const webUrl = 'photos/clark.jpg'; const parentUrl = 'http://www.yahoo.com/cloomb/kimberly.jpg'; executionGraphResolver.getFullResourcePath(webUrl, parentUrl, (err, fullResourcePath) => { chai_1.expect(err).to.not.exist; const expectedFullResourcePath = `${path.dirname(parentUrl)}/${webUrl}`; chai_1.expect(fullResourcePath).to.equal(expectedFullResourcePath); done(); }); }); it('should return full filesystem path if url is valid partial and parentUrl is valid filesystem url', (done) => { const webUrl = 'photos/clark.jpg'; const parentUrl = '/var/local/ledbetter/grim.jpg'; executionGraphResolver.getFullResourcePath(webUrl, parentUrl, (err, fullResourcePath) => { chai_1.expect(err).to.not.exist; const expectedFullResourcePath = `${path.dirname(parentUrl)}/${webUrl}`; chai_1.expect(fullResourcePath).to.equal(expectedFullResourcePath); done(); }); }); }); describe('Testing ExecutionGraphResolver.resolveExecutionGraph', () => { let executionGraphResolver; beforeEach(() => { executionGraphResolver = inversify_config_1.default.get('ExecutionGraphResolver'); }); it('should return an error if url is undefined', (done) => { let undefinedUrl; executionGraphResolver.resolveExecutionGraph(undefinedUrl, (err, executionGraph) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Cannot read property 'constructor' of undefined`); chai_1.expect(executionGraph).to.not.exist; done(); }); }); it('should return an error if url is null', (done) => { let nullUrl = null; executionGraphResolver.resolveExecutionGraph(nullUrl, (err, executionGraph) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Cannot read property 'constructor' of null`); chai_1.expect(executionGraph).to.not.exist; done(); }); }); it('should return an error if url is stupid', (done) => { let stupidUrl = '*-*'; executionGraphResolver.resolveExecutionGraph(stupidUrl, (err, executionGraph) => { chai_1.expect(err).to.exist; chai_1.expect(err.message).to.equal(`Url: '*-*' does not exist`); chai_1.expect(executionGraph).to.not.exist; done(); }); }); }); //# sourceMappingURL=execution-graph-resolver.test.js.map