Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728import { describe, expect, it } from "vitest";import { hasGrantEvidence } from "./grantEvidence";
const url = (search: string) => ({ searchParams: new URLSearchParams(search) });
describe("hasGrantEvidence", () => { it("assumes nothing from an empty flow", () => { expect(hasGrantEvidence()).toBe(false); expect(hasGrantEvidence({})).toBe(false); expect(hasGrantEvidence({ granted: true })).toBe(false); expect(hasGrantEvidence({ url: url("") })).toBe(false); expect(hasGrantEvidence({ granted: false, url: url(""), tasks: [] })).toBe(false); });
it("takes an existing task or a create this session as proof", () => { expect(hasGrantEvidence({ tasks: [{ id: "task-1" }] })).toBe(true); expect(hasGrantEvidence({ sessionCreated: true })).toBe(true); });
it("trusts the callback's attestation only when it came back without an error", () => { expect(hasGrantEvidence({ granted: true, url: url("") })).toBe(true); expect( hasGrantEvidence({ granted: true, url: url("?oauth_error=grant_failed") }) ).toBe(false); expect(hasGrantEvidence({ granted: false, url: url("?page=2") })).toBe(false); });});