Skip to content

Commit 0149f25

Browse files
authored
Switch to default exports (#130)
1 parent d28bfc9 commit 0149f25

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

create-or-update-files.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
const plugin = require("./create-or-update-files");
1+
import CreateOrUpdateMultipleFiles from ".";
2+
import CreateOrUpdateMultipleFilesHandler from "./create-or-update-files";
23
const { Octokit } = require("@octokit/rest");
34

45
const nock = require("nock");
56
nock.disableNetConnect();
67
const octokit = new Octokit();
78

89
function run(body: any) {
9-
return plugin(octokit, body);
10+
return CreateOrUpdateMultipleFilesHandler(octokit, body);
1011
}
1112

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 = {
1326
owner: "mheap",
1427
repo: "test-repo",
1528
branch: "new-branch-name",
@@ -43,8 +56,8 @@ const mockSubmoduleCommitList = {
4356
};
4457

4558
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];
4861
test(`missing parameter (${req})`, () => {
4962
expect(run(body)).rejects.toEqual(`'${req}' is a required parameter`);
5063
});
@@ -499,18 +512,18 @@ test("failure (fileToDelete is missing)", async () => {
499512
});
500513

501514
test("Loads plugin", () => {
502-
const TestOctokit = Octokit.plugin(require("."));
515+
const TestOctokit = Octokit.plugin(CreateOrUpdateMultipleFiles);
503516
const testOctokit = new TestOctokit();
504517
expect(testOctokit).toHaveProperty("createOrUpdateFiles");
505518
});
506519

507520
test("Does not overwrite other methods", () => {
508-
const TestOctokit = Octokit.plugin(require("."));
521+
const TestOctokit = Octokit.plugin(CreateOrUpdateMultipleFiles);
509522
const testOctokit = new TestOctokit();
510523
expect(testOctokit).toHaveProperty("rest.repos.acceptInvitation");
511524
});
512525

513-
function mockGetRef(branch: string, sha: string, success: boolean) {
526+
function mockGetRef(branch: string | undefined, sha: string, success: boolean) {
514527
const m = nock("https://api.github.com").get(
515528
`/repos/${owner}/${repo}/git/ref/heads%2F${branch}`,
516529
);

create-or-update-files.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function isBase64(str: string | Buffer): boolean {
5656
);
5757
}
5858

59-
module.exports = function (
59+
export default function (
6060
octokit: Octokit,
6161
opts: Options,
6262
): Promise<CommitResult> {
@@ -292,7 +292,7 @@ module.exports = function (
292292
return reject(e);
293293
}
294294
});
295-
};
295+
}
296296

297297
async function fileExistsInRepo(
298298
octokit: Octokit,

index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Octokit } from "@octokit/rest";
22

3-
const createOrUpdateFilesPlugin = require("./create-or-update-files");
3+
import createOrUpdateFilesPlugin from "./create-or-update-files";
44

5-
module.exports = function (octokit: Octokit) {
5+
export default function (octokit: Octokit) {
66
return {
77
createOrUpdateFiles: createOrUpdateFilesPlugin.bind(null, octokit),
88
};
9-
};
9+
}

0 commit comments

Comments
 (0)