Open History to see the last commit
1import {
2 IssueTrackerAccountId,
3 IssueTrackerKind,
4 MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES,
5} from "@t3tools/contracts";
6import { describe, expect, it } from "vite-plus/test";
7
8import {
9 boundIssueTrackerScopes,
10 issueTrackerBindingFor,
11 issueTrackerScopeOptions,
12} from "./issueTrackers.ts";
13
14describe("issueTrackerScopeOptions", () => {
15 it("offers no new team once the binding is full, and keeps bound ones removable", () => {
16 const tracker = {
17 tracker: IssueTrackerKind.make("linear"),
18 displayName: "Linear",
19 host: "linear.app",
20 scopeNoun: "team",
21 credential: { label: "Personal API key", helpUrl: null },
22 connected: true,
23 account: "demo",
24 detail: null,
25 scopes: [
26 { key: "ENG", name: "Engineering" },
27 { key: "OPS", name: "Operations" },
28 ],
29 };
30 const full = [
31 "ENG",
32 ...Array.from({ length: MAX_ISSUE_TRACKER_ADDITIONAL_SCOPES }, (_, i) => `T${i}`),
33 ];
34 const options = issueTrackerScopeOptions(tracker, full);
35 expect(options.find((scope) => scope.key === "OPS")?.addable).toBe(false);
36 expect(options.find((scope) => scope.key === "ENG")?.addable).toBe(true);
37 expect(options.find((scope) => scope.key === "T0")).toEqual({
38 key: "T0",
39 name: "T0",
40 addable: true,
41 });
42 expect(issueTrackerScopeOptions(tracker, ["ENG"]).every((scope) => scope.addable)).toBe(true);
43 });
44});
45
46describe("boundIssueTrackerScopes", () => {
47 it("keeps each account's teams apart, and binds new picks with that account", () => {
48 const tracker = IssueTrackerKind.make("linear");
49 const second = { tracker, accountId: IssueTrackerAccountId.make("second") };
50 const binding = issueTrackerBindingFor(second, [], ["ENG", "OPS"]) ?? undefined;
51 expect(binding).toEqual({ ...second, scope: "ENG", additionalScopes: ["OPS"] });
52 expect(boundIssueTrackerScopes(second, binding)).toEqual(["ENG", "OPS"]);
53 expect(boundIssueTrackerScopes({ tracker }, binding)).toEqual([]);
54 });
55});