1import { describe, expect, it } from "vite-plus/test";
2
3import { groupGitHubAccounts, nextGitHubHosts } from "./GitHubAccountSettings.logic";
4
5describe("groupGitHubAccounts", () => {
6 it("groups logins by host, keeping broken and environment logins out of the picker", () => {
7 expect(
8 groupGitHubAccounts([
9 { host: "github.com", account: "personal", active: true, authenticated: true },
10 { host: "github.com", account: "work", active: false, authenticated: true },
11 { host: "github.com", account: "old", active: false, authenticated: false, error: "bad" },
12 {
13 host: "github.com",
14 account: "bot",
15 active: false,
16 authenticated: true,
17 environmentVariable: "GH_TOKEN",
18 },
19 { host: "ghe.acme.test", account: "jm", active: false, authenticated: true },
20 ]),
21 ).toEqual([
22 {
23 host: "github.com",
24 activeAccount: "personal",
25 selectable: ["personal", "work"],
26 broken: [
27 { host: "github.com", account: "old", active: false, authenticated: false, error: "bad" },
28 ],
29 environmentVariable: "GH_TOKEN",
30 },
31 {
32 host: "ghe.acme.test",
33 activeAccount: "jm",
34 selectable: ["jm"],
35 broken: [],
36 environmentVariable: null,
37 },
38 ]);
39 });
40});
41
42describe("nextGitHubHosts", () => {
43 it("pins an account, keeps other hosts, and drops a host back on gh's defaults", () => {
44 const other = { "ghe.acme.test": { enabled: false } };
45 const pinned = nextGitHubHosts(other, "github.com", { account: "work" });
46 expect(pinned).toEqual({ ...other, "github.com": { enabled: true, account: "work" } });
47
48 const disabled = nextGitHubHosts(pinned, "github.com", { enabled: false });
49 expect(disabled["github.com"]).toEqual({ enabled: false, account: "work" });
50
51 expect(nextGitHubHosts(disabled, "github.com", { enabled: true, account: null })).toEqual(
52 other,
53 );
54 });
55});