@revopush/code-push-cli 0.0.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.
Files changed (59) hide show
  1. package/.eslintrc.json +17 -0
  2. package/.idea/cli.iml +9 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/prettier.xml +6 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/README.md +774 -0
  9. package/bin/script/acquisition-sdk.js +178 -0
  10. package/bin/script/cli.js +23 -0
  11. package/bin/script/command-executor.js +1290 -0
  12. package/bin/script/command-parser.js +1097 -0
  13. package/bin/script/commands/debug.js +125 -0
  14. package/bin/script/hash-utils.js +203 -0
  15. package/bin/script/index.js +5 -0
  16. package/bin/script/management-sdk.js +419 -0
  17. package/bin/script/react-native-utils.js +249 -0
  18. package/bin/script/sign.js +69 -0
  19. package/bin/script/types/cli.js +40 -0
  20. package/bin/script/types/rest-definitions.js +19 -0
  21. package/bin/script/types.js +4 -0
  22. package/bin/script/utils/file-utils.js +50 -0
  23. package/bin/test/acquisition-rest-mock.js +108 -0
  24. package/bin/test/acquisition-sdk.js +188 -0
  25. package/bin/test/cli.js +1342 -0
  26. package/bin/test/hash-utils.js +149 -0
  27. package/bin/test/management-sdk.js +338 -0
  28. package/package.json +68 -0
  29. package/prettier.config.js +7 -0
  30. package/script/acquisition-sdk.ts +273 -0
  31. package/script/cli.ts +27 -0
  32. package/script/command-executor.ts +1610 -0
  33. package/script/command-parser.ts +1310 -0
  34. package/script/commands/debug.ts +148 -0
  35. package/script/hash-utils.ts +241 -0
  36. package/script/index.ts +5 -0
  37. package/script/management-sdk.ts +575 -0
  38. package/script/react-native-utils.ts +283 -0
  39. package/script/sign.ts +80 -0
  40. package/script/types/cli.ts +232 -0
  41. package/script/types/rest-definitions.ts +152 -0
  42. package/script/types.ts +35 -0
  43. package/script/utils/file-utils.ts +46 -0
  44. package/test/acquisition-rest-mock.ts +125 -0
  45. package/test/acquisition-sdk.ts +272 -0
  46. package/test/cli.ts +1692 -0
  47. package/test/hash-utils.ts +170 -0
  48. package/test/management-sdk.ts +438 -0
  49. package/test/resources/TestApp/android/app/build.gradle +56 -0
  50. package/test/resources/TestApp/iOS/TestApp/Info.plist +49 -0
  51. package/test/resources/TestApp/index.android.js +2 -0
  52. package/test/resources/TestApp/index.ios.js +2 -0
  53. package/test/resources/TestApp/index.windows.js +2 -0
  54. package/test/resources/TestApp/package.json +6 -0
  55. package/test/resources/TestApp/windows/TestApp/Package.appxmanifest +46 -0
  56. package/test/resources/ignoredMetadata.zip +0 -0
  57. package/test/resources/test.zip +0 -0
  58. package/test/superagent-mock-config.js +58 -0
  59. package/tsconfig.json +13 -0
@@ -0,0 +1,152 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ interface AccessKeyBase {
5
+ createdBy?: string;
6
+ /*legacy*/ description?: string;
7
+ /*key*/ friendlyName?: string;
8
+ /*generated key*/ name?: string;
9
+ }
10
+
11
+ /*out*/
12
+ export interface AccessKey extends AccessKeyBase {
13
+ /*generated*/ createdTime?: number;
14
+ expires: number;
15
+ /*generated*/ isSession?: boolean;
16
+ }
17
+
18
+ /*in*/
19
+ export interface AccessKeyRequest extends AccessKeyBase {
20
+ ttl?: number;
21
+ }
22
+
23
+ /*out*/
24
+ export interface DeploymentMetrics {
25
+ [packageLabelOrAppVersion: string]: UpdateMetrics;
26
+ }
27
+
28
+ /*in*/
29
+ export interface DeploymentStatusReport {
30
+ appVersion: string;
31
+ clientUniqueId?: string;
32
+ deploymentKey: string;
33
+ previousDeploymentKey?: string;
34
+ previousLabelOrAppVersion?: string;
35
+ label?: string;
36
+ status?: string;
37
+ }
38
+
39
+ /*in*/
40
+ export interface DownloadReport {
41
+ clientUniqueId: string;
42
+ deploymentKey: string;
43
+ label: string;
44
+ }
45
+
46
+ /*inout*/
47
+ export interface PackageInfo {
48
+ appVersion?: string;
49
+ description?: string;
50
+ isDisabled?: boolean;
51
+ isMandatory?: boolean;
52
+ /*generated*/ label?: string;
53
+ /*generated*/ packageHash?: string;
54
+ rollout?: number;
55
+ }
56
+
57
+ /*out*/
58
+ export interface UpdateCheckResponse extends PackageInfo {
59
+ target_binary_range?: string;
60
+ downloadURL?: string;
61
+ isAvailable: boolean;
62
+ packageSize?: number;
63
+ shouldRunBinaryVersion?: boolean;
64
+ updateAppVersion?: boolean;
65
+ }
66
+
67
+ /*out*/
68
+ export interface UpdateCheckCacheResponse {
69
+ originalPackage: UpdateCheckResponse;
70
+ rollout?: number;
71
+ rolloutPackage?: UpdateCheckResponse;
72
+ }
73
+
74
+ /*in*/
75
+ export interface UpdateCheckRequest {
76
+ appVersion: string;
77
+ clientUniqueId?: string;
78
+ deploymentKey: string;
79
+ isCompanion?: boolean;
80
+ label?: string;
81
+ packageHash?: string;
82
+ }
83
+
84
+ /*out*/
85
+ export interface UpdateMetrics {
86
+ active: number;
87
+ downloaded?: number;
88
+ failed?: number;
89
+ installed?: number;
90
+ }
91
+
92
+ /*out*/
93
+ export interface Account {
94
+ /*key*/ email: string;
95
+ name: string;
96
+ linkedProviders: string[];
97
+ }
98
+
99
+ /*out*/
100
+ export interface CollaboratorProperties {
101
+ isCurrentAccount?: boolean;
102
+ permission: string;
103
+ }
104
+
105
+ /*out*/
106
+ export interface CollaboratorMap {
107
+ [email: string]: CollaboratorProperties;
108
+ }
109
+
110
+ /*inout*/
111
+ export interface App {
112
+ /*generated*/ collaborators?: CollaboratorMap;
113
+ /*key*/ name: string;
114
+ /*generated*/ deployments?: string[];
115
+ }
116
+
117
+ /*in*/
118
+ export interface AppCreationRequest extends App {
119
+ manuallyProvisionDeployments?: boolean;
120
+ }
121
+
122
+ /*inout*/
123
+ export interface Deployment {
124
+ /*generated key*/ key?: string;
125
+ /*key*/ name: string;
126
+ /*generated*/ package?: Package;
127
+ }
128
+
129
+ /*out*/
130
+ export interface BlobInfo {
131
+ size: number;
132
+ url: string;
133
+ }
134
+
135
+ /*out*/
136
+ export interface PackageHashToBlobInfoMap {
137
+ [packageHash: string]: BlobInfo;
138
+ }
139
+
140
+ /*inout*/
141
+ export interface Package extends PackageInfo {
142
+ /*generated*/ blobUrl: string;
143
+ /*generated*/ diffPackageMap?: PackageHashToBlobInfoMap;
144
+ /*generated*/ originalLabel?: string; // Set on "Promote" and "Rollback"
145
+ /*generated*/ originalDeployment?: string; // Set on "Promote"
146
+ /*generated*/ releasedBy?: string; // Set by commitPackage
147
+ /*generated*/ releaseMethod?: string; // "Upload", "Promote" or "Rollback". Unknown if unspecified
148
+ /*generated*/ size: number;
149
+ /*generated*/ uploadTime: number;
150
+ }
151
+
152
+ export * from "./rest-definitions";
@@ -0,0 +1,35 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ export {
5
+ AccessKeyRequest,
6
+ Account,
7
+ App,
8
+ CollaboratorMap,
9
+ CollaboratorProperties,
10
+ Deployment,
11
+ DeploymentMetrics,
12
+ Package,
13
+ PackageInfo,
14
+ AccessKey as ServerAccessKey,
15
+ UpdateMetrics,
16
+ } from "../script/types/rest-definitions";
17
+
18
+ export interface CodePushError {
19
+ message: string;
20
+ statusCode: number;
21
+ }
22
+
23
+ export interface AccessKey {
24
+ createdTime: number;
25
+ expires: number;
26
+ name: string;
27
+ key?: string;
28
+ }
29
+
30
+ export interface Session {
31
+ loggedInTime: number;
32
+ machineName: string;
33
+ }
34
+
35
+ export type Headers = { [headerName: string]: string };
@@ -0,0 +1,46 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import * as rimraf from "rimraf";
4
+ import * as temp from "temp";
5
+
6
+ export function isBinaryOrZip(path: string): boolean {
7
+ return path.search(/\.zip$/i) !== -1 || path.search(/\.apk$/i) !== -1 || path.search(/\.ipa$/i) !== -1;
8
+ }
9
+
10
+ export function isDirectory(path: string): boolean {
11
+ return fs.statSync(path).isDirectory();
12
+ }
13
+
14
+ export function fileExists(file: string): boolean {
15
+ try {
16
+ return fs.statSync(file).isFile();
17
+ } catch (e) {
18
+ return false;
19
+ }
20
+ };
21
+
22
+ export function copyFileToTmpDir(filePath: string): string {
23
+ if (!isDirectory(filePath)) {
24
+ const outputFolderPath: string = temp.mkdirSync("code-push");
25
+ rimraf.sync(outputFolderPath);
26
+ fs.mkdirSync(outputFolderPath);
27
+
28
+ const outputFilePath: string = path.join(outputFolderPath, path.basename(filePath));
29
+ fs.writeFileSync(outputFilePath, fs.readFileSync(filePath));
30
+
31
+ return outputFolderPath;
32
+ }
33
+ }
34
+
35
+ export function fileDoesNotExistOrIsDirectory(path: string): boolean {
36
+ try {
37
+ return isDirectory(path);
38
+ } catch (error) {
39
+ return true;
40
+ }
41
+ }
42
+
43
+ export function normalizePath(filePath: string): string {
44
+ //replace all backslashes coming from cli running on windows machines by slashes
45
+ return filePath.replace(/\\/g, "/");
46
+ }
@@ -0,0 +1,125 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ import * as express from "express";
5
+ import * as querystring from "querystring";
6
+
7
+ import * as acquisitionSdk from "../script/acquisition-sdk";
8
+ import * as rest from "../script/types/rest-definitions";
9
+
10
+ export var validDeploymentKey = "asdfasdfawerqw";
11
+ export var latestPackage = <rest.UpdateCheckResponse>{
12
+ downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
13
+ description: "Angry flappy birds",
14
+ appVersion: "1.5.0",
15
+ label: "2.4.0",
16
+ isMandatory: false,
17
+ isAvailable: true,
18
+ updateAppVersion: false,
19
+ packageHash: "hash240",
20
+ packageSize: 1024,
21
+ };
22
+
23
+ export var serverUrl = "http://myurl.com";
24
+ var reportStatusDeployUrl = serverUrl + "/reportStatus/deploy";
25
+ var reportStatusDownloadUrl = serverUrl + "/reportStatus/download";
26
+ var updateCheckUrl = serverUrl + "/updateCheck?";
27
+
28
+ export class HttpRequester implements acquisitionSdk.Http.Requester {
29
+ public request(
30
+ verb: acquisitionSdk.Http.Verb,
31
+ url: string,
32
+ requestBodyOrCallback: string | acquisitionSdk.Callback<acquisitionSdk.Http.Response>,
33
+ callback?: acquisitionSdk.Callback<acquisitionSdk.Http.Response>
34
+ ): void {
35
+ if (!callback && typeof requestBodyOrCallback === "function") {
36
+ callback = <acquisitionSdk.Callback<acquisitionSdk.Http.Response>>requestBodyOrCallback;
37
+ }
38
+
39
+ if (verb === acquisitionSdk.Http.Verb.GET && url.indexOf(updateCheckUrl) === 0) {
40
+ var params = querystring.parse(url.substring(updateCheckUrl.length));
41
+ Server.onUpdateCheck(params, callback);
42
+ } else if (verb === acquisitionSdk.Http.Verb.POST && url === reportStatusDeployUrl) {
43
+ Server.onReportStatus(callback);
44
+ } else if (verb === acquisitionSdk.Http.Verb.POST && url === reportStatusDownloadUrl) {
45
+ Server.onReportStatus(callback);
46
+ } else {
47
+ throw new Error("Unexpected call");
48
+ }
49
+ }
50
+ }
51
+
52
+ export class CustomResponseHttpRequester implements acquisitionSdk.Http.Requester {
53
+ response: acquisitionSdk.Http.Response;
54
+
55
+ constructor(response: acquisitionSdk.Http.Response) {
56
+ this.response = response;
57
+ }
58
+
59
+ public request(
60
+ verb: acquisitionSdk.Http.Verb,
61
+ url: string,
62
+ requestBodyOrCallback: string | acquisitionSdk.Callback<acquisitionSdk.Http.Response>,
63
+ callback?: acquisitionSdk.Callback<acquisitionSdk.Http.Response>
64
+ ): void {
65
+ if (typeof requestBodyOrCallback !== "function") {
66
+ throw new Error("Unexpected request body");
67
+ }
68
+
69
+ callback = <acquisitionSdk.Callback<acquisitionSdk.Http.Response>>requestBodyOrCallback;
70
+ callback(null, this.response);
71
+ }
72
+ }
73
+
74
+ class Server {
75
+ public static onAcquire(params: any, callback: acquisitionSdk.Callback<acquisitionSdk.Http.Response>): void {
76
+ if (params.deploymentKey !== validDeploymentKey) {
77
+ callback(/*error=*/ null, {
78
+ statusCode: 200,
79
+ body: JSON.stringify({ updateInfo: { isAvailable: false } }),
80
+ });
81
+ } else {
82
+ callback(/*error=*/ null, {
83
+ statusCode: 200,
84
+ body: JSON.stringify({ updateInfo: latestPackage }),
85
+ });
86
+ }
87
+ }
88
+
89
+ public static onUpdateCheck(params: any, callback: acquisitionSdk.Callback<acquisitionSdk.Http.Response>): void {
90
+ var updateRequest: rest.UpdateCheckRequest = {
91
+ deploymentKey: params.deploymentKey,
92
+ appVersion: params.appVersion,
93
+ packageHash: params.packageHash,
94
+ isCompanion: !!params.isCompanion,
95
+ label: params.label,
96
+ };
97
+
98
+ if (!updateRequest.deploymentKey || !updateRequest.appVersion) {
99
+ callback(/*error=*/ null, { statusCode: 400 });
100
+ } else {
101
+ var updateInfo = <rest.UpdateCheckResponse>{ isAvailable: false };
102
+ if (updateRequest.deploymentKey === validDeploymentKey) {
103
+ if (updateRequest.isCompanion || updateRequest.appVersion === latestPackage.appVersion) {
104
+ if (updateRequest.packageHash !== latestPackage.packageHash) {
105
+ updateInfo = latestPackage;
106
+ }
107
+ } else if (updateRequest.appVersion < latestPackage.appVersion) {
108
+ updateInfo = <rest.UpdateCheckResponse>(<any>{
109
+ updateAppVersion: true,
110
+ appVersion: latestPackage.appVersion,
111
+ });
112
+ }
113
+ }
114
+
115
+ callback(/*error=*/ null, {
116
+ statusCode: 200,
117
+ body: JSON.stringify({ updateInfo: updateInfo }),
118
+ });
119
+ }
120
+ }
121
+
122
+ public static onReportStatus(callback: acquisitionSdk.Callback<acquisitionSdk.Http.Response>): void {
123
+ callback(/*error*/ null, /*response*/ { statusCode: 200 });
124
+ }
125
+ }
@@ -0,0 +1,272 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ import * as assert from "assert";
5
+ import * as express from "express";
6
+ import * as http from "http";
7
+
8
+ import * as acquisitionSdk from "../script/acquisition-sdk";
9
+ import * as mockApi from "./acquisition-rest-mock";
10
+ import * as rest from "../script/types/rest-definitions";
11
+
12
+ var latestPackage: rest.UpdateCheckResponse = clone(mockApi.latestPackage);
13
+
14
+ var configuration: acquisitionSdk.Configuration = {
15
+ appVersion: "1.5.0",
16
+ clientUniqueId: "My iPhone",
17
+ deploymentKey: mockApi.validDeploymentKey,
18
+ serverUrl: mockApi.serverUrl,
19
+ };
20
+
21
+ var templateCurrentPackage: acquisitionSdk.Package = {
22
+ deploymentKey: mockApi.validDeploymentKey,
23
+ description: "sdfsdf",
24
+ label: "v1",
25
+ appVersion: latestPackage.appVersion,
26
+ packageHash: "hash001",
27
+ isMandatory: false,
28
+ packageSize: 100,
29
+ };
30
+
31
+ var scriptUpdateResult: acquisitionSdk.RemotePackage = {
32
+ deploymentKey: mockApi.validDeploymentKey,
33
+ description: latestPackage.description,
34
+ downloadUrl: latestPackage.downloadURL,
35
+ label: latestPackage.label,
36
+ appVersion: latestPackage.appVersion,
37
+ isMandatory: latestPackage.isMandatory,
38
+ packageHash: latestPackage.packageHash,
39
+ packageSize: latestPackage.packageSize,
40
+ };
41
+
42
+ var nativeUpdateResult: acquisitionSdk.NativeUpdateNotification = {
43
+ updateAppVersion: true,
44
+ appVersion: latestPackage.appVersion,
45
+ };
46
+
47
+ describe("Acquisition SDK", () => {
48
+ it("Package with lower label and different package hash gives update", (done: Mocha.Done) => {
49
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
50
+ acquisition.queryUpdateWithCurrentPackage(
51
+ templateCurrentPackage,
52
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
53
+ assert.equal(null, error);
54
+ assert.deepEqual(scriptUpdateResult, returnPackage);
55
+ done();
56
+ }
57
+ );
58
+ });
59
+
60
+ it("Package with equal package hash gives no update", (done: Mocha.Done) => {
61
+ var equalVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
62
+ equalVersionPackage.packageHash = latestPackage.packageHash;
63
+
64
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
65
+ acquisition.queryUpdateWithCurrentPackage(
66
+ equalVersionPackage,
67
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
68
+ assert.equal(null, error);
69
+ assert.equal(null, returnPackage);
70
+ done();
71
+ }
72
+ );
73
+ });
74
+
75
+ it("Package with higher different hash and higher label version gives update", (done: Mocha.Done) => {
76
+ var higherVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
77
+ higherVersionPackage.packageHash = "hash990";
78
+
79
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
80
+ acquisition.queryUpdateWithCurrentPackage(
81
+ higherVersionPackage,
82
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
83
+ assert.equal(null, error);
84
+ assert.deepEqual(scriptUpdateResult, returnPackage);
85
+ done();
86
+ }
87
+ );
88
+ });
89
+
90
+ it("Package with lower native version gives update notification", (done: Mocha.Done) => {
91
+ var lowerAppVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
92
+ lowerAppVersionPackage.appVersion = "0.0.1";
93
+
94
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
95
+ acquisition.queryUpdateWithCurrentPackage(
96
+ lowerAppVersionPackage,
97
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
98
+ assert.equal(null, error);
99
+ assert.deepEqual(nativeUpdateResult, returnPackage);
100
+ done();
101
+ }
102
+ );
103
+ });
104
+
105
+ it("Package with higher native version gives no update", (done: Mocha.Done) => {
106
+ var higherAppVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
107
+ higherAppVersionPackage.appVersion = "9.9.0";
108
+
109
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
110
+ acquisition.queryUpdateWithCurrentPackage(
111
+ higherAppVersionPackage,
112
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
113
+ assert.equal(null, error);
114
+ assert.deepEqual(null, returnPackage);
115
+ done();
116
+ }
117
+ );
118
+ });
119
+
120
+ it("An empty response gives no update", (done: Mocha.Done) => {
121
+ var lowerAppVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
122
+ lowerAppVersionPackage.appVersion = "0.0.1";
123
+
124
+ var emptyReponse: acquisitionSdk.Http.Response = {
125
+ statusCode: 200,
126
+ body: JSON.stringify({}),
127
+ };
128
+
129
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.CustomResponseHttpRequester(emptyReponse), configuration);
130
+ acquisition.queryUpdateWithCurrentPackage(
131
+ lowerAppVersionPackage,
132
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
133
+ assert.equal(null, error);
134
+ done();
135
+ }
136
+ );
137
+ });
138
+
139
+ it("An unexpected (but valid) JSON response gives no update", (done: Mocha.Done) => {
140
+ var lowerAppVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
141
+ lowerAppVersionPackage.appVersion = "0.0.1";
142
+
143
+ var unexpectedResponse: acquisitionSdk.Http.Response = {
144
+ statusCode: 200,
145
+ body: JSON.stringify({ unexpected: "response" }),
146
+ };
147
+
148
+ var acquisition = new acquisitionSdk.AcquisitionManager(
149
+ new mockApi.CustomResponseHttpRequester(unexpectedResponse),
150
+ configuration
151
+ );
152
+ acquisition.queryUpdateWithCurrentPackage(
153
+ lowerAppVersionPackage,
154
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
155
+ assert.equal(null, error);
156
+ done();
157
+ }
158
+ );
159
+ });
160
+
161
+ it("Package for companion app ignores high native version and gives update", (done: Mocha.Done) => {
162
+ var higherAppVersionCompanionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
163
+ higherAppVersionCompanionPackage.appVersion = "9.9.0";
164
+
165
+ var companionAppConfiguration = clone(configuration);
166
+ configuration.ignoreAppVersion = true;
167
+
168
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
169
+ acquisition.queryUpdateWithCurrentPackage(
170
+ higherAppVersionCompanionPackage,
171
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
172
+ assert.equal(null, error);
173
+ assert.deepEqual(scriptUpdateResult, returnPackage);
174
+ done();
175
+ }
176
+ );
177
+ });
178
+
179
+ it("If latest package is mandatory, returned package is mandatory", (done: Mocha.Done) => {
180
+ mockApi.latestPackage.isMandatory = true;
181
+
182
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
183
+ acquisition.queryUpdateWithCurrentPackage(templateCurrentPackage, (error: Error, returnPackage: acquisitionSdk.RemotePackage) => {
184
+ assert.equal(null, error);
185
+ assert.equal(true, returnPackage.isMandatory);
186
+ done();
187
+ });
188
+ });
189
+
190
+ it("If invalid arguments are provided, an error is raised", (done: Mocha.Done) => {
191
+ var invalidPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
192
+ invalidPackage.appVersion = null;
193
+
194
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
195
+ try {
196
+ acquisition.queryUpdateWithCurrentPackage(
197
+ invalidPackage,
198
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
199
+ assert.fail("Should throw an error if the native implementation gave an incorrect package");
200
+ done();
201
+ }
202
+ );
203
+ } catch (error) {
204
+ done();
205
+ }
206
+ });
207
+
208
+ it("If an invalid JSON response is returned by the server, an error is raised", (done: Mocha.Done) => {
209
+ var lowerAppVersionPackage: acquisitionSdk.Package = clone(templateCurrentPackage);
210
+ lowerAppVersionPackage.appVersion = "0.0.1";
211
+
212
+ var invalidJsonReponse: acquisitionSdk.Http.Response = {
213
+ statusCode: 200,
214
+ body: "invalid {{ json",
215
+ };
216
+
217
+ var acquisition = new acquisitionSdk.AcquisitionManager(
218
+ new mockApi.CustomResponseHttpRequester(invalidJsonReponse),
219
+ configuration
220
+ );
221
+ acquisition.queryUpdateWithCurrentPackage(
222
+ lowerAppVersionPackage,
223
+ (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
224
+ assert.notEqual(null, error);
225
+ done();
226
+ }
227
+ );
228
+ });
229
+
230
+ it("If deploymentKey is not valid...", (done: Mocha.Done) => {
231
+ // TODO: behaviour is not defined
232
+ done();
233
+ });
234
+
235
+ it("reportStatusDeploy(...) signals completion", (done: Mocha.Done): void => {
236
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
237
+
238
+ acquisition.reportStatusDeploy(
239
+ templateCurrentPackage,
240
+ acquisitionSdk.AcquisitionStatus.DeploymentFailed,
241
+ "1.5.0",
242
+ mockApi.validDeploymentKey,
243
+ (error: Error, parameter: void): void => {
244
+ if (error) {
245
+ throw error;
246
+ }
247
+
248
+ assert.equal(parameter, /*expected*/ null);
249
+
250
+ done();
251
+ }
252
+ );
253
+ });
254
+
255
+ it("reportStatusDownload(...) signals completion", (done: Mocha.Done): void => {
256
+ var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);
257
+
258
+ acquisition.reportStatusDownload(templateCurrentPackage, (error: Error, parameter: void): void => {
259
+ if (error) {
260
+ throw error;
261
+ }
262
+
263
+ assert.equal(parameter, /*expected*/ null);
264
+
265
+ done();
266
+ });
267
+ });
268
+ });
269
+
270
+ function clone<T>(initialObject: T): T {
271
+ return JSON.parse(JSON.stringify(initialObject));
272
+ }