Skip to content

Commit 7440204

Browse files
authored
test: add getOctokit integration tests for multi-token usage
Verifies the real getOctokit from @actions/github creates functional Octokit clients when invoked through callAsyncFunction, ensuring: - Secondary clients have full REST/GraphQL API surface - Secondary clients are independent from primary github client - GHES base URL option is accepted - Multiple tokens produce distinct client instances
1 parent 2fe016f commit 7440204

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
3+
import {getOctokit} from '@actions/github'
4+
import {callAsyncFunction} from '../src/async-function'
5+
6+
describe('getOctokit integration via callAsyncFunction', () => {
7+
test('real getOctokit creates a functional Octokit client in script scope', async () => {
8+
const result = await callAsyncFunction(
9+
{getOctokit} as any,
10+
`
11+
const client = getOctokit('fake-token-for-test')
12+
return {
13+
hasRest: typeof client.rest === 'object',
14+
hasGraphql: typeof client.graphql === 'function',
15+
hasRequest: typeof client.request === 'function',
16+
hasIssues: typeof client.rest.issues === 'object',
17+
hasPulls: typeof client.rest.pulls === 'object'
18+
}
19+
`
20+
)
21+
22+
expect(result).toEqual({
23+
hasRest: true,
24+
hasGraphql: true,
25+
hasRequest: true,
26+
hasIssues: true,
27+
hasPulls: true
28+
})
29+
})
30+
31+
test('secondary client is independent from primary github client', async () => {
32+
const primary = getOctokit('primary-token')
33+
34+
const result = await callAsyncFunction(
35+
{github: primary, getOctokit} as any,
36+
`
37+
const secondary = getOctokit('secondary-token')
38+
return {
39+
bothHaveRest: typeof github.rest === 'object' && typeof secondary.rest === 'object',
40+
areDistinct: github !== secondary
41+
}
42+
`
43+
)
44+
45+
expect(result).toEqual({
46+
bothHaveRest: true,
47+
areDistinct: true
48+
})
49+
})
50+
51+
test('getOctokit accepts options for GHES base URL', async () => {
52+
const result = await callAsyncFunction(
53+
{getOctokit} as any,
54+
`
55+
const client = getOctokit('fake-token', {
56+
baseUrl: 'https://ghes.example.com/api/v3'
57+
})
58+
return typeof client.rest === 'object'
59+
`
60+
)
61+
62+
expect(result).toBe(true)
63+
})
64+
65+
test('multiple getOctokit calls produce independent clients with different tokens', async () => {
66+
const result = await callAsyncFunction(
67+
{getOctokit} as any,
68+
`
69+
const clientA = getOctokit('token-a')
70+
const clientB = getOctokit('token-b')
71+
return {
72+
aHasRest: typeof clientA.rest === 'object',
73+
bHasRest: typeof clientB.rest === 'object',
74+
areDistinct: clientA !== clientB
75+
}
76+
`
77+
)
78+
79+
expect(result).toEqual({
80+
aHasRest: true,
81+
bHasRest: true,
82+
areDistinct: true
83+
})
84+
})
85+
})

0 commit comments

Comments
 (0)