-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrefresh-token.test.ts
75 lines (72 loc) · 2.12 KB
/
refresh-token.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { describe, expect, it } from "vitest";
import fetchMock from "fetch-mock";
import { request } from "@octokit/request";
import { refreshToken } from "../src/index.js";
describe("refreshToken()", () => {
it("README example", async () => {
const mock = fetchMock.sandbox().postOnce(
"https://github.com/login/oauth/access_token",
{
body: {
access_token: "secret456",
scope: "",
token_type: "bearer",
expires_in: 28800,
refresh_token: "r1.token456",
refresh_token_expires_in: 15897600,
},
headers: {
date: "Thu, 1 Jan 1970 00:00:00 GMT",
},
},
{
headers: {
accept: "application/json",
"user-agent": "test",
"content-type": "application/json; charset=utf-8",
},
body: {
client_id: "lv1.1234567890abcdef",
client_secret: "1234567890abcdef12347890abcdef12345678",
grant_type: "refresh_token",
refresh_token: "r1.refreshtoken123",
},
},
);
const { data, authentication } = await refreshToken({
clientType: "github-app",
clientId: "lv1.1234567890abcdef",
clientSecret: "1234567890abcdef12347890abcdef12345678",
refreshToken: "r1.refreshtoken123",
request: request.defaults({
headers: {
"user-agent": "test",
},
request: {
fetch: mock,
},
}),
});
expect(data).toMatchInlineSnapshot(`
{
"access_token": "secret456",
"expires_in": 28800,
"refresh_token": "r1.token456",
"refresh_token_expires_in": 15897600,
"scope": "",
"token_type": "bearer",
}
`);
expect(authentication).toMatchInlineSnapshot(`
{
"clientId": "lv1.1234567890abcdef",
"clientSecret": "1234567890abcdef12347890abcdef12345678",
"clientType": "github-app",
"expiresAt": "1970-01-01T08:00:00.000Z",
"refreshToken": "r1.token456",
"refreshTokenExpiresAt": "1970-07-04T00:00:00.000Z",
"token": "secret456",
}
`);
});
});