test: tighten heartbeat session store assertions

This commit is contained in:
Shakker
2026-05-08 17:57:33 +01:00
parent 396179883c
commit 79dd22bfb2

View File

@@ -82,6 +82,14 @@ describe("initSessionState - heartbeat should not trigger session reset", () =>
});
};
const expectPersistedSession = (sessionStore: Record<string, SessionEntry>): SessionEntry => {
const entry = sessionStore["main:user123"];
if (!entry) {
throw new Error("Expected persisted session for main:user123");
}
return entry;
};
it("should NOT reset session when Provider is 'heartbeat'", async () => {
// Setup: Create a session entry that is "stale" (older than idle timeout)
const now = Date.now();
@@ -191,7 +199,7 @@ describe("initSessionState - heartbeat should not trigger session reset", () =>
expect(heartbeatResult.sessionEntry.lastInteractionAt).toBe(staleTime);
const persistedAfterHeartbeat = loadSessionStore(storePath);
expect(persistedAfterHeartbeat["main:user123"]?.lastInteractionAt).toBe(staleTime);
expect(expectPersistedSession(persistedAfterHeartbeat).lastInteractionAt).toBe(staleTime);
const userResult = await initSessionState({
ctx: createBaseCtx({
@@ -278,7 +286,7 @@ describe("initSessionState - heartbeat should not trigger session reset", () =>
expect(heartbeatResult.sessionId).toBe("legacy-idle-session");
const persistedAfterHeartbeat = loadSessionStore(storePath);
expect(persistedAfterHeartbeat["main:user123"]?.lastInteractionAt).toBeUndefined();
expect(expectPersistedSession(persistedAfterHeartbeat).lastInteractionAt).toBeUndefined();
const userResult = await initSessionState({
ctx: createBaseCtx({