-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathproject-changes-service.ts
155 lines (134 loc) · 5.14 KB
/
project-changes-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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as path from "path";
import { BaseServiceTest } from "./base-service-test";
import temp = require("temp");
import { assert } from "chai";
import { PlatformsData } from "../lib/platforms-data";
import { ProjectChangesService } from "../lib/services/project-changes-service";
import * as Constants from "../lib/constants";
import { FileSystem } from "../lib/common/file-system";
import * as HostInfoLib from "../lib/common/host-info";
import * as ErrorsLib from "../lib/common/errors";
// start tracking temporary folders/files
temp.track();
class ProjectChangesServiceTest extends BaseServiceTest {
public projectDir: string;
constructor() {
super();
}
initInjector(): void {
this.projectDir = temp.mkdirSync("projectDir");
this.injector.register("projectData", {
projectDir: this.projectDir
});
this.injector.register("platformsData", PlatformsData);
this.injector.register("androidProjectService", {});
this.injector.register("iOSProjectService", {});
this.injector.register("hostInfo", HostInfoLib.HostInfo);
this.injector.register("errors", ErrorsLib.Errors);
this.injector.register("fs", FileSystem);
this.injector.register("devicePlatformsConstants", {});
this.injector.register("devicePlatformsConstants", {});
this.injector.register("projectChangesService", ProjectChangesService);
const fs = this.injector.resolve<IFileSystem>("fs");
fs.writeJson(path.join(this.projectDir, Constants.PACKAGE_JSON_FILE_NAME), {
nativescript: {
id: "org.nativescript.test"
}
});
}
get projectChangesService(): IProjectChangesService {
return this.injector.resolve("projectChangesService");
}
get projectData(): IProjectData {
return this.injector.resolve("projectData");
}
get platformsData(): any {
return this.injector.resolve("platformsData");
}
}
describe("Project Changes Service Tests", () => {
let serviceTest: ProjectChangesServiceTest;
beforeEach(() => {
serviceTest = new ProjectChangesServiceTest();
const platformsDir = path.join(
serviceTest.projectDir,
Constants.PLATFORMS_DIR_NAME
);
serviceTest.platformsData.getPlatformData =
(platform: string) => {
if (platform.toLowerCase() === "ios") {
return {
projectRoot: path.join(platformsDir, platform),
get platformProjectService(): any {
return {
checkForChanges(changesInfo: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void {
changesInfo.signingChanged = true;
}
};
}
};
} else {
return {
projectRoot: path.join(platformsDir, platform),
get platformProjectService(): any {
return {
checkForChanges(changesInfo: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): void { /* no android changes */ }
};
}
};
}
};
});
describe("Get Prepare Info File Path", () => {
it("Gets the correct Prepare Info path for ios/android", () => {
for (let platform of ["ios", "android"]) {
let actualPrepareInfoPath = serviceTest.projectChangesService
.getPrepareInfoFilePath(platform, this.projectData);
const expectedPrepareInfoPath = path.join(serviceTest.projectDir,
Constants.PLATFORMS_DIR_NAME,
platform,
".nsprepareinfo");
assert.equal(actualPrepareInfoPath, expectedPrepareInfoPath);
}
});
});
describe("Get Prepare Info", () => {
it("Returns empty if file path doesn't exists", () => {
for (let platform of ["ios", "android"]) {
let projectInfo = serviceTest.projectChangesService.getPrepareInfo(platform, this.projectData);
assert.isNull(projectInfo);
}
});
it("Reads the Prepare Info correctly", () => {
const fs: FileSystem = serviceTest.resolve("fs");
for (let platform of ["ios", "android"]) {
// arrange
const prepareInfoPath = path.join(serviceTest.projectDir, Constants.PLATFORMS_DIR_NAME,
platform, ".nsprepareinfo");
const expectedPrepareInfo: IPrepareInfo = {
time: new Date().toString(),
bundle: true,
release: false,
changesRequireBuild: true,
changesRequireBuildTime: new Date().toString(),
iOSProvisioningProfileUUID: "provisioning_profile_test",
projectFileHash: "",
nativePlatformStatus: Constants.NativePlatformStatus.requiresPlatformAdd
};
fs.writeJson(prepareInfoPath, expectedPrepareInfo);
// act
let actualPrepareInfo = serviceTest.projectChangesService.getPrepareInfo(platform, this.projectData);
// assert
assert.deepEqual(actualPrepareInfo, expectedPrepareInfo);
}
});
});
describe("Accumulates Changes From Project Services", () => {
it("accumulates changes from the project service", () => {
let iOSChanges = serviceTest.projectChangesService.checkForChanges("ios", serviceTest.projectData, { bundle: false, release: false, provision: undefined });
assert.isTrue(!!iOSChanges.signingChanged, "iOS signingChanged expected to be true");
let androidChanges = serviceTest.projectChangesService.checkForChanges("android", serviceTest.projectData, { bundle: false, release: false, provision: undefined });
assert.isFalse(!!androidChanges.signingChanged, "Android signingChanged expected to be false");
});
});
});