@appcircle/codepush-cli 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +17 -0
- package/.github/pre-push +30 -0
- package/.github/prepare-commit--msg +2 -0
- package/CONTRIBUTING.md +71 -0
- package/Dockerfile +9 -0
- package/Jenkinsfile +45 -0
- package/README.md +837 -0
- package/bin/script/acquisition-sdk.js +178 -0
- package/bin/script/cli.js +23 -0
- package/bin/script/command-executor.js +1292 -0
- package/bin/script/command-parser.js +1123 -0
- package/bin/script/commands/debug.js +125 -0
- package/bin/script/hash-utils.js +203 -0
- package/bin/script/index.js +5 -0
- package/bin/script/management-sdk.js +454 -0
- package/bin/script/react-native-utils.js +249 -0
- package/bin/script/sign.js +69 -0
- package/bin/script/types/cli.js +40 -0
- package/bin/script/types/rest-definitions.js +19 -0
- package/bin/script/types.js +4 -0
- package/bin/script/utils/file-utils.js +50 -0
- package/bin/test/acquisition-rest-mock.js +108 -0
- package/bin/test/acquisition-sdk.js +188 -0
- package/bin/test/cli.js +1342 -0
- package/bin/test/hash-utils.js +149 -0
- package/bin/test/management-sdk.js +338 -0
- package/package.json +74 -0
- package/prettier.config.js +7 -0
- package/script/acquisition-sdk.ts +273 -0
- package/script/cli.ts +27 -0
- package/script/command-executor.ts +1614 -0
- package/script/command-parser.ts +1340 -0
- package/script/commands/debug.ts +148 -0
- package/script/hash-utils.ts +241 -0
- package/script/index.ts +5 -0
- package/script/management-sdk.ts +627 -0
- package/script/react-native-utils.ts +283 -0
- package/script/sign.ts +80 -0
- package/script/types/cli.ts +234 -0
- package/script/types/rest-definitions.ts +152 -0
- package/script/types.ts +35 -0
- package/script/utils/check-package.mjs +11 -0
- package/script/utils/file-utils.ts +46 -0
- package/test/acquisition-rest-mock.ts +125 -0
- package/test/acquisition-sdk.ts +272 -0
- package/test/cli.ts +1692 -0
- package/test/hash-utils.ts +170 -0
- package/test/management-sdk.ts +438 -0
- package/test/resources/TestApp/android/app/build.gradle +56 -0
- package/test/resources/TestApp/iOS/TestApp/Info.plist +49 -0
- package/test/resources/TestApp/index.android.js +2 -0
- package/test/resources/TestApp/index.ios.js +2 -0
- package/test/resources/TestApp/index.windows.js +2 -0
- package/test/resources/TestApp/package.json +6 -0
- package/test/resources/TestApp/windows/TestApp/Package.appxmanifest +46 -0
- package/test/resources/ignoredMetadata.zip +0 -0
- package/test/resources/test.zip +0 -0
- package/test/superagent-mock-config.js +58 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const assert = require("assert");
|
|
6
|
+
const acquisitionSdk = require("../script/acquisition-sdk");
|
|
7
|
+
const mockApi = require("./acquisition-rest-mock");
|
|
8
|
+
var latestPackage = clone(mockApi.latestPackage);
|
|
9
|
+
var configuration = {
|
|
10
|
+
appVersion: "1.5.0",
|
|
11
|
+
clientUniqueId: "My iPhone",
|
|
12
|
+
deploymentKey: mockApi.validDeploymentKey,
|
|
13
|
+
serverUrl: mockApi.serverUrl,
|
|
14
|
+
};
|
|
15
|
+
var templateCurrentPackage = {
|
|
16
|
+
deploymentKey: mockApi.validDeploymentKey,
|
|
17
|
+
description: "sdfsdf",
|
|
18
|
+
label: "v1",
|
|
19
|
+
appVersion: latestPackage.appVersion,
|
|
20
|
+
packageHash: "hash001",
|
|
21
|
+
isMandatory: false,
|
|
22
|
+
packageSize: 100,
|
|
23
|
+
};
|
|
24
|
+
var scriptUpdateResult = {
|
|
25
|
+
deploymentKey: mockApi.validDeploymentKey,
|
|
26
|
+
description: latestPackage.description,
|
|
27
|
+
downloadUrl: latestPackage.downloadURL,
|
|
28
|
+
label: latestPackage.label,
|
|
29
|
+
appVersion: latestPackage.appVersion,
|
|
30
|
+
isMandatory: latestPackage.isMandatory,
|
|
31
|
+
packageHash: latestPackage.packageHash,
|
|
32
|
+
packageSize: latestPackage.packageSize,
|
|
33
|
+
};
|
|
34
|
+
var nativeUpdateResult = {
|
|
35
|
+
updateAppVersion: true,
|
|
36
|
+
appVersion: latestPackage.appVersion,
|
|
37
|
+
};
|
|
38
|
+
describe("Acquisition SDK", () => {
|
|
39
|
+
it("Package with lower label and different package hash gives update", (done) => {
|
|
40
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
41
|
+
acquisition.queryUpdateWithCurrentPackage(templateCurrentPackage, (error, returnPackage) => {
|
|
42
|
+
assert.equal(null, error);
|
|
43
|
+
assert.deepEqual(scriptUpdateResult, returnPackage);
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it("Package with equal package hash gives no update", (done) => {
|
|
48
|
+
var equalVersionPackage = clone(templateCurrentPackage);
|
|
49
|
+
equalVersionPackage.packageHash = latestPackage.packageHash;
|
|
50
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
51
|
+
acquisition.queryUpdateWithCurrentPackage(equalVersionPackage, (error, returnPackage) => {
|
|
52
|
+
assert.equal(null, error);
|
|
53
|
+
assert.equal(null, returnPackage);
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
it("Package with higher different hash and higher label version gives update", (done) => {
|
|
58
|
+
var higherVersionPackage = clone(templateCurrentPackage);
|
|
59
|
+
higherVersionPackage.packageHash = "hash990";
|
|
60
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
61
|
+
acquisition.queryUpdateWithCurrentPackage(higherVersionPackage, (error, returnPackage) => {
|
|
62
|
+
assert.equal(null, error);
|
|
63
|
+
assert.deepEqual(scriptUpdateResult, returnPackage);
|
|
64
|
+
done();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it("Package with lower native version gives update notification", (done) => {
|
|
68
|
+
var lowerAppVersionPackage = clone(templateCurrentPackage);
|
|
69
|
+
lowerAppVersionPackage.appVersion = "0.0.1";
|
|
70
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
71
|
+
acquisition.queryUpdateWithCurrentPackage(lowerAppVersionPackage, (error, returnPackage) => {
|
|
72
|
+
assert.equal(null, error);
|
|
73
|
+
assert.deepEqual(nativeUpdateResult, returnPackage);
|
|
74
|
+
done();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it("Package with higher native version gives no update", (done) => {
|
|
78
|
+
var higherAppVersionPackage = clone(templateCurrentPackage);
|
|
79
|
+
higherAppVersionPackage.appVersion = "9.9.0";
|
|
80
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
81
|
+
acquisition.queryUpdateWithCurrentPackage(higherAppVersionPackage, (error, returnPackage) => {
|
|
82
|
+
assert.equal(null, error);
|
|
83
|
+
assert.deepEqual(null, returnPackage);
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it("An empty response gives no update", (done) => {
|
|
88
|
+
var lowerAppVersionPackage = clone(templateCurrentPackage);
|
|
89
|
+
lowerAppVersionPackage.appVersion = "0.0.1";
|
|
90
|
+
var emptyReponse = {
|
|
91
|
+
statusCode: 200,
|
|
92
|
+
body: JSON.stringify({}),
|
|
93
|
+
};
|
|
94
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.CustomResponseHttpRequester(emptyReponse), configuration);
|
|
95
|
+
acquisition.queryUpdateWithCurrentPackage(lowerAppVersionPackage, (error, returnPackage) => {
|
|
96
|
+
assert.equal(null, error);
|
|
97
|
+
done();
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it("An unexpected (but valid) JSON response gives no update", (done) => {
|
|
101
|
+
var lowerAppVersionPackage = clone(templateCurrentPackage);
|
|
102
|
+
lowerAppVersionPackage.appVersion = "0.0.1";
|
|
103
|
+
var unexpectedResponse = {
|
|
104
|
+
statusCode: 200,
|
|
105
|
+
body: JSON.stringify({ unexpected: "response" }),
|
|
106
|
+
};
|
|
107
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.CustomResponseHttpRequester(unexpectedResponse), configuration);
|
|
108
|
+
acquisition.queryUpdateWithCurrentPackage(lowerAppVersionPackage, (error, returnPackage) => {
|
|
109
|
+
assert.equal(null, error);
|
|
110
|
+
done();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it("Package for companion app ignores high native version and gives update", (done) => {
|
|
114
|
+
var higherAppVersionCompanionPackage = clone(templateCurrentPackage);
|
|
115
|
+
higherAppVersionCompanionPackage.appVersion = "9.9.0";
|
|
116
|
+
var companionAppConfiguration = clone(configuration);
|
|
117
|
+
configuration.ignoreAppVersion = true;
|
|
118
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
119
|
+
acquisition.queryUpdateWithCurrentPackage(higherAppVersionCompanionPackage, (error, returnPackage) => {
|
|
120
|
+
assert.equal(null, error);
|
|
121
|
+
assert.deepEqual(scriptUpdateResult, returnPackage);
|
|
122
|
+
done();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
it("If latest package is mandatory, returned package is mandatory", (done) => {
|
|
126
|
+
mockApi.latestPackage.isMandatory = true;
|
|
127
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
128
|
+
acquisition.queryUpdateWithCurrentPackage(templateCurrentPackage, (error, returnPackage) => {
|
|
129
|
+
assert.equal(null, error);
|
|
130
|
+
assert.equal(true, returnPackage.isMandatory);
|
|
131
|
+
done();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
it("If invalid arguments are provided, an error is raised", (done) => {
|
|
135
|
+
var invalidPackage = clone(templateCurrentPackage);
|
|
136
|
+
invalidPackage.appVersion = null;
|
|
137
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
138
|
+
try {
|
|
139
|
+
acquisition.queryUpdateWithCurrentPackage(invalidPackage, (error, returnPackage) => {
|
|
140
|
+
assert.fail("Should throw an error if the native implementation gave an incorrect package");
|
|
141
|
+
done();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
done();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
it("If an invalid JSON response is returned by the server, an error is raised", (done) => {
|
|
149
|
+
var lowerAppVersionPackage = clone(templateCurrentPackage);
|
|
150
|
+
lowerAppVersionPackage.appVersion = "0.0.1";
|
|
151
|
+
var invalidJsonReponse = {
|
|
152
|
+
statusCode: 200,
|
|
153
|
+
body: "invalid {{ json",
|
|
154
|
+
};
|
|
155
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.CustomResponseHttpRequester(invalidJsonReponse), configuration);
|
|
156
|
+
acquisition.queryUpdateWithCurrentPackage(lowerAppVersionPackage, (error, returnPackage) => {
|
|
157
|
+
assert.notEqual(null, error);
|
|
158
|
+
done();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
it("If deploymentKey is not valid...", (done) => {
|
|
162
|
+
// TODO: behaviour is not defined
|
|
163
|
+
done();
|
|
164
|
+
});
|
|
165
|
+
it("reportStatusDeploy(...) signals completion", (done) => {
|
|
166
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
167
|
+
acquisition.reportStatusDeploy(templateCurrentPackage, acquisitionSdk.AcquisitionStatus.DeploymentFailed, "1.5.0", mockApi.validDeploymentKey, (error, parameter) => {
|
|
168
|
+
if (error) {
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
assert.equal(parameter, /*expected*/ null);
|
|
172
|
+
done();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it("reportStatusDownload(...) signals completion", (done) => {
|
|
176
|
+
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
|
|
177
|
+
acquisition.reportStatusDownload(templateCurrentPackage, (error, parameter) => {
|
|
178
|
+
if (error) {
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
assert.equal(parameter, /*expected*/ null);
|
|
182
|
+
done();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
function clone(initialObject) {
|
|
187
|
+
return JSON.parse(JSON.stringify(initialObject));
|
|
188
|
+
}
|