-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathuser-settings-service.ts
82 lines (73 loc) · 2.21 KB
/
user-settings-service.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
import { Yok } from "../../lib/common/yok";
import { UserSettingsService } from "../../lib/services/user-settings-service";
import { assert } from "chai";
import * as path from "path";
class JsonFileSettingsServiceMock {
constructor(public jsonFileSettingsPath: string) { }
}
describe("userSettingsService", () => {
const profileDir = "my-profile-dir";
const expectedJsonFileSettingsFilePath = path.join(profileDir, "user-settings.json");
const createTestInjector = (): IInjector => {
const testInjector = new Yok();
testInjector.register("settingsService", {
getProfileDir: () => profileDir
});
testInjector.register("jsonFileSettingsService", JsonFileSettingsServiceMock);
testInjector.register("userSettingsService", UserSettingsService);
return testInjector;
};
const testCases = [
{
methodName: "getSettingValue",
input: ["settingName"],
expectedArgs: [
"settingName",
undefined
]
},
{
methodName: "saveSetting",
input: ["settingName", "settingValue"],
expectedArgs: [
"settingName",
"settingValue",
undefined
]
},
{
methodName: "saveSettings",
input: [{ value: { subValue: 1 } }],
expectedArgs: [
{ value: { subValue: 1 } },
undefined
]
},
{
methodName: "removeSetting",
input: ["settingName"],
expectedArgs: [
"settingName"
]
},
{
methodName: "loadUserSettingsFile",
input: [],
expectedArgs: []
}
];
for (const testCase of testCases) {
it(`calls ${testCase.methodName} method of jsonFileSettingsService with correct args`, async () => {
const testInjector = createTestInjector();
const dataPassedToJsonFileSettingsService: any[] = [];
const userSettingsService = testInjector.resolve("userSettingsService");
const jsonFileSettingsService = userSettingsService.$jsonFileSettingsService;
jsonFileSettingsService[testCase.methodName] = async (...args: any[]): Promise<void> => {
dataPassedToJsonFileSettingsService.push(...args);
};
await userSettingsService[testCase.methodName](...testCase.input);
assert.deepEqual(dataPassedToJsonFileSettingsService, testCase.expectedArgs);
assert.equal(jsonFileSettingsService.jsonFileSettingsPath, expectedJsonFileSettingsFilePath);
});
}
});