Core engine: entitlements (§14), delivery action runner (§21). Payment rails: arc (viem USDC verify), circle (REST), x402 middleware, payments, webhooks (HMAC), notifications (Resend). Integrations: github (Octokit App), discord (REST v10). Commerce: saas billing, bundles, license-keys, api-keys, file-delivery (signed URLs + SigV4), usage/credits, agent-services, escrow, marketplace-core, risk. Persistence: database (Drizzle/Postgres, 48 tables §25). Plus supporting domain packages. 561 tests passing across 117 files; tsc -b green for every package.
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { SettleKitError } from "@settlekit/common";
|
|
import {
|
|
createGitHubAccessClient,
|
|
isValidGitHubUsername,
|
|
verifyGithubUsername,
|
|
type GitHubApi,
|
|
} from "../src/index.js";
|
|
|
|
/** Minimal in-memory GitHubApi backed by a fixed set of known users. */
|
|
function makeApi(users: Record<string, number>): GitHubApi {
|
|
return {
|
|
async listInstallationRepositories() {
|
|
return [];
|
|
},
|
|
async listOrgTeams() {
|
|
return [];
|
|
},
|
|
async getUser(username) {
|
|
const id = users[username];
|
|
return id === undefined ? undefined : { id, login: username };
|
|
},
|
|
async addRepoCollaborator() {
|
|
return { invitationId: 1 };
|
|
},
|
|
async removeRepoCollaborator() {},
|
|
async getRepoCollaboratorPermission() {
|
|
return "read";
|
|
},
|
|
async listRepoInvitations() {
|
|
return [];
|
|
},
|
|
async cancelRepoInvitation() {},
|
|
async addTeamMembership() {},
|
|
async removeTeamMembership() {},
|
|
};
|
|
}
|
|
|
|
describe("isValidGitHubUsername", () => {
|
|
it("accepts valid logins and rejects malformed ones", () => {
|
|
expect(isValidGitHubUsername("octocat")).toBe(true);
|
|
expect(isValidGitHubUsername("-bad")).toBe(false);
|
|
expect(isValidGitHubUsername("has space")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("verifyGithubUsername", () => {
|
|
it("returns exists + user id for a known user", async () => {
|
|
const api = makeApi({ buyer: 42 });
|
|
const result = await verifyGithubUsername(api, "buyer");
|
|
expect(result.exists).toBe(true);
|
|
expect(result.user?.id).toBe(42);
|
|
});
|
|
|
|
it("returns exists=false for an unknown user", async () => {
|
|
const api = makeApi({});
|
|
const result = await verifyGithubUsername(api, "ghost");
|
|
expect(result.exists).toBe(false);
|
|
});
|
|
|
|
it("throws a validation error for malformed usernames", async () => {
|
|
const api = makeApi({});
|
|
await expect(verifyGithubUsername(api, "-nope")).rejects.toBeInstanceOf(SettleKitError);
|
|
});
|
|
});
|
|
|
|
describe("createGitHubAccessClient", () => {
|
|
it("adapts a GitHubApi into the high-level access client surface", async () => {
|
|
const api = makeApi({});
|
|
const client = createGitHubAccessClient(api);
|
|
const invite = await client.inviteRepoCollaborator({
|
|
installationId: 1,
|
|
owner: "seller",
|
|
repo: "repo",
|
|
username: "buyer",
|
|
});
|
|
expect(invite.invitationId).toBe(1);
|
|
expect(
|
|
await client.getRepoCollaboratorPermission({ installationId: 1, owner: "seller", repo: "repo", username: "buyer" }),
|
|
).toBe("read");
|
|
});
|
|
});
|