Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DordeDimitrijev committed Nov 19, 2024
1 parent 9baedae commit 315ba25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
5 changes: 3 additions & 2 deletions src/script/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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`);
callback(/*error=*/ null, /*remotePackage=*/ null);
return;
}

Expand Down Expand Up @@ -165,7 +166,7 @@ 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 queryUpdateWithCurrentPackage`);
console.log(`[CodePush] Api calls are disabled, skipping reportStatusDeploy`);
return;
}

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

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

Expand Down
30 changes: 15 additions & 15 deletions src/test/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ 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.reportStatusDeploy(templateCurrentPackage, acquisitionSdk.AcquisitionStatus.DeploymentSucceeded, "1.5.0", mockApi.validDeploymentKey, ((error: Error, parameter: void): void => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, false);
}))

acquisition.reportStatusDownload(templateCurrentPackage, ((error: Error, parameter: void): void => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, false);
}));
done();
})

it("disables api calls on unsuccessful response", (done: Mocha.Done): void => {
var invalidJsonResponse: acquisitionSdk.Http.Response = {
statusCode: 404,
Expand All @@ -237,27 +250,14 @@ describe("Acquisition SDK", () => {

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

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

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

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

acquisition.reportStatusDownload(templateCurrentPackage, ((error: Error, parameter: void): void => {
assert.strictEqual(acquisitionSdk.AcquisitionManager.apiCallsDisabled, false);
done();
}));
})
});

function clone<T>(initialObject: T): T {
Expand Down

0 comments on commit 315ba25

Please sign in to comment.