Skip to content

Commit 9b6b824

Browse files
committed
test: cover fresh family selection happy path
1 parent 66d2d63 commit 9b6b824

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

test/accounts-load-from-disk.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,32 @@ describe("AccountManager loadFromDisk", () => {
280280
const selected = manager.getNextForFamily("codex");
281281
expect(selected?.refreshToken).toBe("stale-1");
282282
});
283+
284+
it("getNextForFamily prefers a fresh account when one is available", () => {
285+
const now = Date.now();
286+
const manager = new AccountManager(undefined, {
287+
version: 3 as const,
288+
activeIndex: 0,
289+
activeIndexByFamily: { codex: 0 },
290+
accounts: [
291+
{
292+
refreshToken: "stale-1",
293+
accessToken: "access-1",
294+
expiresAt: now + 60_000,
295+
addedAt: now,
296+
lastUsed: now,
297+
},
298+
{
299+
refreshToken: "token-fresh",
300+
accessToken: "access-fresh",
301+
expiresAt: now + 10 * 60_000,
302+
addedAt: now,
303+
lastUsed: now - 5_000,
304+
},
305+
],
306+
} as never);
307+
308+
const selected = manager.getNextForFamily("codex");
309+
expect(selected?.refreshToken).toBe("token-fresh");
310+
});
283311
});

0 commit comments

Comments
 (0)