Skip to content

Commit

Permalink
feat: createNodeMiddleware(). Deprecate getNodeMiddleware() (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored Mar 21, 2021
1 parent f4cf342 commit 48a4085
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,23 @@ import {
AddEventHandler,
State,
} from "./types";
import { createNodeMiddleware } from "./middleware/node/index";
import { MiddlewareOptions } from "./middleware/node/types";

export { getAuthorizationUrl } from "./methods/get-authorization-url";
export { createToken } from "./methods/create-token";
export { checkToken } from "./methods/check-token";
export { resetToken } from "./methods/reset-token";
export { deleteToken } from "./methods/delete-token";
export { deleteAuthorization } from "./methods/delete-authorization";
export { getNodeMiddleware } from "./middleware/node/index";
export { createNodeMiddleware } from "./middleware/node/index";

export function getNodeMiddleware(app: OAuthApp, options?: MiddlewareOptions) {
console.warn(
`[@octokit/oauth-app] getNodeMiddleWare() is deprecated. Use createNodeMiddleware() instead`
);
return createNodeMiddleware(app, options);
}

export class OAuthApp {
static VERSION = VERSION;
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { middleware } from "./middleware";
import { MiddlewareOptions } from "./types";
import { onUnhandledRequestDefault } from "./on-unhandled-request-default";

export function getNodeMiddleware(
export function createNodeMiddleware(
app: OAuthApp,
{
pathPrefix = "/api/github/oauth",
Expand Down
17 changes: 17 additions & 0 deletions test/deprecations.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getNodeMiddleware, OAuthApp } from "../src";

describe("deprecations", () => {
it("getNodeMiddleware", () => {
const app = new OAuthApp({
clientId: "0123",
clientSecret: "0123secret",
});

console.warn = jest.fn();
getNodeMiddleware(app);

expect(console.warn).toHaveBeenCalledWith(
"[@octokit/oauth-app] getNodeMiddleWare() is deprecated. Use createNodeMiddleware() instead"
);
});
});
44 changes: 22 additions & 22 deletions test/node-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createServer, IncomingMessage, ServerResponse } from "http";
import { createServer } from "http";
import { URL } from "url";

import fetch from "node-fetch";
import { OAuthApp, getNodeMiddleware } from "../src/";
import { OAuthApp, createNodeMiddleware } from "../src/";

describe("getNodeMiddleware(app)", () => {
describe("createNodeMiddleware(app)", () => {
it("GET /api/github/oauth/login", async () => {
const app = new OAuthApp({
clientId: "0123",
clientSecret: "0123secret",
});

const server = createServer(getNodeMiddleware(app)).listen();
const server = createServer(createNodeMiddleware(app)).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();

Expand Down Expand Up @@ -43,7 +43,7 @@ describe("getNodeMiddleware(app)", () => {
defaultScopes: ["repo"],
});

const server = createServer(getNodeMiddleware(app)).listen();
const server = createServer(createNodeMiddleware(app)).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();

Expand Down Expand Up @@ -74,7 +74,7 @@ describe("getNodeMiddleware(app)", () => {
clientSecret: "0123secret",
});

const server = createServer(getNodeMiddleware(app)).listen();
const server = createServer(createNodeMiddleware(app)).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();

Expand Down Expand Up @@ -106,7 +106,7 @@ describe("getNodeMiddleware(app)", () => {
};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("getNodeMiddleware(app)", () => {
};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("getNodeMiddleware(app)", () => {
};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down Expand Up @@ -207,7 +207,7 @@ describe("getNodeMiddleware(app)", () => {
};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down Expand Up @@ -243,7 +243,7 @@ describe("getNodeMiddleware(app)", () => {
};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down Expand Up @@ -274,7 +274,7 @@ describe("getNodeMiddleware(app)", () => {
};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down Expand Up @@ -308,7 +308,7 @@ describe("getNodeMiddleware(app)", () => {
});

const server = createServer(
getNodeMiddleware(app, {
createNodeMiddleware(app, {
onUnhandledRequest: (request, response) => {
expect(request.method).toEqual("POST");
expect(request.url).toEqual("/unrelated");
Expand Down Expand Up @@ -346,7 +346,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -362,7 +362,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -384,7 +384,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -406,7 +406,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -432,7 +432,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -457,7 +457,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -481,7 +481,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -506,7 +506,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand All @@ -531,7 +531,7 @@ describe("getNodeMiddleware(app)", () => {
const appMock = {};

const server = createServer(
getNodeMiddleware((appMock as unknown) as OAuthApp)
createNodeMiddleware((appMock as unknown) as OAuthApp)
).listen();
// @ts-ignore complains about { port } although it's included in returned AddressInfo interface
const { port } = server.address();
Expand Down

0 comments on commit 48a4085

Please sign in to comment.