Skip to content

Commit

Permalink
test: add tests for filtering out wrong activity modes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Oct 18, 2023
1 parent f06a424 commit cd26ca2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
41 changes: 41 additions & 0 deletions tests/retirement-explorer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const nock = require("nock");
const { getRetirementActivities } = require("../src/api/retirement-explorer");
const { CONFIG } = require("../src/config");
const { generateUriForHostAndPort } = require("../src/utils");

const retirementExplorerUri = generateUriForHostAndPort(
CONFIG().RETIREMENT_EXPLORER.PROTOCOL,
CONFIG().RETIREMENT_EXPLORER.HOST,
CONFIG().RETIREMENT_EXPLORER.PORT
);

describe("getRetirementActivities", () => {
const apiEndpoint = retirementExplorerUri;
const mockResponse = {
activities: [
{ mode: "PERMISSIONLESS_RETIREMENT", someField: "someValue" },
{ mode: "TOKENIZATION", someField: "someOtherValue" },
],
};

beforeEach(() => {
nock(apiEndpoint)
.get("/v1/activities?page=1&limit=10&minHeight=1&sort=asc")
.reply(200, mockResponse);
});

it('should filter out activities that do not have a mode of "PERMISSIONLESS_RETIREMENT"', async () => {
const result = await getRetirementActivities(1, 10, 0);
expect(result).toEqual([
{ mode: "PERMISSIONLESS_RETIREMENT", someField: "someValue" },
]);
});

it("should handle API errors gracefully", async () => {
nock.cleanAll();
nock(apiEndpoint).get("/retirement-activities").replyWithError("API Error");

const result = await getRetirementActivities(1, 10, 0);
expect(result).toEqual([]);
});
});
16 changes: 13 additions & 3 deletions tests/tasks/sync-retirements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("Task: Sync Retirements", () => {

afterEach(async () => {
sinon.restore();
await new Promise(resolve => setTimeout(() => resolve(), 1000));
await new Promise((resolve) => setTimeout(() => resolve(), 1000));
});

it("skips retirement task if no homeorg can be attained by the registry", async () => {
Expand Down Expand Up @@ -105,9 +105,14 @@ describe("Task: Sync Retirements", () => {
registryGetHomeOrgStub.resolves(modifiedHomeOrg);

// Stub registry methods
let registryGetAssetUnitBlocksStub = sinon.stub(registry, "getAssetUnitBlocks");
let registryGetAssetUnitBlocksStub = sinon.stub(
registry,
"getAssetUnitBlocks"
);
sinon.stub(registry, "getLastProcessedHeight").resolves(12345);
retirementExplorerGetRetirementActivitiesStub.onFirstCall().resolves(ActivityResponseMock.activities);
retirementExplorerGetRetirementActivitiesStub
.onFirstCall()
.resolves(ActivityResponseMock.activities);
retirementExplorerGetRetirementActivitiesStub.onSecondCall().resolves([]);

// Spy on logger.warn method
Expand Down Expand Up @@ -155,6 +160,7 @@ describe("Task: Sync Retirements", () => {
beneficiary_name: "TEST_BENEFICIARY_NAME",
beneficiary_address: "TEST_BENEFICIARY_ADDRESS",
height: 99999,
mode: "PERMISSIONLESS_RETIREMENT",
cw_unit: {
marketplaceIdentifier: "TEST_MARKETPLACE_IDENTIFIER",
},
Expand All @@ -167,6 +173,7 @@ describe("Task: Sync Retirements", () => {
beneficiary_name: "TEST_BENEFICIARY_NAME",
beneficiary_address: "TEST_BENEFICIARY_ADDRESS",
height: 12346,
mode: "PERMISSIONLESS_RETIREMENT",
cw_unit: {
marketplaceIdentifier: "TEST_MARKETPLACE_IDENTIFIER",
},
Expand Down Expand Up @@ -238,6 +245,7 @@ describe("Task: Sync Retirements", () => {
amount: 10000,
beneficiary_name: "TEST_BENEFICIARY_NAME",
beneficiary_address: "TEST_BENEFICIARY_ADDRESS",
mode: "PERMISSIONLESS_RETIREMENT",
height: 99999,
cw_unit: {
marketplaceIdentifier: "TEST_MARKETPLACE_IDENTIFIER",
Expand Down Expand Up @@ -286,6 +294,7 @@ describe("Task: Sync Retirements", () => {
beneficiary_name: "TEST_BENEFICIARY_NAME",
beneficiary_address: "TEST_BENEFICIARY_ADDRESS",
height: 99999,
mode: "PERMISSIONLESS_RETIREMENT",
cw_unit: {
marketplaceIdentifier: "TEST_MARKETPLACE_IDENTIFIER",
},
Expand All @@ -298,6 +307,7 @@ describe("Task: Sync Retirements", () => {
beneficiary_name: "TEST_BENEFICIARY_NAME",
beneficiary_address: "TEST_BENEFICIARY_ADDRESS",
height: 12344,
mode: "PERMISSIONLESS_RETIREMENT",
cw_unit: {
marketplaceIdentifier: "TEST_MARKETPLACE_IDENTIFIER",
},
Expand Down

0 comments on commit cd26ca2

Please sign in to comment.