-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathproject-commands.ts
101 lines (79 loc) · 2.77 KB
/
project-commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { Yok } from "../lib/common/yok";
import * as stubs from "./stubs";
import { CreateProjectCommand } from "../lib/commands/create-project";
import { StringParameterBuilder } from "../lib/common/command-params";
import * as constants from "../lib/constants";
import {assert} from "chai";
let selectedTemplateName: string;
let isProjectCreated: boolean;
let dummyArgs = ["dummyArgsString"];
class ProjectServiceMock implements IProjectService {
createProject(projectName: string, selectedTemplate?: string): IFuture<void> {
return (() => {
selectedTemplateName = selectedTemplate;
isProjectCreated = true;
}).future<void>()();
}
}
class ProjectNameValidatorMock implements IProjectNameValidator {
public validate(name: string): boolean {
return true;
}
}
function createTestInjector() {
let testInjector = new Yok();
testInjector.register("injector", testInjector);
testInjector.register("staticConfig", {});
testInjector.register("projectService", ProjectServiceMock);
testInjector.register("errors", stubs.ErrorsStub);
testInjector.register("logger", stubs.LoggerStub);
testInjector.register("projectNameValidator", ProjectNameValidatorMock);
testInjector.register("options", {
ng: false,
template: undefined
});
testInjector.register("createCommand", CreateProjectCommand);
testInjector.register("stringParameterBuilder", StringParameterBuilder);
return testInjector;
}
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("#CreateProjectCommand", () => {
it("should not fail when using only --ng.", () => {
options.ng = true;
createProjectCommand.execute(dummyArgs).wait();
assert.isTrue(isProjectCreated);
});
it("should not fail when using only --template.", () => {
options.template = "ng";
createProjectCommand.execute(dummyArgs).wait();
assert.isTrue(isProjectCreated);
});
it("should set the template name correctly when used --ng.", () => {
options.ng = true;
createProjectCommand.execute(dummyArgs).wait();
assert.deepEqual(selectedTemplateName, constants.ANGULAR_NAME);
});
it("should not set the template name when --ng is not used.", () => {
options.ng = false;
createProjectCommand.execute(dummyArgs).wait();
assert.isUndefined(selectedTemplateName);
});
it("should fail when --ng and --template are used simultaneously.", () => {
options.ng = true;
options.template = "ng";
assert.throws(() => {
createProjectCommand.execute(dummyArgs).wait();
});
});
});
});