Repository navigation
Expand file tree
/
Copy pathgithub.test.js
More file actions
663 lines (604 loc) · 22.9 KB
/
Copy pathgithub.test.js
File metadata and controls
663 lines (604 loc) · 22.9 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
const { getPendingReviews } = require("./github");
global.fetch = jest.fn();
const MOCK_TOKEN = "ghp_test123";
beforeEach(() => {
fetch.mockClear();
});
function graphqlOk(nodes) {
return {
ok: true,
json: async () => ({
data: { repository: { pullRequests: { nodes } } },
}),
};
}
describe("getPendingReviews (GraphQL)", () => {
test("issues one POST per repo against the GraphQL endpoint with Bearer auth", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
{
number: 10,
title: "Add feature",
url: "https://github.com/celestiaorg/celestia-app/pull/10",
isDraft: false,
author: { login: "cmwaters" },
reviewRequests: {
nodes: [{ requestedReviewer: { login: "rootulp" } }],
},
timelineItems: {
nodes: [
{
createdAt: "2026-04-13T08:00:00Z",
requestedReviewer: { login: "rootulp" },
},
],
},
},
])
);
const config = {
org: "celestiaorg",
repos: ["celestia-app"],
teamMembers: [
{ name: "Rootul", github: "rootulp", defaultHidden: false },
{ name: "Nina", github: "ninabarbakadze", defaultHidden: false },
],
};
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(fetch).toHaveBeenCalledTimes(1);
const [url, opts] = fetch.mock.calls[0];
expect(url).toBe("https://api.github.com/graphql");
expect(opts.method).toBe("POST");
expect(opts.headers.Authorization).toBe(`Bearer ${MOCK_TOKEN}`);
const body = JSON.parse(opts.body);
expect(body.variables).toEqual({
owner: "celestiaorg",
name: "celestia-app",
});
expect(typeof body.query).toBe("string");
expect(result.rootulp).toHaveLength(1);
expect(result.rootulp[0]).toEqual({
number: 10,
title: "Add feature",
url: "https://github.com/celestiaorg/celestia-app/pull/10",
repo: "celestia-app",
author: "cmwaters",
authorCategory: "external",
reviewer: "rootulp",
requestedAt: "2026-04-13T08:00:00Z",
});
expect(result.ninabarbakadze).toEqual([]);
});
test("filters out draft PRs", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
{
number: 1,
title: "Draft work",
url: "https://github.com/celestiaorg/celestia-app/pull/1",
isDraft: true,
author: { login: "cmwaters" },
reviewRequests: {
nodes: [{ requestedReviewer: { login: "rootulp" } }],
},
timelineItems: {
nodes: [
{
createdAt: "2026-04-13T08:00:00Z",
requestedReviewer: { login: "rootulp" },
},
],
},
},
])
);
const config = {
org: "celestiaorg",
repos: ["celestia-app"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toEqual([]);
});
test("ignores requested reviewers not on the team", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
{
number: 1,
title: "External reviewer",
url: "https://github.com/celestiaorg/celestia-app/pull/1",
isDraft: false,
author: { login: "cmwaters" },
reviewRequests: {
nodes: [{ requestedReviewer: { login: "external-dev" } }],
},
timelineItems: { nodes: [] },
},
])
);
const config = {
org: "celestiaorg",
repos: ["celestia-app"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toEqual([]);
});
test("picks the most recent review_requested timestamp when re-requested", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
{
number: 1,
title: "Re-requested",
url: "https://github.com/celestiaorg/celestia-app/pull/1",
isDraft: false,
author: { login: "cmwaters" },
reviewRequests: {
nodes: [{ requestedReviewer: { login: "rootulp" } }],
},
timelineItems: {
nodes: [
{
createdAt: "2026-04-10T10:00:00Z",
requestedReviewer: { login: "rootulp" },
},
{
createdAt: "2026-04-11T09:00:00Z",
requestedReviewer: { login: "rootulp" },
},
],
},
},
])
);
const config = {
org: "celestiaorg",
repos: ["celestia-app"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toHaveLength(1);
expect(result.rootulp[0].requestedAt).toBe("2026-04-11T09:00:00Z");
});
test("tolerates per-repo failures and still returns successful repos", async () => {
fetch
.mockResolvedValueOnce({
ok: false,
status: 500,
json: async () => ({ message: "server error" }),
})
.mockResolvedValueOnce(
graphqlOk([
{
number: 2,
title: "OK",
url: "https://github.com/celestiaorg/celestia-core/pull/2",
isDraft: false,
author: { login: "cmwaters" },
reviewRequests: {
nodes: [{ requestedReviewer: { login: "rootulp" } }],
},
timelineItems: {
nodes: [
{
createdAt: "2026-04-13T08:00:00Z",
requestedReviewer: { login: "rootulp" },
},
],
},
},
])
);
const config = {
org: "celestiaorg",
repos: ["celestia-app", "celestia-core"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
try {
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toHaveLength(1);
expect(result.rootulp[0].number).toBe(2);
expect(result.rootulp[0].repo).toBe("celestia-core");
} finally {
warnSpy.mockRestore();
}
});
test("annotates an unreachable repo when running in GitHub Actions", async () => {
fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({
data: { repository: null },
errors: [
{
type: "NOT_FOUND",
message:
"Could not resolve to a Repository with the name 'celestiaorg/infrastructure'.",
},
],
}),
});
const config = {
org: "celestiaorg",
repos: ["infrastructure"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
const previous = process.env.GITHUB_ACTIONS;
process.env.GITHUB_ACTIONS = "true";
try {
await getPendingReviews(config, MOCK_TOKEN);
expect(warnSpy).toHaveBeenCalledTimes(1);
const message = warnSpy.mock.calls[0][0];
expect(message).toMatch(/^::warning::/);
expect(message).toContain("infrastructure");
} finally {
if (previous === undefined) delete process.env.GITHUB_ACTIONS;
else process.env.GITHUB_ACTIONS = previous;
warnSpy.mockRestore();
}
});
test("logs a plain warning for an unreachable repo outside GitHub Actions", async () => {
fetch.mockResolvedValueOnce({
ok: false,
status: 500,
json: async () => ({ message: "server error" }),
});
const config = {
org: "celestiaorg",
repos: ["infrastructure"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
const previous = process.env.GITHUB_ACTIONS;
delete process.env.GITHUB_ACTIONS;
try {
await getPendingReviews(config, MOCK_TOKEN);
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy.mock.calls[0][0]).not.toMatch(/^::warning::/);
expect(warnSpy.mock.calls[0][0]).toContain("infrastructure");
} finally {
if (previous !== undefined) process.env.GITHUB_ACTIONS = previous;
warnSpy.mockRestore();
}
});
});
describe("dismissed reviews", () => {
const config = {
org: "celestiaorg",
repos: ["celestia-app"],
teamMembers: [
{ name: "Rootul", github: "rootulp" },
{ name: "Nina", github: "ninabarbakadze" },
],
};
const dismissedAt = "2026-04-13T10:00:00Z";
const original = {
id: "review-1", author: { login: "rootulp" },
submittedAt: "2026-04-12T08:00:00Z", state: "DISMISSED",
};
const dismissal = { createdAt: dismissedAt, review: original };
function pr(nodes = [original, dismissal], requested = [], extra = {}) {
return {
number: 10, title: "Needs another look", url: "https://example.com/10",
isDraft: false, author: { login: "cmwaters" }, authorAssociation: "MEMBER",
reviewRequests: { nodes: requested.map((login) => ({ requestedReviewer: { login } })) },
timelineItems: { nodes },
...extra,
};
}
test("restores a dismissed review without an explicit request, timed from dismissal", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr()]));
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toEqual([expect.objectContaining({
number: 10, requestedAt: dismissedAt, reviewer: "rootulp", authorCategory: "coworker",
})]);
expect(result.ninabarbakadze).toEqual([]);
const query = JSON.parse(fetch.mock.calls[0][1].body).query;
expect(query).toContain("REVIEW_DISMISSED_EVENT");
expect(query).toContain("PULL_REQUEST_REVIEW");
});
test.each(["APPROVED", "CHANGES_REQUESTED", "COMMENTED"])(
"a replacement %s review clears the dismissal", async (state) => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
original, dismissal,
{ id: "review-2", author: original.author, submittedAt: "2026-04-13T11:00:00Z", state },
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toEqual([]);
}
);
test("dismissing an older review does not undo a newer approval", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
original,
{ id: "review-2", author: original.author, submittedAt: "2026-04-13T09:00:00Z", state: "APPROVED" },
dismissal,
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toEqual([]);
});
test("a comment before dismissal does not satisfy the new need to review", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
original,
{ id: "comment", author: original.author, submittedAt: "2026-04-13T09:00:00Z", state: "COMMENTED" },
dismissal,
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp[0].requestedAt).toBe(dismissedAt);
});
test("an unsubmitted review or another person's review does not clear the dismissal", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
original, dismissal,
{ id: "draft", author: original.author, submittedAt: null, state: "PENDING" },
{ id: "other", author: { login: "ninabarbakadze" }, submittedAt: "2026-04-13T11:00:00Z", state: "APPROVED" },
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toHaveLength(1);
});
test.each(["2026-04-13T09:00:00Z", "2026-04-13T11:00:00Z"])(
"deduplicates an explicit request at %s and uses the latest wait start", async (createdAt) => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
original, dismissal, { createdAt, requestedReviewer: original.author },
], ["rootulp"])]));
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toHaveLength(1);
expect(result.rootulp[0].requestedAt).toBe(createdAt > dismissedAt ? createdAt : dismissedAt);
}
);
test("a replacement review can itself be dismissed and restore the queue again", async () => {
const replacement = { ...original, id: "review-2", submittedAt: "2026-04-13T11:00:00Z" };
const again = "2026-04-14T10:00:00Z";
fetch.mockResolvedValueOnce(graphqlOk([pr([
original, dismissal, replacement, { createdAt: again, review: replacement },
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp[0].requestedAt).toBe(again);
});
test("ignores drafts, non-team reviewers, deleted authors and deleted reviews", async () => {
fetch.mockResolvedValueOnce(graphqlOk([
pr(undefined, [], { isDraft: true }),
pr([{ ...dismissal, review: { ...original, author: { login: "external" } } }]),
pr([{ ...dismissal, review: { ...original, author: null } }]),
pr([{ ...dismissal, review: null }]),
]));
expect(await getPendingReviews(config, MOCK_TOKEN)).toEqual({ rootulp: [], ninabarbakadze: [] });
});
test.each([true, false])("reads later timeline pages (replacement review: %s)", async (replaced) => {
const node = pr();
node.timelineItems.pageInfo = { hasNextPage: true, endCursor: "next-page" };
const later = replaced
? [{ id: "review-2", author: original.author, submittedAt: "2026-04-13T11:00:00Z", state: "APPROVED" }]
: [dismissal];
node.timelineItems.nodes = [original];
fetch.mockResolvedValueOnce(graphqlOk([node])).mockResolvedValueOnce({
ok: true,
json: async () => ({ data: { repository: { pullRequest: {
timelineItems: { nodes: later, pageInfo: { hasNextPage: false, endCursor: null } },
} } } }),
});
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toHaveLength(replaced ? 0 : 1);
expect(JSON.parse(fetch.mock.calls[1][1].body).variables).toEqual({
owner: "celestiaorg", name: "celestia-app", number: 10, after: "next-page",
});
});
});
describe("commits after approval", () => {
const config = {
org: "celestiaorg", repos: ["celestia-app"],
teamMembers: [{ name: "Rootul", github: "rootulp" }],
};
const approvedAt = "2026-04-13T09:00:00Z";
const pushedAt = "2026-04-13T10:00:00Z";
const approval = {
author: { login: "rootulp" }, state: "APPROVED", submittedAt: approvedAt,
commit: { oid: "original" },
};
function pr(reviews = [approval], extra = {}) {
return {
number: 10, title: "Updated PR", url: "https://example.com/10", isDraft: false,
author: { login: "cmwaters" }, headRefOid: "new-head",
commits: { nodes: [{ commit: { oid: "new-head", committedDate: pushedAt, pushedDate: pushedAt } }] },
reviewRequests: { nodes: [] }, timelineItems: { nodes: reviews }, ...extra,
};
}
test("restores a PR after commits follow an approval without an explicit request", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr()]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toEqual([
expect.objectContaining({ number: 10, requestedAt: pushedAt }),
]);
const query = JSON.parse(fetch.mock.calls[0][1].body).query;
expect(query).toContain("headRefOid");
expect(query).toContain("commit { oid }");
});
test.each(["APPROVED", "CHANGES_REQUESTED", "COMMENTED"])(
"a later %s review clears the entry", async (state) => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
approval, { ...approval, state, submittedAt: "2026-04-13T11:00:00Z", commit: { oid: "new-head" } },
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toEqual([]);
}
);
test("does not add an approval of the current head, even with a future commit date", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([{ ...approval, commit: { oid: "new-head" } }])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toEqual([]);
});
test("a comment before the new commits does not satisfy the need to review them", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
approval, { ...approval, state: "COMMENTED", submittedAt: "2026-04-13T09:30:00Z" },
])]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp[0].requestedAt).toBe(pushedAt);
});
test("detects a newly pushed head even with an old commit date and no push date", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([approval], {
commits: { nodes: [{ commit: { oid: "new-head", committedDate: "2026-04-12T10:00:00Z", pushedDate: null } }] },
})]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp[0].requestedAt).toBe(approvedAt);
});
test("ignores unsubmitted drafts, other reviewers, non-approvals and draft PRs", async () => {
fetch.mockResolvedValueOnce(graphqlOk([
pr([approval, { ...approval, state: "PENDING", submittedAt: null }]),
pr([{ ...approval, author: { login: "external" } }]),
pr([{ ...approval, state: "COMMENTED" }]),
pr([{ ...approval, state: "CHANGES_REQUESTED" }]),
pr([approval], { isDraft: true }),
]));
expect((await getPendingReviews(config, MOCK_TOKEN)).rootulp).toHaveLength(1);
});
test("combines new commits, dismissal and explicit requests into one queue entry", async () => {
const dismissed = { ...approval, state: "DISMISSED" };
fetch.mockResolvedValueOnce(graphqlOk([pr([
dismissed, { review: dismissed, createdAt: pushedAt },
{ requestedReviewer: approval.author, createdAt: approvedAt },
], { reviewRequests: { nodes: [{ requestedReviewer: approval.author }] } })]));
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toHaveLength(1);
expect(result.rootulp[0].requestedAt).toBe(pushedAt);
});
test("deduplicates a new-commit entry with an explicit request", async () => {
fetch.mockResolvedValueOnce(graphqlOk([pr([
approval, { requestedReviewer: approval.author, createdAt: approvedAt },
], { reviewRequests: { nodes: [{ requestedReviewer: approval.author }] } })]));
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp).toHaveLength(1);
expect(result.rootulp[0].requestedAt).toBe(pushedAt);
});
});
describe("pending review ordering", () => {
const config = {
org: "celestiaorg",
repos: ["celestia-app"],
teamMembers: [{ name: "Rootul", github: "rootulp", defaultHidden: false }],
};
// Minimal PR node: always requests a review from rootulp so every PR lands
// in his queue, with `requestedAt` controlling the within-group order.
function prNode({ number, author, authorAssociation, requestedAt }) {
return {
number,
title: `PR ${number}`,
url: `https://github.com/celestiaorg/celestia-app/pull/${number}`,
isDraft: false,
author,
authorAssociation,
reviewRequests: { nodes: [{ requestedReviewer: { login: "rootulp" } }] },
timelineItems: {
nodes: [{ createdAt: requestedAt, requestedReviewer: { login: "rootulp" } }],
},
};
}
test("labels org members, bots, and outside contributors", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
prNode({
number: 1,
author: { login: "vgonkivs", __typename: "User" },
authorAssociation: "MEMBER",
requestedAt: "2026-04-13T08:00:00Z",
}),
prNode({
number: 2,
author: { login: "dependabot", __typename: "Bot" },
authorAssociation: "CONTRIBUTOR",
requestedAt: "2026-04-13T09:00:00Z",
}),
prNode({
number: 3,
author: { login: "drive-by", __typename: "User" },
authorAssociation: "FIRST_TIME_CONTRIBUTOR",
requestedAt: "2026-04-13T10:00:00Z",
}),
prNode({
number: 4,
author: { login: "contractor", __typename: "User" },
authorAssociation: "COLLABORATOR",
requestedAt: "2026-04-13T11:00:00Z",
}),
])
);
const result = await getPendingReviews(config, MOCK_TOKEN);
const byNumber = Object.fromEntries(
result.rootulp.map((pr) => [pr.number, pr.authorCategory])
);
expect(byNumber).toEqual({
1: "coworker",
2: "bot",
3: "external",
4: "coworker",
});
});
test("treats a `[bot]` login as a bot even when typed as a user", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
prNode({
number: 1,
author: { login: "dependabot[bot]", __typename: "User" },
authorAssociation: "CONTRIBUTOR",
requestedAt: "2026-04-13T08:00:00Z",
}),
])
);
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp[0].authorCategory).toBe("bot");
});
test("treats configured team members as coworkers regardless of association", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
prNode({
number: 1,
author: { login: "rootulp", __typename: "User" },
authorAssociation: "NONE",
requestedAt: "2026-04-13T08:00:00Z",
}),
])
);
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp[0].authorCategory).toBe("coworker");
});
test("orders coworkers, then bots, then external contributors", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
prNode({
number: 1,
author: { login: "drive-by", __typename: "User" },
authorAssociation: "CONTRIBUTOR",
requestedAt: "2026-04-01T08:00:00Z",
}),
prNode({
number: 2,
author: { login: "dependabot", __typename: "Bot" },
authorAssociation: "CONTRIBUTOR",
requestedAt: "2026-04-02T08:00:00Z",
}),
prNode({
number: 3,
author: { login: "vgonkivs", __typename: "User" },
authorAssociation: "MEMBER",
requestedAt: "2026-04-03T08:00:00Z",
}),
])
);
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp.map((pr) => pr.number)).toEqual([3, 2, 1]);
});
test("orders the longest wait first within a group", async () => {
fetch.mockResolvedValueOnce(
graphqlOk([
prNode({
number: 1,
author: { login: "renaynay", __typename: "User" },
authorAssociation: "MEMBER",
requestedAt: "2026-04-03T08:00:00Z",
}),
prNode({
number: 2,
author: { login: "vgonkivs", __typename: "User" },
authorAssociation: "MEMBER",
requestedAt: "2026-04-01T08:00:00Z",
}),
prNode({
number: 3,
author: { login: "mcrakhman", __typename: "User" },
authorAssociation: "MEMBER",
requestedAt: "2026-04-02T08:00:00Z",
}),
])
);
const result = await getPendingReviews(config, MOCK_TOKEN);
expect(result.rootulp.map((pr) => pr.number)).toEqual([2, 3, 1]);
});
});