Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitLabPullRequestProvider.test.ts

40 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { gitLabViewerPermissions } from "./GitLabPullRequestProvider.ts";
4​
5describe("gitLabViewerPermissions", () => {
6 it("offers everything to a viewer GitLab says can merge", () => {
7 expect(gitLabViewerPermissions({ viewerCanMerge: true })).toEqual({
8 actions: ["merge", "ready", "draft", "close", "reopen"],
9 comment: true,
10 resolve: true,
11 verdicts: ["comment", "approve"],
12 // GitLab says nothing about who may set a reviewer, and an unreported permission is granted.
13 requestReviewers: true,
14 });
15 });
16​
17 it("keeps merge from a viewer GitLab says cannot", () => {
18 // `user.can_merge` already accounts for the role, the approval rules and a protected target
19 // branch, so it is the one answer here that does not have to be inferred.
20 expect(gitLabViewerPermissions({ viewerCanMerge: false })).toEqual({
21 actions: ["ready", "draft", "close", "reopen"],
22 comment: true,
23 resolve: true,
24 verdicts: ["comment", "approve"],
25 requestReviewers: true,
26 });
27 });
28​
29 it("treats an author with read access as any other reader, which is all GitLab says", () => {
30 // Its REST API names no relationship between the viewer and the merge request beyond
31 // `can_merge`, so the four an author keeps stay offered to everyone rather than being taken
32 // from the one person entitled to them.
33 expect(gitLabViewerPermissions({ viewerCanMerge: false }).actions).toEqual([
34 "ready",
35 "draft",
36 "close",
37 "reopen",
38 ]);
39 });
40});