Skip to content

Commit

Permalink
fix: adapting tests to retryable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
barbmarcio committed Jul 26, 2024
1 parent 0f498b0 commit e3ae74b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions test/auctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe("createAuction", () => {
returnStatus(401, `${baseURL}/${apis.auctions}`);
expect(createAuction({ apiKey: "apiKey" }, {} as TopsortAuction)).rejects.toEqual({
status: 401,
retry: false,
statusText: "Unauthorized",
body: {},
});
Expand All @@ -27,6 +28,7 @@ describe("createAuction", () => {
returnStatus(429, `${baseURL}/${apis.auctions}`);
expect(createAuction({ apiKey: "apiKey" }, {} as TopsortAuction)).rejects.toEqual({
status: 429,
retry: true,
statusText: "Too Many Requests",
body: {},
});
Expand All @@ -36,6 +38,7 @@ describe("createAuction", () => {
returnStatus(500, `${baseURL}/${apis.auctions}`);
expect(createAuction({ apiKey: "apiKey" }, {} as TopsortAuction)).rejects.toEqual({
status: 500,
retry: true,
statusText: "Internal Server Error",
body: {},
});
Expand Down
17 changes: 8 additions & 9 deletions test/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ describe("reportEvent", () => {
returnStatus(401, `${baseURL}/${apis.events}`);
expect(reportEvent({ apiKey: "apiKey" }, {} as TopsortEvent)).rejects.toEqual({
status: 401,
retry: false,
statusText: "Unauthorized",
body: {},
});
});

it("should handle retryable error", async () => {
returnStatus(429, `${baseURL}/${apis.events}`);
expect(reportEvent({ apiKey: "apiKey" }, {} as TopsortEvent)).rejects.toEqual({
status: 429,
statusText: "Too Many Requests",
body: {},
expect(reportEvent({ apiKey: "apiKey" }, {} as TopsortEvent)).resolves.toEqual({
ok: false,
retry: true,
});
});

it("should handle server error", async () => {
returnStatus(500, `${baseURL}/${apis.events}`);
expect(reportEvent({ apiKey: "apiKey" }, {} as TopsortEvent)).rejects.toEqual({
status: 500,
statusText: "Internal Server Error",
body: {},
expect(reportEvent({ apiKey: "apiKey" }, {} as TopsortEvent)).resolves.toEqual({
ok: false,
retry: true,
});
});

Expand All @@ -45,7 +44,7 @@ describe("reportEvent", () => {
},
{} as TopsortEvent,
),
).resolves.toEqual({ ok: true });
).resolves.toEqual({ ok: true, retry: false });
});

it("should handle fetch error", async () => {
Expand Down

0 comments on commit e3ae74b

Please sign in to comment.