Skip to content
Permalink
Browse files

Merge pull request #57 from webcomputing/feature/CS-216-multilingual-…

…agent

Feature/cs 216 multilingual agent
  • Loading branch information...
antoniusostermann committed Apr 3, 2019
2 parents 2816b08 + c75443f commit e4144af8f72780e0d62a91ac4f01ddad203f13ec
@@ -26,7 +26,7 @@
"author": "Antonius Ostermann <ostermann.antonius@gmail.com> (http://www.antonius-ostermann.de)",
"license": "SEE LICENSE IN <LICENSE>",
"peerDependencies": {
"inversify-components": "^0.4.4",
"inversify-components": "^0.4.6",
"express": "^4.16.2"
},
"dependencies": {
@@ -0,0 +1,106 @@
import * as fs from "fs";
import * as path from "path";
import { CLIGeneratorExtension, GeneratorApplication } from "../../../src/assistant-source";
import { componentInterfaces } from "../../../src/components/root/private-interfaces";
import { ThisContext } from "../../this-context";

interface CurrentThisContext extends ThisContext {
/** Base directory used by the GeneratorApplication */
baseDir: string;
/** Build directory used by the GeneratorApplication */
buildDir: string;
/** Instance of the current GeneratorApplication Class */
generatorApplication: GeneratorApplication;
/** Current build timestamp */
buildTimestamp: Date;
/** Mocked instance of the Generator class. */
generatorExtension: CLIGeneratorExtension;
/** All Spy instances used by the current specs */
spy: Partial<{
/** fs.mkdirSync Spy */
mkdirSync: jasmine.Spy;
/** fs.existsSync Spy */
existsSync: jasmine.Spy;
/** Spy for the this.generatorExtension.execute method */
execute: jasmine.Spy;
}>;
}

const { mkdirSync, existsSync } = fs;

describe("GeneratorApplication", function() {
beforeEach(async function(this: CurrentThisContext) {
this.specHelper.prepareSpec({});
/** Mock the build timestamp used by the GeneratorApplication to create a build number */
jasmine.clock().install();
this.buildTimestamp = new Date();
jasmine.clock().mockDate(this.buildTimestamp);

/** Mock data for the base directory */
this.baseDir = "tmp";

/** Disable hard disk operations */
this.spy = {};
this.spy.mkdirSync = jasmine.createSpy("mkdirSync");
(fs as any).mkdirSync = this.spy.mkdirSync;
this.spy.existsSync = jasmine.createSpy("existsSync");
(fs as any).existsSync = this.spy.existsSync;

/** Create an instance of the GeneratorApplication */
this.generatorApplication = new GeneratorApplication(this.baseDir);

/** Create a spy on the used CLIGeneratorExtension */
this.generatorExtension = this.assistantJs.container.inversifyInstance.getAll<CLIGeneratorExtension>(componentInterfaces.generator)[0];
this.spy.execute = jasmine.createSpy("execute");
(this.generatorExtension as any).execute = this.spy.execute;
this.assistantJs.container.inversifyInstance.rebind(componentInterfaces.generator).toConstantValue(this.generatorExtension);
});

afterEach(function() {
/** Cleanup the mocked date */
jasmine.clock().uninstall();

/** Reset fs spy objects */
(fs as any).mkdirSync = mkdirSync;
(fs as any).existsSync = existsSync;
});

describe("#execute", function() {
describe("with existing base directory", function() {
beforeEach(async function(this: CurrentThisContext) {
this.spy.existsSync!.and.returnValue(true);
this.generatorApplication.execute(this.assistantJs.container);
});

it("will not create the base directory", async function(this: CurrentThisContext) {
expect(this.spy.mkdirSync!).not.toHaveBeenCalledWith(this.baseDir);
});
});

describe("without existing base directory", function() {
beforeEach(async function(this: CurrentThisContext) {
this.spy.existsSync!.and.returnValue(false);
this.generatorApplication.execute(this.assistantJs.container);
});

it("creates the base directory", async function(this: CurrentThisContext) {
expect(this.spy.mkdirSync!).toHaveBeenCalledWith(this.baseDir);
});
});

describe("regarding general behavior", function() {
beforeEach(async function(this: CurrentThisContext) {
this.generatorApplication.execute(this.assistantJs.container);
this.buildDir = path.join(this.baseDir, this.buildTimestamp.getTime().toString());
});

it("creates the build directory", async function(this: CurrentThisContext) {
expect(this.spy.mkdirSync!).toHaveBeenCalledWith(this.buildDir);
});

it("execute generatorExtension", async function(this: CurrentThisContext) {
expect(this.generatorExtension.execute).toHaveBeenCalledWith(this.buildDir);
});
});
});
});
Oops, something went wrong.

0 comments on commit e4144af

Please sign in to comment.
You can’t perform that action at this time.