codeant-ai-for-open-source[bot] commented on code in PR #45957:
URL: https://github.com/apache/superset/pull/45957#discussion_r4470689692


##########
superset-embedded-sdk/src/index.test.ts:
##########
@@ -516,25 +516,115 @@ describe("embedDashboard", () => {
   });
 
   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();
+      });

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `da47442`.
   
   The test now uses a resolved token to verify unmount behavior and no longer 
asserts that the mocked switchboard rejects an invalid token.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



##########
superset-embedded-sdk/src/index.test.ts:
##########
@@ -516,25 +516,115 @@ describe("embedDashboard", () => {
   });
 
   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();
+      });
+
+      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();
+      });

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `da47442`.
   
   The initial token request now resolves with a valid fake JWT; the test 
awaits embedding before triggering and resolving the later refresh.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

  • [PR] feat(s... nextjohnp7 (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... gabotorresruiz (via GitHub) via notifications
    • Re: [P... nextjohnp7 (via GitHub) via notifications
    • Re: [P... nextjohnp7 (via GitHub) via notifications
    • Re: [P... codeant-ai-for-open-source[bot] (via GitHub) via notifications
    • Re: [P... gabotorresruiz (via GitHub) via notifications
    • Re: [P... nextjohnp7 (via GitHub) via notifications
    • Re: [P... netlify[bot] (via GitHub) via notifications
    • Re: [P... hainenber (via GitHub) via notifications
    • Re: [P... gabotorresruiz (via GitHub) via notifications
    • Re: [P... gabotorresruiz (via GitHub) via notifications

Reply via email to