-
Notifications
You must be signed in to change notification settings - Fork 367
Expand file tree
/
Copy pathazuredevops.test.ts
More file actions
137 lines (124 loc) · 4.76 KB
/
Copy pathazuredevops.test.ts
File metadata and controls
137 lines (124 loc) · 4.76 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import type { AzureDevOpsConnectionConfig } from '@sourcebot/schemas/v3/azuredevops.type';
import { beforeEach, describe, expect, test, vi } from 'vitest';
const mocks = vi.hoisted(() => ({
getProjects: vi.fn(),
getRepositories: vi.fn(),
getRepository: vi.fn(),
}));
vi.mock("@sentry/node", () => ({
captureException: vi.fn(),
}));
vi.mock("@sourcebot/shared", async (importOriginal) => ({
...await importOriginal<typeof import("@sourcebot/shared")>(),
getTokenFromConfig: vi.fn(async () => "token"),
}));
vi.mock("azure-devops-node-api", () => ({
getPersonalAccessTokenHandler: vi.fn(() => ({})),
WebApi: class {
getCoreApi = vi.fn(async () => ({
getProjects: mocks.getProjects,
}));
getGitApi = vi.fn(async () => ({
getRepositories: mocks.getRepositories,
getRepository: mocks.getRepository,
}));
},
}));
vi.mock("./utils.js", () => ({
fetchWithRetry: (routine: () => Promise<unknown>) => routine(),
measure: async (routine: () => Promise<unknown>) => ({
durationMs: 1,
data: await routine(),
}),
}));
import { getAzureDevOpsReposFromConfig } from './azuredevops';
import { collectRepositoryDiscoveryIssues } from './repositoryDiscoveryIssueContext.js';
const config = (overrides: Partial<AzureDevOpsConnectionConfig>): AzureDevOpsConnectionConfig => ({
type: "azuredevops",
deploymentType: "cloud",
token: { env: "AZURE_DEVOPS_TOKEN" },
...overrides,
});
beforeEach(() => {
vi.clearAllMocks();
const notFound = Object.assign(new Error("Not Found"), { statusCode: 404 });
mocks.getProjects.mockRejectedValue(notFound);
mocks.getRepositories.mockRejectedValue(notFound);
mocks.getRepository.mockRejectedValue(notFound);
});
describe("Azure DevOps repository discovery", () => {
test("reports inaccessible configured targets as partial successes", async () => {
const result = await collectRepositoryDiscoveryIssues(() =>
getAzureDevOpsReposFromConfig(config({
orgs: ["missing-org"],
projects: ["org/missing-project"],
repos: ["org/project/missing-repo"],
}))
);
expect(result).toEqual({
value: [],
issues: [
{
code: "NOT_FOUND_OR_INACCESSIBLE",
effect: "TARGET_SKIPPED",
subject: {
kind: "organization",
value: "missing-org",
},
message: "Azure DevOps organization was not found or is inaccessible.",
},
{
code: "NOT_FOUND_OR_INACCESSIBLE",
effect: "TARGET_SKIPPED",
subject: {
kind: "project",
value: "org/missing-project",
},
message: "Azure DevOps project was not found or is inaccessible.",
},
{
code: "NOT_FOUND_OR_INACCESSIBLE",
effect: "TARGET_SKIPPED",
subject: {
kind: "repository",
value: "org/project/missing-repo",
},
message: "Azure DevOps repository was not found or is inaccessible.",
},
],
});
});
test("reports incomplete project enumeration within an organization", async () => {
mocks.getProjects.mockResolvedValue([
{ name: "missing-id" },
{ id: "broken-project-id", name: "broken-project" },
]);
mocks.getRepositories.mockRejectedValue(new Error("Service unavailable"));
const result = await collectRepositoryDiscoveryIssues(() =>
getAzureDevOpsReposFromConfig(config({ orgs: ["my-org"] }))
);
expect(result).toEqual({
value: [],
issues: [
{
code: "INVALID_PROVIDER_RESPONSE",
effect: "DISCOVERY_INCOMPLETE",
subject: {
kind: "project",
value: "my-org/missing-id",
},
message: "Azure DevOps returned a project without an ID, so its repositories were skipped.",
},
{
code: "ENUMERATION_FAILED",
effect: "DISCOVERY_INCOMPLETE",
subject: {
kind: "project",
value: "my-org/broken-project",
},
message: "Azure DevOps repository enumeration did not complete for this project.",
},
],
});
});
});