@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.
- package/.eslintrc.json +17 -0
- package/.idea/cli.iml +9 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +774 -0
- package/bin/script/acquisition-sdk.js +178 -0
- package/bin/script/cli.js +23 -0
- package/bin/script/command-executor.js +1290 -0
- package/bin/script/command-parser.js +1097 -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 +419 -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 +68 -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 +1610 -0
- package/script/command-parser.ts +1310 -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 +575 -0
- package/script/react-native-utils.ts +283 -0
- package/script/sign.ts +80 -0
- package/script/types/cli.ts +232 -0
- package/script/types/rest-definitions.ts +152 -0
- package/script/types.ts +35 -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,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs/promises");
|
|
4
|
+
const hashUtils = require("./hash-utils");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const jwt = require("jsonwebtoken");
|
|
7
|
+
const file_utils_1 = require("./utils/file-utils");
|
|
8
|
+
const CURRENT_CLAIM_VERSION = "1.0.0";
|
|
9
|
+
const METADATA_FILE_NAME = ".codepushrelease";
|
|
10
|
+
async function sign(privateKeyPath, updateContentsPath) {
|
|
11
|
+
if (!privateKeyPath) {
|
|
12
|
+
return Promise.resolve(null);
|
|
13
|
+
}
|
|
14
|
+
let privateKey;
|
|
15
|
+
try {
|
|
16
|
+
privateKey = await fs.readFile(privateKeyPath);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return Promise.reject(new Error(`The path specified for the signing key ("${privateKeyPath}") was not valid.`));
|
|
20
|
+
}
|
|
21
|
+
// If releasing a single file, copy the file to a temporary 'CodePush' directory in which to publish the release
|
|
22
|
+
try {
|
|
23
|
+
if (!(0, file_utils_1.isDirectory)(updateContentsPath)) {
|
|
24
|
+
updateContentsPath = (0, file_utils_1.copyFileToTmpDir)(updateContentsPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
Promise.reject(error);
|
|
29
|
+
}
|
|
30
|
+
const signatureFilePath = path.join(updateContentsPath, METADATA_FILE_NAME);
|
|
31
|
+
let prevSignatureExists = true;
|
|
32
|
+
try {
|
|
33
|
+
await fs.access(signatureFilePath, fs.constants.F_OK);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err.code === "ENOENT") {
|
|
37
|
+
prevSignatureExists = false;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return Promise.reject(new Error(`Could not delete previous release signature at ${signatureFilePath}.
|
|
41
|
+
Please, check your access rights.`));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (prevSignatureExists) {
|
|
45
|
+
console.log(`Deleting previous release signature at ${signatureFilePath}`);
|
|
46
|
+
await fs.rmdir(signatureFilePath);
|
|
47
|
+
}
|
|
48
|
+
const hash = await hashUtils.generatePackageHashFromDirectory(updateContentsPath, path.join(updateContentsPath, ".."));
|
|
49
|
+
const claims = {
|
|
50
|
+
claimVersion: CURRENT_CLAIM_VERSION,
|
|
51
|
+
contentHash: hash,
|
|
52
|
+
};
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
jwt.sign(claims, privateKey, { algorithm: "RS256" }, async (err, signedJwt) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
reject(new Error("The specified signing key file was not valid"));
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await fs.writeFile(signatureFilePath, signedJwt);
|
|
60
|
+
console.log(`Generated a release signature and wrote it to ${signatureFilePath}`);
|
|
61
|
+
resolve(null);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.default = sign;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CommandType = void 0;
|
|
6
|
+
var CommandType;
|
|
7
|
+
(function (CommandType) {
|
|
8
|
+
CommandType[CommandType["accessKeyAdd"] = 0] = "accessKeyAdd";
|
|
9
|
+
CommandType[CommandType["accessKeyPatch"] = 1] = "accessKeyPatch";
|
|
10
|
+
CommandType[CommandType["accessKeyList"] = 2] = "accessKeyList";
|
|
11
|
+
CommandType[CommandType["accessKeyRemove"] = 3] = "accessKeyRemove";
|
|
12
|
+
CommandType[CommandType["appAdd"] = 4] = "appAdd";
|
|
13
|
+
CommandType[CommandType["appList"] = 5] = "appList";
|
|
14
|
+
CommandType[CommandType["appRemove"] = 6] = "appRemove";
|
|
15
|
+
CommandType[CommandType["appRename"] = 7] = "appRename";
|
|
16
|
+
CommandType[CommandType["appTransfer"] = 8] = "appTransfer";
|
|
17
|
+
CommandType[CommandType["collaboratorAdd"] = 9] = "collaboratorAdd";
|
|
18
|
+
CommandType[CommandType["collaboratorList"] = 10] = "collaboratorList";
|
|
19
|
+
CommandType[CommandType["collaboratorRemove"] = 11] = "collaboratorRemove";
|
|
20
|
+
CommandType[CommandType["debug"] = 12] = "debug";
|
|
21
|
+
CommandType[CommandType["deploymentAdd"] = 13] = "deploymentAdd";
|
|
22
|
+
CommandType[CommandType["deploymentHistory"] = 14] = "deploymentHistory";
|
|
23
|
+
CommandType[CommandType["deploymentHistoryClear"] = 15] = "deploymentHistoryClear";
|
|
24
|
+
CommandType[CommandType["deploymentList"] = 16] = "deploymentList";
|
|
25
|
+
CommandType[CommandType["deploymentMetrics"] = 17] = "deploymentMetrics";
|
|
26
|
+
CommandType[CommandType["deploymentRemove"] = 18] = "deploymentRemove";
|
|
27
|
+
CommandType[CommandType["deploymentRename"] = 19] = "deploymentRename";
|
|
28
|
+
CommandType[CommandType["link"] = 20] = "link";
|
|
29
|
+
CommandType[CommandType["login"] = 21] = "login";
|
|
30
|
+
CommandType[CommandType["logout"] = 22] = "logout";
|
|
31
|
+
CommandType[CommandType["patch"] = 23] = "patch";
|
|
32
|
+
CommandType[CommandType["promote"] = 24] = "promote";
|
|
33
|
+
CommandType[CommandType["register"] = 25] = "register";
|
|
34
|
+
CommandType[CommandType["release"] = 26] = "release";
|
|
35
|
+
CommandType[CommandType["releaseReact"] = 27] = "releaseReact";
|
|
36
|
+
CommandType[CommandType["rollback"] = 28] = "rollback";
|
|
37
|
+
CommandType[CommandType["sessionList"] = 29] = "sessionList";
|
|
38
|
+
CommandType[CommandType["sessionRemove"] = 30] = "sessionRemove";
|
|
39
|
+
CommandType[CommandType["whoami"] = 31] = "whoami";
|
|
40
|
+
})(CommandType || (exports.CommandType = CommandType = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
__exportStar(require("./rest-definitions"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizePath = exports.fileDoesNotExistOrIsDirectory = exports.copyFileToTmpDir = exports.fileExists = exports.isDirectory = exports.isBinaryOrZip = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const rimraf = require("rimraf");
|
|
7
|
+
const temp = require("temp");
|
|
8
|
+
function isBinaryOrZip(path) {
|
|
9
|
+
return path.search(/\.zip$/i) !== -1 || path.search(/\.apk$/i) !== -1 || path.search(/\.ipa$/i) !== -1;
|
|
10
|
+
}
|
|
11
|
+
exports.isBinaryOrZip = isBinaryOrZip;
|
|
12
|
+
function isDirectory(path) {
|
|
13
|
+
return fs.statSync(path).isDirectory();
|
|
14
|
+
}
|
|
15
|
+
exports.isDirectory = isDirectory;
|
|
16
|
+
function fileExists(file) {
|
|
17
|
+
try {
|
|
18
|
+
return fs.statSync(file).isFile();
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.fileExists = fileExists;
|
|
25
|
+
;
|
|
26
|
+
function copyFileToTmpDir(filePath) {
|
|
27
|
+
if (!isDirectory(filePath)) {
|
|
28
|
+
const outputFolderPath = temp.mkdirSync("code-push");
|
|
29
|
+
rimraf.sync(outputFolderPath);
|
|
30
|
+
fs.mkdirSync(outputFolderPath);
|
|
31
|
+
const outputFilePath = path.join(outputFolderPath, path.basename(filePath));
|
|
32
|
+
fs.writeFileSync(outputFilePath, fs.readFileSync(filePath));
|
|
33
|
+
return outputFolderPath;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.copyFileToTmpDir = copyFileToTmpDir;
|
|
37
|
+
function fileDoesNotExistOrIsDirectory(path) {
|
|
38
|
+
try {
|
|
39
|
+
return isDirectory(path);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.fileDoesNotExistOrIsDirectory = fileDoesNotExistOrIsDirectory;
|
|
46
|
+
function normalizePath(filePath) {
|
|
47
|
+
//replace all backslashes coming from cli running on windows machines by slashes
|
|
48
|
+
return filePath.replace(/\\/g, "/");
|
|
49
|
+
}
|
|
50
|
+
exports.normalizePath = normalizePath;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CustomResponseHttpRequester = exports.HttpRequester = exports.serverUrl = exports.latestPackage = exports.validDeploymentKey = void 0;
|
|
6
|
+
const querystring = require("querystring");
|
|
7
|
+
exports.validDeploymentKey = "asdfasdfawerqw";
|
|
8
|
+
exports.latestPackage = {
|
|
9
|
+
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
|
10
|
+
description: "Angry flappy birds",
|
|
11
|
+
appVersion: "1.5.0",
|
|
12
|
+
label: "2.4.0",
|
|
13
|
+
isMandatory: false,
|
|
14
|
+
isAvailable: true,
|
|
15
|
+
updateAppVersion: false,
|
|
16
|
+
packageHash: "hash240",
|
|
17
|
+
packageSize: 1024,
|
|
18
|
+
};
|
|
19
|
+
exports.serverUrl = "http://myurl.com";
|
|
20
|
+
var reportStatusDeployUrl = exports.serverUrl + "/reportStatus/deploy";
|
|
21
|
+
var reportStatusDownloadUrl = exports.serverUrl + "/reportStatus/download";
|
|
22
|
+
var updateCheckUrl = exports.serverUrl + "/updateCheck?";
|
|
23
|
+
class HttpRequester {
|
|
24
|
+
request(verb, url, requestBodyOrCallback, callback) {
|
|
25
|
+
if (!callback && typeof requestBodyOrCallback === "function") {
|
|
26
|
+
callback = requestBodyOrCallback;
|
|
27
|
+
}
|
|
28
|
+
if (verb === 0 /* acquisitionSdk.Http.Verb.GET */ && url.indexOf(updateCheckUrl) === 0) {
|
|
29
|
+
var params = querystring.parse(url.substring(updateCheckUrl.length));
|
|
30
|
+
Server.onUpdateCheck(params, callback);
|
|
31
|
+
}
|
|
32
|
+
else if (verb === 2 /* acquisitionSdk.Http.Verb.POST */ && url === reportStatusDeployUrl) {
|
|
33
|
+
Server.onReportStatus(callback);
|
|
34
|
+
}
|
|
35
|
+
else if (verb === 2 /* acquisitionSdk.Http.Verb.POST */ && url === reportStatusDownloadUrl) {
|
|
36
|
+
Server.onReportStatus(callback);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error("Unexpected call");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.HttpRequester = HttpRequester;
|
|
44
|
+
class CustomResponseHttpRequester {
|
|
45
|
+
response;
|
|
46
|
+
constructor(response) {
|
|
47
|
+
this.response = response;
|
|
48
|
+
}
|
|
49
|
+
request(verb, url, requestBodyOrCallback, callback) {
|
|
50
|
+
if (typeof requestBodyOrCallback !== "function") {
|
|
51
|
+
throw new Error("Unexpected request body");
|
|
52
|
+
}
|
|
53
|
+
callback = requestBodyOrCallback;
|
|
54
|
+
callback(null, this.response);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.CustomResponseHttpRequester = CustomResponseHttpRequester;
|
|
58
|
+
class Server {
|
|
59
|
+
static onAcquire(params, callback) {
|
|
60
|
+
if (params.deploymentKey !== exports.validDeploymentKey) {
|
|
61
|
+
callback(/*error=*/ null, {
|
|
62
|
+
statusCode: 200,
|
|
63
|
+
body: JSON.stringify({ updateInfo: { isAvailable: false } }),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
callback(/*error=*/ null, {
|
|
68
|
+
statusCode: 200,
|
|
69
|
+
body: JSON.stringify({ updateInfo: exports.latestPackage }),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
static onUpdateCheck(params, callback) {
|
|
74
|
+
var updateRequest = {
|
|
75
|
+
deploymentKey: params.deploymentKey,
|
|
76
|
+
appVersion: params.appVersion,
|
|
77
|
+
packageHash: params.packageHash,
|
|
78
|
+
isCompanion: !!params.isCompanion,
|
|
79
|
+
label: params.label,
|
|
80
|
+
};
|
|
81
|
+
if (!updateRequest.deploymentKey || !updateRequest.appVersion) {
|
|
82
|
+
callback(/*error=*/ null, { statusCode: 400 });
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
var updateInfo = { isAvailable: false };
|
|
86
|
+
if (updateRequest.deploymentKey === exports.validDeploymentKey) {
|
|
87
|
+
if (updateRequest.isCompanion || updateRequest.appVersion === exports.latestPackage.appVersion) {
|
|
88
|
+
if (updateRequest.packageHash !== exports.latestPackage.packageHash) {
|
|
89
|
+
updateInfo = exports.latestPackage;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (updateRequest.appVersion < exports.latestPackage.appVersion) {
|
|
93
|
+
updateInfo = {
|
|
94
|
+
updateAppVersion: true,
|
|
95
|
+
appVersion: exports.latestPackage.appVersion,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
callback(/*error=*/ null, {
|
|
100
|
+
statusCode: 200,
|
|
101
|
+
body: JSON.stringify({ updateInfo: updateInfo }),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
static onReportStatus(callback) {
|
|
106
|
+
callback(/*error*/ null, /*response*/ { statusCode: 200 });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -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
|
+
}
|