Skip to content

Commit

Permalink
feat: throw helpful error when appId or privateKey is set to a fa…
Browse files Browse the repository at this point in the history
…lsy value (#280)

* test: throw helpful error when `appId` or `privateKey` is set to a falsy value

* feat: throw helpful error when `appId` or `privateKey` is set to a falsy value
  • Loading branch information
gr2m authored Apr 22, 2021
1 parent 92e6903 commit ee7b247
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ export {
export const createAppAuth: StrategyInterface = function createAppAuth(
options: StrategyOptions
) {
if (!options.appId) {
throw new Error("[@octokit/auth-app] appId option is required");
}
if (!options.privateKey) {
throw new Error("[@octokit/auth-app] privateKey option is required");
}
if ("installationId" in options && !options.installationId) {
throw new Error(
"[@octokit/auth-app] installationId is set to a falsy value"
);
}

const log = Object.assign(
{
warn: console.warn.bind(console),
Expand Down
2 changes: 1 addition & 1 deletion test/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("deprecations", () => {
const warn = jest.fn();
const auth = createAppAuth({
appId: "1",
privateKey: "",
privateKey: "1",
clientId: "12345678901234567890",
clientSecret: "1234567890123456789012345678901234567890",
log: { warn },
Expand Down
30 changes: 30 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2135,3 +2135,33 @@ test("factory auth option", async () => {
})
);
});

it("throws helpful error if `appId` is not set properly (#184)", async () => {
expect(() => {
createAppAuth({
// @ts-ignore
appId: undefined,
privateKey: PRIVATE_KEY,
});
}).toThrowError("[@octokit/auth-app] appId option is required");
});

it("throws helpful error if `privateKey` is not set properly (#184)", async () => {
expect(() => {
createAppAuth({
appId: APP_ID,
// @ts-ignore
privateKey: undefined,
});
}).toThrowError("[@octokit/auth-app] privateKey option is required");
});

it("throws helpful error if `installationId` is set to a falsy value in createAppAuth() (#184)", async () => {
expect(() => {
createAppAuth({
appId: APP_ID,
privateKey: PRIVATE_KEY,
installationId: "",
});
}).toThrowError("[@octokit/auth-app] installationId is set to a falsy value");
});

0 comments on commit ee7b247

Please sign in to comment.