-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathupdate.ts
78 lines (69 loc) · 2.6 KB
/
update.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
import * as stubs from "./stubs";
import * as yok from "../lib/common/yok";
import { UpdateCommand } from "../lib/commands/update";
import { assert } from "chai";
import { Options } from "../lib/options";
import { StaticConfig } from "../lib/config";
import { SettingsService } from "../lib/common/test/unit-tests/stubs";
import { DevicePlatformsConstants } from "../lib/common/mobile/device-platforms-constants";
import { IInjector } from "../lib/common/definitions/yok";
const projectFolder = "test";
function createTestInjector(projectDir: string = projectFolder): IInjector {
const testInjector: IInjector = new yok.Yok();
testInjector.register("logger", stubs.LoggerStub);
testInjector.register("markingModeService", stubs.MarkingModeServiceStub);
testInjector.register("options", Options);
testInjector.register("analyticsService", {
trackException: async (): Promise<void> => undefined,
checkConsent: async (): Promise<void> => undefined,
trackFeature: async (): Promise<void> => undefined,
});
testInjector.register("errors", stubs.ErrorsStub);
testInjector.register("staticConfig", StaticConfig);
testInjector.register("projectData", {
projectDir,
initializeProjectData: () => {
/* empty */
},
dependencies: {},
});
testInjector.register("settingsService", SettingsService);
testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);
testInjector.register("migrateController", {
shouldMigrate: () => {
return false;
},
});
testInjector.register("updateController", {
shouldUpdate: () => {
return true;
},
});
return testInjector;
}
describe("update command method tests", () => {
describe("canExecute", () => {
it("returns false if too many arguments", async () => {
const testInjector = createTestInjector();
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
const canExecuteOutput = await updateCommand.canExecute([
"333",
"111",
"444",
]);
return assert.equal(canExecuteOutput, false);
});
it("returns false when projectDir is an empty string", async () => {
const testInjector = createTestInjector("");
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
const canExecuteOutput = await updateCommand.canExecute([]);
return assert.equal(canExecuteOutput, false);
});
it("returns true when the setup is correct", async () => {
const testInjector = createTestInjector();
const updateCommand = testInjector.resolve<UpdateCommand>(UpdateCommand);
const canExecuteOutput = await updateCommand.canExecute(["3.3.0"]);
return assert.equal(canExecuteOutput, true);
});
});
});