-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for filtering out wrong activity modes
- Loading branch information
1 parent
f06a424
commit cd26ca2
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters