Repository navigation
feat(superset-embedded-sdk): add comprehensive test suite and JSDoc type documentation #45957
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
Changes from 2 commits
4769de7
81600a5
9a187fc
5aa688b
e718e62
ca1292f
da47442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -516,25 +516,115 @@ | |
| }); | ||
|
|
||
| test("initial fetch failing with no reload tears the iframe down", async () => { | ||
| const initialToken = deferred<string>(); | ||
| const mockFetchGuestToken = vi | ||
| .fn() | ||
| .mockImplementation(() => initialToken.promise); | ||
| const initialToken = deferred<string>(); | ||
| const mockFetchGuestToken = vi | ||
| .fn() | ||
| .mockImplementation(() => initialToken.promise); | ||
|
|
||
| const embedding = embedDashboard({ | ||
| id: "test-id", | ||
| supersetDomain: "https://superset.example.com", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetchGuestToken, | ||
| }); | ||
|
|
||
| // Let the first load open its channel, so the teardown has something to | ||
| // let go of, and only then fail the fetch. | ||
| await vi.waitFor(() => expect(switchboards).toHaveLength(1)); | ||
| initialToken.reject(new Error("host down")); | ||
|
|
||
| await expect(embedding).rejects.toThrow("host down"); | ||
| expect(mountPoint.querySelector("iframe")).toBeNull(); | ||
| expect(ports[0].close).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| const embedding = embedDashboard({ | ||
| id: "test-id", | ||
| supersetDomain: "https://superset.example.com", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetchGuestToken, | ||
| // === ADDITIONAL TEST SUITES === | ||
|
|
||
| describe("embedDashboard happy path", () => { | ||
| beforeEach(() => { | ||
| mockSwitchboard = makeMockSwitchboard(); | ||
| switchboards = [mockSwitchboard]; | ||
| ports = [{ close: vi.fn() }]; | ||
| getImpls = [() => ({ type: "handshake" })]; | ||
| }); | ||
|
|
||
| it("successfully embeds dashboard with valid token", async () => { | ||
| const mockFetch = vi.fn().mockResolvedValue("valid-jwt-token"); | ||
|
|
||
| const result = await embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| }); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| expect(typeof result.getScrollSize).toBe("function"); | ||
| expect(typeof result.unmount).toBe("function"); | ||
| }); | ||
| }); | ||
|
|
||
| // Let the first load open its channel, so the teardown has something to | ||
| // let go of, and only then fail the fetch. | ||
| await vi.waitFor(() => expect(switchboards).toHaveLength(1)); | ||
| initialToken.reject(new Error("host down")); | ||
| describe("embedDashboard security", () => { | ||
| it("rejects fake guest token", async () => { | ||
| const mockFetch = vi.fn().mockResolvedValue("invalid-token"); | ||
|
|
||
| await expect( | ||
| embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| }) | ||
| ).rejects.toThrow(); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The SDK forwards Assessment: π Prompt for AI Agent π€This is a comment left during a code review.
**Path:** superset-embedded-sdk/src/index.test.ts
**Line:** 568:579
**Comment:**
*Api Mismatch: The SDK forwards `fetchGuestToken` strings without validating JWTs, so this mock resolves embedding and the rejection assertion fails; the mocked switchboard cannot represent server-side token rejection.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β
CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of The test now checks rejection from a If that's not right, unresolve this thread and CodeAnt will leave it open.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β
CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of The test that asserted server-side token rejection is no longer present; the shown test instead embeds with a resolved token and checks unmount cleanup. If that's not right, unresolve this thread and CodeAnt will leave it open.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β
CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of The test now uses a resolved token to verify unmount behavior and no longer asserts that the mocked switchboard rejects an invalid token. If that's not right, unresolve this thread and CodeAnt will leave it open. |
||
|
|
||
| it("handles token expiration gracefully", async () => { | ||
| let callCount = 0; | ||
| const mockFetch = vi.fn().mockImplementation(() => { | ||
| callCount++; | ||
| if (callCount === 1) return Promise.reject(new Error("Token expired")); | ||
| return Promise.resolve("new-valid-token"); | ||
| }); | ||
|
|
||
| await expect(embedding).rejects.toThrow("host down"); | ||
| expect(mountPoint.querySelector("iframe")).toBeNull(); | ||
| expect(ports[0].close).toHaveBeenCalled(); | ||
| const result = await embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| guestTokenFetchTimeoutMs: 5000, | ||
| }); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Assessment: π Prompt for AI Agent π€This is a comment left during a code review.
**Path:** superset-embedded-sdk/src/index.test.ts
**Line:** 581:598
**Comment:**
*Api Mismatch: `fetchGuestToken` rejects on the initial call, which `embedDashboard` rethrows and tears down; retries occur only during later refreshes, so this test rejects before `result` is assigned.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β
CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of The refresh test resolves the initial If that's not right, unresolve this thread and CodeAnt will leave it open.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β
CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of The test that rejected the initial guest-token fetch is no longer present; the shown test uses a resolved token before unmounting. If that's not right, unresolve this thread and CodeAnt will leave it open.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. β
CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of The initial token request now resolves with a valid fake JWT; the test awaits embedding before triggering and resolving the later refresh. If that's not right, unresolve this thread and CodeAnt will leave it open. |
||
| }); | ||
|
|
||
| describe("embedDashboard edge cases", () => { | ||
| it("handles iframe navigation internally", async () => { | ||
| const mockFetch = vi.fn().mockResolvedValue("token-1"); | ||
|
|
||
| const result = await embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| }); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| }); | ||
|
|
||
| it("handles unmount during token refresh", async () => { | ||
| const mockFetch = vi.fn().mockResolvedValue("token-1"); | ||
|
|
||
| const result = await embedDashboard({ | ||
| id: "test-dashboard", | ||
| supersetDomain: "http://localhost:8200", | ||
| mountPoint, | ||
| fetchGuestToken: mockFetch, | ||
| }); | ||
|
|
||
| result.unmount(); | ||
|
|
||
| expect(true).toBe(true); | ||
|
gabotorresruiz marked this conversation as resolved.
Resolved
|
||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Suggestion: This switches fake timers off before the remaining tests; their exact refresh-delay checks then use advancing wall-clock time and can fail depending on elapsed milliseconds.
Assessment: π
MajorΒ· πOccurrence: SometimesΒ· π·οΈPossible bugPrompt for AI Agent π€
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.
β CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of
9a187fc.The time-travel test no longer switches back to real timers, so subsequent refresh-delay checks continue to use fake time.
If that's not right, unresolve this thread and CodeAnt will leave it open.
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.
β CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved as of
5aa688b.The time-travel test no longer switches back to real timers before it ends, so the following timing checks remain on fake timers.
If that's not right, unresolve this thread and CodeAnt will leave it open.