Skip to content

Commit

Permalink
PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
TsvetanMilanov committed Mar 23, 2016
1 parent fc8c05e commit 28202a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 51 deletions.
6 changes: 2 additions & 4 deletions lib/commands/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ export class CreateProjectCommand implements ICommand {
this.$errors.fail("You cannot use --ng and --template simultaneously.");
}

if (this.$options.ng) {
this.$options.template = constants.ANGULAR_NAME;
}
let selectedTemplate = this.$options.ng ? constants.ANGULAR_NAME : this.$options.template;

this.$projectService.createProject(args[0], this.$options.template).wait();
this.$projectService.createProject(args[0], selectedTemplate).wait();
}).future<void>()();
}

Expand Down
82 changes: 35 additions & 47 deletions test/project-commands.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/// <reference path=".d.ts" />
"use strict";

import * as yok from "../lib/common/yok";
import { Yok } from "../lib/common/yok";
import * as stubs from "./stubs";
import { CreateProjectCommand } from "../lib/commands/create-project";
import * as constants from "../lib/constants";
import {assert} from "chai";

let selectedTemplateName: string;
let isProjectCreated: boolean;
let dummyArgsString = "dummyArgsString";
let dummyArgs = ["dummyArgsString"];

class ProjectServiceMock implements IProjectService {
createProject(projectName: string, selectedTemplate?: string): IFuture<void> {
Expand All @@ -27,7 +27,7 @@ class ProjectNameValidatorMock implements IProjectNameValidator {
}

function createTestInjector() {
let testInjector = new yok.Yok();
let testInjector = new Yok();

testInjector.register("injector", testInjector);
testInjector.register("staticConfig", {});
Expand All @@ -44,70 +44,58 @@ function createTestInjector() {
return testInjector;
}

describe('Project Service Tests', () => {
describe("Project commands tests", () => {
let testInjector: IInjector;
let options: IOptions;
let createProjectCommand: ICommand;

beforeEach(() => {
testInjector = createTestInjector();
isProjectCreated = false;
selectedTemplateName = undefined;
options = testInjector.resolve("$options");
createProjectCommand = testInjector.resolve("$createCommand");
});

describe("project commands tests", () => {
describe("#CreateProjectCommand", () => {
it("should not fail when using only --ng.", () => {
let options: IOptions = testInjector.resolve("$options");
options.ng = true;
describe("#CreateProjectCommand", () => {
it("should not fail when using only --ng.", () => {
options.ng = true;

let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
createProjectCommand.execute(dummyArgs).wait();

createProjectCommand.execute([dummyArgsString]).wait();

assert.isTrue(isProjectCreated);
});

it("should not fail when using only --template.", () => {
let options: IOptions = testInjector.resolve("$options");
options.template = "ng";

let createProjectCommand: ICommand = testInjector.resolve("$createCommand");

createProjectCommand.execute([dummyArgsString]).wait();

assert.isTrue(isProjectCreated);
});
assert.isTrue(isProjectCreated);
});

it("should set the template name correctly when used --ng.", () => {
let options: IOptions = testInjector.resolve("$options");
options.ng = true;
it("should not fail when using only --template.", () => {
options.template = "ng";

let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
createProjectCommand.execute(dummyArgs).wait();

createProjectCommand.execute([dummyArgsString]).wait();
assert.isTrue(isProjectCreated);
});

assert.deepEqual(options.template, constants.ANGULAR_NAME);
});
it("should set the template name correctly when used --ng.", () => {
options.ng = true;

it("should not set the template name when --ng is not used.", () => {
let options: IOptions = testInjector.resolve("$options");
options.ng = false;
createProjectCommand.execute(dummyArgs).wait();

let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
assert.deepEqual(selectedTemplateName, constants.ANGULAR_NAME);
});

createProjectCommand.execute([dummyArgsString]).wait();
it("should not set the template name when --ng is not used.", () => {
options.ng = false;

assert.isUndefined(options.template);
});
createProjectCommand.execute(dummyArgs).wait();

it("should fail when --ng and --template are used simultaneously.", () => {
let options: IOptions = testInjector.resolve("$options");
options.ng = true;
options.template = "ng";
assert.isUndefined(selectedTemplateName);
});

let createProjectCommand: ICommand = testInjector.resolve("$createCommand");
it("should fail when --ng and --template are used simultaneously.", () => {
options.ng = true;
options.template = "ng";

assert.throws(() => {
createProjectCommand.execute([dummyArgsString]).wait();
});
assert.throws(() => {
createProjectCommand.execute(dummyArgs).wait();
});
});
});
Expand Down

0 comments on commit 28202a7

Please sign in to comment.