-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscope-token.test.ts
128 lines (122 loc) · 3.3 KB
/
scope-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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { describe, expect, it } from "vitest";
import fetchMock from "fetch-mock";
import { request } from "@octokit/request";
import { scopeToken } from "../src/index.js";
describe("scopeToken()", () => {
it("README example", async () => {
const mock = fetchMock.sandbox().postOnce(
"https://api.github.com/applications/lv1.1234567890abcdef/token/scoped",
{
account: {
login: "octokit",
id: 1,
},
token: "usertoken456",
},
{
headers: {
accept: "application/vnd.github.v3+json",
"user-agent": "test",
authorization:
"basic bHYxLjEyMzQ1Njc4OTBhYmNkZWY6MTIzNDU2Nzg5MGFiY2RlZjEyMzQ3ODkwYWJjZGVmMTIzNDU2Nzg=",
"content-type": "application/json; charset=utf-8",
},
body: {
access_token: "usertoken123",
target: "octokit",
repositories: ["oauth-methods.js"],
permissions: { issues: "write" },
},
},
);
const { data, authentication } = await scopeToken({
clientType: "github-app",
clientId: "lv1.1234567890abcdef",
clientSecret: "1234567890abcdef12347890abcdef12345678",
token: "usertoken123",
target: "octokit",
repositories: ["oauth-methods.js"],
permissions: {
issues: "write",
},
request: request.defaults({
headers: {
"user-agent": "test",
},
request: {
fetch: mock,
},
}),
});
expect(data).toMatchInlineSnapshot(`
{
"account": {
"id": 1,
"login": "octokit",
},
"token": "usertoken456",
}
`);
expect(authentication).toMatchInlineSnapshot(`
{
"clientId": "lv1.1234567890abcdef",
"clientSecret": "1234567890abcdef12347890abcdef12345678",
"clientType": "github-app",
"token": "usertoken456",
}
`);
});
it("passes `expires_at` through", async () => {
const mock = fetchMock
.sandbox()
.postOnce(
"https://api.github.com/applications/lv1.1234567890abcdef/token/scoped",
{
account: {
login: "octokit",
id: 1,
},
expires_at: "2021-10-06T17:26:27Z",
token: "usertoken456",
},
);
const { data, authentication } = await scopeToken({
clientType: "github-app",
clientId: "lv1.1234567890abcdef",
clientSecret: "1234567890abcdef12347890abcdef12345678",
token: "usertoken123",
target: "octokit",
repositories: ["oauth-methods.js"],
permissions: {
issues: "write",
},
request: request.defaults({
headers: {
"user-agent": "test",
},
request: {
fetch: mock,
},
}),
});
expect(data).toMatchInlineSnapshot(`
{
"account": {
"id": 1,
"login": "octokit",
},
"expires_at": "2021-10-06T17:26:27Z",
"token": "usertoken456",
}
`);
expect(authentication).toMatchInlineSnapshot(`
{
"clientId": "lv1.1234567890abcdef",
"clientSecret": "1234567890abcdef12347890abcdef12345678",
"clientType": "github-app",
"expiresAt": "2021-10-06T17:26:27Z",
"token": "usertoken456",
}
`);
});
});