Files
wehub-resource-sync 70bf21e064
Handle Changesets / Handle Changesets (push) Waiting to run
Semgrep OSS scan / semgrep-oss (push) Waiting to run
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

54 lines
1.3 KiB
TypeScript

import { describe, it } from "vitest";
import { readStoredAuthState } from "../src/state";
import type {
AuthConfigStorage,
UserAuthConfig,
} from "../src/auth-config-file";
function memoryStorage(initial?: UserAuthConfig): AuthConfigStorage {
let value = initial;
return {
// Per the `ConfigStorage<T>.read()` contract, "no usable config
// stored yet" is represented as `undefined`, not a thrown
// exception. Throws are reserved for genuine errors (filesystem
// permission failures, etc.).
read() {
return value;
},
write(config) {
value = config;
},
clear() {
value = undefined;
},
path() {
return "<memory>";
},
};
}
describe("readStoredAuthState storage injection", () => {
it("reads OAuth tokens from an injected storage backend", ({ expect }) => {
const storage = memoryStorage({
oauth_token: "oauth-xyz",
refresh_token: "refresh-xyz",
expiration_time: "2099-01-01T00:00:00.000Z",
scopes: ["account:read"],
});
expect(readStoredAuthState({ storage })).toEqual({
accessToken: {
value: "oauth-xyz",
expiry: "2099-01-01T00:00:00.000Z",
},
refreshToken: { value: "refresh-xyz" },
scopes: ["account:read"],
});
});
it("returns an empty object when the injected storage is empty", ({
expect,
}) => {
expect(readStoredAuthState({ storage: memoryStorage() })).toEqual({});
});
});