forked from keithah/multi-provider-code-review
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreview-request.test.ts
More file actions
78 lines (71 loc) · 2.12 KB
/
Copy pathreview-request.test.ts
File metadata and controls
78 lines (71 loc) · 2.12 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
import {
ControlPlaneManualReviewRequestClient,
ManualReviewRequestAvailability,
} from '../../../src/control-plane/review-request';
const applied = {
status: 'applied' as const,
apiUrl: 'https://api.reviewrouter.site',
actionVersion: '1.0.0',
configVersion: 1,
sessionToken: 'session-token',
};
describe('ControlPlaneManualReviewRequestClient', () => {
it('treats runtime-config fallback as unavailable rather than legacy-safe', () => {
const client = new ControlPlaneManualReviewRequestClient({
status: 'fallback',
reason: 'network_error',
});
expect(client.availability()).toBe(
ManualReviewRequestAvailability.Unavailable
);
});
it('does not treat repository_not_registered as an unsupported endpoint', async () => {
const client = new ControlPlaneManualReviewRequestClient(
applied,
jest.fn(
async () =>
new Response(
JSON.stringify({ error: { code: 'repository_not_registered' } }),
{ status: 404, headers: { 'content-type': 'application/json' } }
)
) as typeof fetch
);
await expect(client.request(command())).rejects.toThrow(
'manual_review_request_failed:404:repository_not_registered'
);
});
it.each([
[{ error: { code: 'review_request_intent_disabled' } }],
[
{
error: 'Not Found',
message: 'Route POST:/api/action/v1/review-requests/manual not found',
},
],
])(
'allows legacy fallback only for an explicitly unsupported endpoint',
async (body) => {
const client = new ControlPlaneManualReviewRequestClient(
applied,
jest.fn(
async () =>
new Response(JSON.stringify(body), {
status: 404,
headers: { 'content-type': 'application/json' },
})
) as typeof fetch
);
await expect(client.request(command())).resolves.toEqual({
status: 'unsupported',
});
}
);
});
function command() {
return {
pullRequestNumber: 252,
expectedHeadSha: 'a'.repeat(40),
sourceId: 'manual-comment:1',
commandKind: 'review' as const,
};
}