-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathrepositorySelection.test.ts
More file actions
89 lines (80 loc) · 2.13 KB
/
Copy pathrepositorySelection.test.ts
File metadata and controls
89 lines (80 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { describe, expect, it } from "vitest";
import {
buildRepositoryOptions,
findRepositoryOption,
isRepositorySelectionComplete,
toRepositorySelection,
} from "./repositorySelection";
describe("repositorySelection", () => {
const integrations = [
{
id: 7,
kind: "github",
display_name: "Personal GitHub",
},
{
id: 11,
kind: "github",
config: {
account: {
login: "posthog",
},
},
},
];
it("preserves integration identity for each repository option", () => {
const options = buildRepositoryOptions(integrations, {
7: ["annika/mobile-app"],
11: ["posthog/posthog", "posthog/code"],
});
expect(options).toEqual([
{
integrationId: 7,
integrationLabel: "Personal GitHub",
repository: "annika/mobile-app",
},
{
integrationId: 11,
integrationLabel: "posthog",
repository: "posthog/code",
},
{
integrationId: 11,
integrationLabel: "posthog",
repository: "posthog/posthog",
},
]);
});
it("finds the exact repository option when multiple integrations expose the same repository", () => {
const options = buildRepositoryOptions(integrations, {
7: ["posthog/posthog"],
11: ["posthog/posthog"],
});
const selected = findRepositoryOption(options, {
integrationId: 11,
repository: "posthog/posthog",
});
expect(selected).toEqual({
integrationId: 11,
integrationLabel: "posthog",
repository: "posthog/posthog",
});
});
it("converts an option into a reusable repository selection payload", () => {
const options = buildRepositoryOptions(integrations, {
11: ["posthog/code"],
});
const selection = toRepositorySelection(options[0] ?? null);
expect(selection).toEqual({
integrationId: 11,
repository: "posthog/code",
});
expect(isRepositorySelectionComplete(selection)).toBe(true);
expect(
isRepositorySelectionComplete({
integrationId: null,
repository: "posthog/code",
}),
).toBe(false);
});
});