Repository navigation
Expand file tree
/
Copy pathpullRequestEnvironmentFallback.test.ts
More file actions
58 lines (53 loc) · 2.06 KB
/
Copy pathpullRequestEnvironmentFallback.test.ts
File metadata and controls
58 lines (53 loc) · 2.06 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
import { describe, expect, it } from "vite-plus/test";
import type { EnvironmentProject } from "@t3tools/client-runtime/state/models";
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
import { EnvironmentId } from "@t3tools/contracts";
import { pullRequestFallbackEnvironment } from "./pullRequestEnvironmentFallback";
const project = (environmentId: string, id: string, canonicalKey: string) =>
({
environmentId,
id,
repositoryIdentity: { canonicalKey },
}) as unknown as EnvironmentProject;
const projects = [
project("laptop", "t3", "github.com/pingdotgg/t3code"),
project("desktop", "other", "github.com/pingdotgg/other"),
project("server", "t3-copy", "github.com/pingdotgg/t3code"),
];
const target = {
environmentId: "laptop",
projectId: "t3",
repository: "pingdotgg/t3code",
host: "github.com",
};
const environment = (
environmentId: string,
connectionState: EnvironmentConnectionPhase = "connected",
isEnabled = true,
) => ({ environmentId: EnvironmentId.make(environmentId), connectionState, isEnabled });
describe("pullRequestFallbackEnvironment", () => {
it("moves to a connected copy of the repository when the original is down", () => {
expect(
pullRequestFallbackEnvironment(target, projects, [
environment("desktop"),
environment("server"),
]),
).toEqual({ environmentId: "server", projectId: "t3-copy" });
});
it("stays put while the original is connected or nothing else holds the repository", () => {
expect(
pullRequestFallbackEnvironment(target, projects, [
environment("laptop"),
environment("server"),
]),
).toBe(null);
expect(pullRequestFallbackEnvironment(target, projects, [environment("desktop")])).toBe(null);
});
it("derives the host from the original project when the route has none", () => {
const { host: _host, ...hostless } = target;
expect(pullRequestFallbackEnvironment(hostless, projects, [environment("server")])).toEqual({
environmentId: "server",
projectId: "t3-copy",
});
});
});