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


##########
superset-embedded-sdk/src/guestTokenRefresh.test.ts:
##########
@@ -122,4 +122,162 @@ describe("guest token refresh", () => {
     expect(DEFAULT_TOKEN_REFRESH_RETRY_MS).toBe(10000);
     expect(DEFAULT_TOKEN_REFRESH_RETRY_MS).toBeGreaterThan(0);
   });
+
+  // === ADDITIONAL TEST CASES (adjusted for actual behavior) ===
+
+  it("schedules refresh with past exp - returns minimum wait", () => {
+    // Token already expired: Math.max(MIN, negative) = MIN, then MIN - buffer
+    const ttl = 100;
+    const exp = Date.now() / 1000 - ttl; // past expiration
+    const fakeToken = makeFakeJWT({ exp });
+
+    const timing = getGuestTokenRefreshTiming(fakeToken);
+
+    // Function returns MIN_REFRESH_WAIT_MS - REFRESH_TIMING_BUFFER_MS when 
exp is past
+    expect(timing).toBe(MIN_REFRESH_WAIT_MS - REFRESH_TIMING_BUFFER_MS);
+  });
+
+  it("schedules refresh with very long TTL", () => {
+    const ttl = 86400; // 24 hours
+    const exp = Date.now() / 1000 + ttl;
+    const fakeToken = makeFakeJWT({ exp });
+
+    const timing = getGuestTokenRefreshTiming(fakeToken);
+
+    expect(timing).toBeGreaterThan(MIN_REFRESH_WAIT_MS);
+    expect(timing).toBe(ttl * 1000 - REFRESH_TIMING_BUFFER_MS);
+  });
+
+  it("schedules refresh with TTL just above minimum", () => {
+    // TTL just enough to exceed minimum wait after buffer
+    const ttlMs = MIN_REFRESH_WAIT_MS + REFRESH_TIMING_BUFFER_MS + 1; // just 
above minimum
+    const ttl = ttlMs / 1000;
+    const exp = Date.now() / 1000 + ttl;
+    const fakeToken = makeFakeJWT({ exp });
+
+    const timing = getGuestTokenRefreshTiming(fakeToken);
+
+    expect(timing).toBeGreaterThan(MIN_REFRESH_WAIT_MS);
+    // Should be close to minimum + buffer, but function adds buffer at end
+    expect(timing).toBeLessThanOrEqual(ttl * 1000 - REFRESH_TIMING_BUFFER_MS + 
100);
+  });
+
+  it("handles time travel - system time moves forward", () => {
+    // Time travel: set time forward, verify timing still calculates correctly
+    vi.useFakeTimers();
+    vi.setSystemTime(new Date("2022-03-03 01:00"));
+
+    const ttl = 1300;
+    const exp = Date.now() / 1000 + ttl;
+    const fakeToken = makeFakeJWT({ exp });
+
+    const timing = getGuestTokenRefreshTiming(fakeToken);
+
+    expect(timing).toBeGreaterThan(MIN_REFRESH_WAIT_MS);
+    expect(timing).toBe(ttl * 1000 - REFRESH_TIMING_BUFFER_MS);
+
+    vi.useRealTimers();
+  });

Review Comment:
   ✅ **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.
   
   <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