Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import * as BitbucketApi from "../sourceControl/BitbucketApi.ts";
4import {
5 bitbucketErrorReason,
6 bitbucketViewerPermissions,
7} from "./BitbucketPullRequestProvider.ts";
8
9describe("bitbucketErrorReason", () => {
10 it("treats only an HTTP 401 as unusable credentials", () => {
11 const responseError = (status: number) =>
12 new BitbucketApi.BitbucketResponseError({
13 operation: "request",
14 status,
15 responseBodyLength: 0,
16 });
17
18 expect(bitbucketErrorReason(responseError(401))).toBe("unauthenticated");
19 expect(bitbucketErrorReason(responseError(403))).toBe("failed");
20 });
21});
22
23describe("bitbucketViewerPermissions", () => {
24 it("offers both actions to credentials with write access", () => {
25 expect(bitbucketViewerPermissions({ canWrite: true })).toEqual({
26 actions: ["merge", "close"],
27 comment: true,
28 resolve: true,
29 verdicts: ["comment", "approve", "request-changes"],
30 // Bitbucket says nothing about who may set a reviewer, and an unreported permission is
31 // granted.
32 requestReviewers: true,
33 });
34 });
35
36 it("keeps merge from credentials that can only read the repository", () => {
37 expect(bitbucketViewerPermissions({ canWrite: false })).toEqual({
38 actions: ["close"],
39 comment: true,
40 resolve: true,
41 verdicts: ["comment", "approve", "request-changes"],
42 requestReviewers: true,
43 });
44 });
45
46 it("treats an author with read access as any other reader, which is all Bitbucket says", () => {
47 // The repository permission is the whole of what Bitbucket reports per account; it says
48 // nothing about who opened this pull request, and its author may decline it with read access
49 // alone — so declining stays offered rather than being taken from them.
50 expect(bitbucketViewerPermissions({ canWrite: false }).actions).toEqual(["close"]);
51 });
52});