|
1 | | -const plugin = require("./create-or-update-files"); |
| 1 | +import CreateOrUpdateMultipleFiles from "."; |
| 2 | +import CreateOrUpdateMultipleFilesHandler from "./create-or-update-files"; |
2 | 3 | const { Octokit } = require("@octokit/rest"); |
3 | 4 |
|
4 | 5 | const nock = require("nock"); |
5 | 6 | nock.disableNetConnect(); |
6 | 7 | const octokit = new Octokit(); |
7 | 8 |
|
8 | 9 | function run(body: any) { |
9 | | - return plugin(octokit, body); |
| 10 | + return CreateOrUpdateMultipleFilesHandler(octokit, body); |
10 | 11 | } |
11 | 12 |
|
12 | | -const validRequest = { |
| 13 | +type RequestStructure = { |
| 14 | + owner: string; |
| 15 | + repo: string; |
| 16 | + branch: string; |
| 17 | + createBranch: boolean; |
| 18 | + base?: string; // Marked as optional |
| 19 | + changes?: Array<{ |
| 20 | + message: string; |
| 21 | + files: Record<string, string | { contents: string }>; |
| 22 | + }>; |
| 23 | +}; |
| 24 | + |
| 25 | +const validRequest: RequestStructure = { |
13 | 26 | owner: "mheap", |
14 | 27 | repo: "test-repo", |
15 | 28 | branch: "new-branch-name", |
@@ -43,8 +56,8 @@ const mockSubmoduleCommitList = { |
43 | 56 | }; |
44 | 57 |
|
45 | 58 | for (let req of ["owner", "repo", "branch"]) { |
46 | | - const body = { ...validRequest }; |
47 | | - delete body[req]; |
| 59 | + const body: RequestStructure = { ...validRequest }; |
| 60 | + delete body[req as keyof RequestStructure]; |
48 | 61 | test(`missing parameter (${req})`, () => { |
49 | 62 | expect(run(body)).rejects.toEqual(`'${req}' is a required parameter`); |
50 | 63 | }); |
@@ -499,18 +512,18 @@ test("failure (fileToDelete is missing)", async () => { |
499 | 512 | }); |
500 | 513 |
|
501 | 514 | test("Loads plugin", () => { |
502 | | - const TestOctokit = Octokit.plugin(require(".")); |
| 515 | + const TestOctokit = Octokit.plugin(CreateOrUpdateMultipleFiles); |
503 | 516 | const testOctokit = new TestOctokit(); |
504 | 517 | expect(testOctokit).toHaveProperty("createOrUpdateFiles"); |
505 | 518 | }); |
506 | 519 |
|
507 | 520 | test("Does not overwrite other methods", () => { |
508 | | - const TestOctokit = Octokit.plugin(require(".")); |
| 521 | + const TestOctokit = Octokit.plugin(CreateOrUpdateMultipleFiles); |
509 | 522 | const testOctokit = new TestOctokit(); |
510 | 523 | expect(testOctokit).toHaveProperty("rest.repos.acceptInvitation"); |
511 | 524 | }); |
512 | 525 |
|
513 | | -function mockGetRef(branch: string, sha: string, success: boolean) { |
| 526 | +function mockGetRef(branch: string | undefined, sha: string, success: boolean) { |
514 | 527 | const m = nock("https://api.github.com").get( |
515 | 528 | `/repos/${owner}/${repo}/git/ref/heads%2F${branch}`, |
516 | 529 | ); |
|
0 commit comments