Files
OmniRoute/tests/unit/oauth-connection-tokenexpiresat-5326.test.ts
Diego Rodrigues de Sa e Souza 78f09c8d9f Release v3.8.41 (#5327)
Release v3.8.41 — 52 commits since v3.8.40 (19 CHANGELOG bullets, 11 contributors).

All gating CI green: Unit×8, Coverage×8, Vitest, Package Artifact, Quality Ratchet, CodeQL, Lint, Docs Sync (Strict), Node 24/26 compat, E2E×9, Integration, Electron smoke.

Advisory checks overridden (main unprotected): PR Test Policy = test-masking heuristic on the cumulative 52-commit assert delta (legitimate dead-code-sweep removals + consolidations, reviewed per-PR); SonarCloud/SonarQube = new-code maintainability/coverage quality gate (CodeQL/Semgrep/Security/npm-audit/Dependabot all clean — not a security finding).
2026-06-29 16:51:03 -03:00

44 lines
1.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { buildOAuthConnectionCreatePayload } from "../../src/lib/oauth/connectionPersistence.ts";
// Regression for #5326: a freshly created OAuth connection (e.g. antigravity) used
// to persist only `expiresAt`, leaving `tokenExpiresAt` null. The dashboard token
// badge prefers `tokenExpiresAt` and falls back to the original grant clock when it
// is null, flashing a false "Token Expired" until the first background refresh.
// The create payload must mirror the computed expiry into BOTH fields.
test("buildOAuthConnectionCreatePayload mirrors expiresAt into tokenExpiresAt (#5326)", () => {
const expiresAt = new Date(Date.now() + 3600 * 1000).toISOString();
const tokenData = {
accessToken: "at-123",
refreshToken: "rt-123",
email: "user@example.com",
expiresIn: 3600,
};
const payload = buildOAuthConnectionCreatePayload("antigravity", tokenData, expiresAt);
assert.equal(payload.provider, "antigravity");
assert.equal(payload.authType, "oauth");
assert.equal(payload.testStatus, "active");
assert.equal(payload.expiresAt, expiresAt);
// The fix: tokenExpiresAt is set (was null/undefined before) and equals expiresAt.
assert.equal(payload.tokenExpiresAt, expiresAt);
assert.equal(payload.tokenExpiresAt, payload.expiresAt);
// tokenData fields are still carried through.
assert.equal(payload.accessToken, "at-123");
assert.equal(payload.refreshToken, "rt-123");
});
test("buildOAuthConnectionCreatePayload keeps tokenExpiresAt null when expiry is unknown", () => {
const payload = buildOAuthConnectionCreatePayload(
"antigravity",
{ accessToken: "at-456" },
null
);
assert.equal(payload.expiresAt, null);
assert.equal(payload.tokenExpiresAt, null);
});