-
Notifications
You must be signed in to change notification settings - Fork 26
/
deprecations.test.ts
55 lines (49 loc) · 1.75 KB
/
deprecations.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
import { URL } from "url";
import * as nodeFetch from "node-fetch";
import fromEntries from "fromentries";
import { createCloudflareHandler, OAuthApp } from "../src";
import { Octokit } from "@octokit/core";
describe("deprecations", () => {
beforeAll(() => {
Object.fromEntries ||= fromEntries;
(global as any).Request = nodeFetch.Request;
(global as any).Response = nodeFetch.Response;
});
afterAll(() => {
delete (global as any).Request;
delete (global as any).Response;
});
it("createCloudflareHandler works but logs out deprecation message", async () => {
const warn = jest.fn().mockResolvedValue(undefined);
const handleRequest = createCloudflareHandler(
new OAuthApp({
clientType: "github-app",
clientId: "client_id_123",
clientSecret: "client_secret_456",
Octokit: Octokit.defaults({
log: {
debug: () => undefined,
info: () => undefined,
warn,
error: () => undefined,
},
}),
})
);
expect(warn.mock.calls.length).toEqual(1);
expect(warn.mock.calls[0][0]).toEqual(
"[@octokit/oauth-app] `createCloudflareHandler` is deprecated, use `createWebWorkerHandler` instead"
);
const request = new Request("/api/github/oauth/login");
const { status, headers } = await handleRequest(request);
expect(status).toEqual(302);
const url = new URL(headers.get("location") as string);
expect(url).toMatchObject({
origin: "https://github.com",
pathname: "/login/oauth/authorize",
});
expect(url.searchParams.get("client_id")).toEqual("client_id_123");
expect(url.searchParams.get("state")).toMatch(/^\w+$/);
expect(url.searchParams.get("scope")).toEqual(null);
});
});