/
delete-files.test.ts
62 lines (54 loc) · 1.64 KB
/
delete-files.test.ts
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
import { Octokit as Core } from "@octokit/core";
import { RequestError } from "@octokit/request-error";
import { createPullRequest, DELETE_FILE } from "../src";
const Octokit = Core.plugin(createPullRequest);
test("delete files", async () => {
const fixtures = require("./fixtures/delete-files");
const fixturePr = fixtures[fixtures.length - 1].response;
const octokit = new Octokit();
octokit.hook.wrap("request", (_, options) => {
const currentFixtures = fixtures.shift();
const {
baseUrl,
method,
url,
request,
headers,
mediaType,
draft,
...params
} = options;
expect(
`${currentFixtures.request.method} ${currentFixtures.request.url}`
).toEqual(`${options.method} ${options.url}`);
Object.keys(params).forEach((paramName) => {
expect(currentFixtures.request[paramName]).toStrictEqual(
params[paramName]
);
});
if (currentFixtures.response.status >= 400) {
throw new RequestError("Error", currentFixtures.response.status, {
request: currentFixtures.request,
headers: currentFixtures.response.headers,
});
}
return currentFixtures.response;
});
const pr = await octokit.createPullRequest({
owner: "gr2m",
repo: "pull-request-test",
title: "One comes, one goes",
body: "because",
head: "patch",
changes: {
files: {
"path/to/file1.txt": "Content for file1",
"path/to/file2.txt": DELETE_FILE,
"path/to/file-does-not-exist.txt": DELETE_FILE,
},
commit: "why",
},
});
expect(pr).toStrictEqual(fixturePr);
expect(fixtures.length).toEqual(0);
});