27 lines · 875 B
import { describe, expect, mock, test } from "bun:test";

mock.module("cloudflare:workers", () => ({ env: {}, DurableObject: class {} }));
mock.module("../repos", () => ({ loadRepoById: async () => null }));
mock.module("../token-scope", () => ({
  credentialAllows: () => true,
  patCredentialById: async () => null,
  tokenIsLive: async () => false,
}));

const { subscriberOwner } = await import("./hub-do");

describe("subscriberOwner", () => {
  test("keys subscriber slots on the user, not the token, so extra tokens never add quota", () => {
    const viewer = {
      id: "u1",
      name: "alice",
      displayName: null,
      email: "",
      isAdmin: false,
      emailVerified: true,
    };
    expect(subscriberOwner({ viewer })).toBe("u1");
    expect(subscriberOwner({ viewer, tokenId: "t1" } as Parameters<typeof subscriberOwner>[0])).toBe("u1");
  });
});