-
Notifications
You must be signed in to change notification settings - Fork 7
fix(sentry): stop the spin claim and the voice list from throwing uncaught #1526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
103 changes: 103 additions & 0 deletions
103
packages/sdk/src/modules/games/mutations/game-claim.spec.ts
This file contains hidden or 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,103 @@ | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import { gameClaimRequest } from "./game-claim"; | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
|
|
||
| function jsonResponse(data: unknown, status = 200) { | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
| return { | ||
| ok: status >= 200 && status < 300, | ||
| status, | ||
| headers: { get: () => "application/json; charset=utf-8" }, | ||
| text: async () => JSON.stringify(data), | ||
| }; | ||
| } | ||
|
|
||
| function htmlResponse(html: string, status = 200) { | ||
| return { | ||
| ok: status >= 200 && status < 300, | ||
| status, | ||
| headers: { get: () => "text/html; charset=utf-8" }, | ||
| text: async () => html, | ||
| }; | ||
| } | ||
|
|
||
| describe("gameClaimRequest", () => { | ||
| // getBoundFetch() caches the bound fetch on first call, so reuse one stable | ||
| // mock and reset it per test. | ||
| const fetchMock = vi.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| fetchMock.mockReset(); | ||
| vi.stubGlobal("fetch", fetchMock); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it("POSTs to /private-api/post-game with the code, game type and key", async () => { | ||
| fetchMock.mockResolvedValueOnce(jsonResponse({ score: 50 })); | ||
|
|
||
| const result = await gameClaimRequest("hs-token", "spin", "spin-key"); | ||
|
|
||
| const [url, init] = fetchMock.mock.calls[0]; | ||
| expect(String(url)).toContain("/private-api/post-game"); | ||
| expect((init as RequestInit).method).toBe("POST"); | ||
| const body = JSON.parse((init as RequestInit).body as string); | ||
| expect(body).toMatchObject({ | ||
| code: "hs-token", | ||
| game_type: "spin", | ||
| key: "spin-key", | ||
| }); | ||
| expect(result).toEqual({ score: 50 }); | ||
| }); | ||
|
|
||
| // The 502 that produced ECENCY-NEXT-1FCJ: an nginx HTML page parsed as JSON | ||
| // threw a bare SyntaxError that named neither the endpoint nor the cause. | ||
| it("throws a stable, body-free error on an HTML gateway response (ECENCY-NEXT-1FCJ)", async () => { | ||
| fetchMock.mockResolvedValueOnce( | ||
| htmlResponse("<html><body><h1>502 Bad Gateway</h1></body></html>", 502) | ||
| ); | ||
|
|
||
| const err = await gameClaimRequest("t", "spin", "k").then( | ||
| () => { | ||
| throw new Error("expected the 502 to reject"); | ||
| }, | ||
| (e: Error) => e | ||
| ); | ||
|
|
||
| expect(err.message).toBe("[SDK][Games] – failed with status 502"); | ||
| // The raw page must not leak into the message, else Sentry fragments the | ||
| // group across every distinct error page. | ||
| expect(err.message).not.toContain("<html>"); | ||
| }); | ||
|
|
||
| it("throws a descriptive error when a 2xx response is not JSON", async () => { | ||
| fetchMock.mockResolvedValueOnce(htmlResponse("<html>OK</html>", 200)); | ||
|
|
||
| await expect(gameClaimRequest("t", "spin", "k")).rejects.toThrow( | ||
| /expected JSON but received "text\/html"/ | ||
| ); | ||
| }); | ||
|
|
||
| it("throws a descriptive error when a 2xx JSON body is malformed", async () => { | ||
| fetchMock.mockResolvedValueOnce({ | ||
| ok: true, | ||
| status: 200, | ||
| headers: { get: () => "application/json" }, | ||
| text: async () => "not-json", | ||
| }); | ||
|
|
||
| await expect(gameClaimRequest("t", "spin", "k")).rejects.toThrow( | ||
| /malformed JSON response/ | ||
| ); | ||
| }); | ||
|
|
||
| it("folds a short JSON error body into the message on a non-2xx", async () => { | ||
| fetchMock.mockResolvedValueOnce( | ||
| jsonResponse({ message: "No spins left" }, 409) | ||
| ); | ||
|
|
||
| await expect(gameClaimRequest("t", "spin", "k")).rejects.toThrow( | ||
| /failed with status 409: .*No spins left/ | ||
| ); | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. claimgame failure lacks regression test
📘 Rule violation▣ TestabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation toolsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 208fabd. Added
apps/web/src/specs/app/perks/perks-points-spin-banner.spec.tsx: a rejectedclaim()asserts theperks.spin-errortoast fires and that neither the success toast norrefetchruns, plus the success-path counterpart. Verified the failing-path test fails against the pre-fix component withexpected "vi.fn()" to be called with arguments: [ 'perks.spin-error' ].