Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DordeDimitrijev committed Nov 20, 2024
1 parent 315ba25 commit b9a7352
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/script/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ export class AcquisitionStatus {
}

export class AcquisitionManager {
private readonly BASER_URL_PART = "appcenter.ms"
private readonly BASER_URL_PART = "appcenter.ms";
private _appVersion: string;
private _clientUniqueId: string;
private _deploymentKey: string;
private _httpRequester: Http.Requester;
private _ignoreAppVersion: boolean;
private _serverUrl: string;
private _publicPrefixUrl: string = "v0.1/public/codepush/";

private static _apiCallsDisabled: boolean = false;
constructor(httpRequester: Http.Requester, configuration: Configuration) {
this._httpRequester = httpRequester;
Expand All @@ -80,6 +81,7 @@ export class AcquisitionManager {
this._deploymentKey = configuration.deploymentKey;
this._ignoreAppVersion = configuration.ignoreAppVersion;
}

// Used for Tests
public static get apiCallsDisabled(): boolean {
return this._apiCallsDisabled;
Expand All @@ -93,7 +95,7 @@ export class AcquisitionManager {

public queryUpdateWithCurrentPackage(currentPackage: Package, callback?: Callback<RemotePackage | NativeUpdateNotification>): void {
if (AcquisitionManager._apiCallsDisabled) {
console.log(`[CodePush] Api calls are disabled, skipping queryUpdateWithCurrentPackage`);
console.log(`[CodePush] Api calls are disabled, skipping API call`);
callback(/*error=*/ null, /*remotePackage=*/ null);
return;
}
Expand Down Expand Up @@ -166,7 +168,8 @@ export class AcquisitionManager {

public reportStatusDeploy(deployedPackage?: Package, status?: string, previousLabelOrAppVersion?: string, previousDeploymentKey?: string, callback?: Callback<void>): void {
if (AcquisitionManager._apiCallsDisabled) {
console.log(`[CodePush] Api calls are disabled, skipping reportStatusDeploy`);
console.log(`[CodePush] Api calls are disabled, skipping API call`);
callback(null, null)
return;
}

Expand Down Expand Up @@ -232,7 +235,8 @@ export class AcquisitionManager {

public reportStatusDownload(downloadedPackage: Package, callback?: Callback<void>): void {
if (AcquisitionManager._apiCallsDisabled) {
console.log(`[CodePush] Api calls are disabled, skipping reportStatusDownload`);
console.log(`[CodePush] Api calls are disabled, skipping API call`);
callback(null, null)
return;
}

Expand All @@ -255,6 +259,7 @@ export class AcquisitionManager {
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
return;
}

callback(/*error*/ null, /*not used*/ null);
}
});
Expand Down
17 changes: 16 additions & 1 deletion src/test/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,15 @@ describe("Acquisition SDK", () => {

it("doesnt disable api calls on successful response", (done: Mocha.Done): void => {
var acquisition = new acquisitionSdk.AcquisitionManager(new mockApi.HttpRequester(), configuration);


acquisition.queryUpdateWithCurrentPackage(templateCurrentPackage, (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, false);
});

acquisition.queryUpdateWithCurrentPackage(templateCurrentPackage, (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
assert.notStrictEqual(returnPackage, null)
});

acquisition.reportStatusDeploy(templateCurrentPackage, acquisitionSdk.AcquisitionStatus.DeploymentSucceeded, "1.5.0", mockApi.validDeploymentKey, ((error: Error, parameter: void): void => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, false);
}))
Expand All @@ -252,6 +260,13 @@ describe("Acquisition SDK", () => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, true);
});

acquisition.reportStatusDeploy(templateCurrentPackage, acquisitionSdk.AcquisitionStatus.DeploymentSucceeded, "1.5.0", mockApi.validDeploymentKey, ((error: Error, parameter: void): void => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, true);
}))
acquisition.reportStatusDownload(templateCurrentPackage, ((error: Error, parameter: void): void => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, true);
}));

acquisition.queryUpdateWithCurrentPackage(templateCurrentPackage, (error: Error, returnPackage: acquisitionSdk.RemotePackage | acquisitionSdk.NativeUpdateNotification) => {
assert.strictEqual(returnPackage, null);
})
Expand Down

0 comments on commit b9a7352

Please sign in to comment.