Skip to content

Commit 4649033

Browse files
committed
fix(oauth): update Notion test to match Basic Auth + JSON body config
1 parent 6a9b878 commit 4649033

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

apps/sim/lib/oauth/oauth.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ describe('OAuth Token Refresh', () => {
180180
providerId: 'outlook',
181181
endpoint: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
182182
},
183-
{ name: 'Notion', providerId: 'notion', endpoint: 'https://api.notion.com/v1/oauth/token' },
184183
{ name: 'Slack', providerId: 'slack', endpoint: 'https://slack.com/api/oauth.v2.access' },
185184
{
186185
name: 'Dropbox',
@@ -274,6 +273,44 @@ describe('OAuth Token Refresh', () => {
274273
)
275274
})
276275

276+
it.concurrent('should send Notion request with Basic Auth header and JSON body', async () => {
277+
const mockFetch = createMockFetch(defaultOAuthResponse)
278+
const refreshToken = 'test_refresh_token'
279+
280+
await withMockFetch(mockFetch, () => refreshOAuthToken('notion', refreshToken))
281+
282+
expect(mockFetch).toHaveBeenCalledWith(
283+
'https://api.notion.com/v1/oauth/token',
284+
expect.objectContaining({
285+
method: 'POST',
286+
headers: expect.objectContaining({
287+
'Content-Type': 'application/json',
288+
Authorization: expect.stringMatching(/^Basic /),
289+
}),
290+
body: expect.any(String),
291+
})
292+
)
293+
294+
const [, requestOptions] = mockFetch.mock.calls[0] as [
295+
string,
296+
{ headers: Record<string, string>; body: string },
297+
]
298+
299+
const authHeader = requestOptions.headers.Authorization
300+
const base64Credentials = authHeader.replace('Basic ', '')
301+
const credentials = Buffer.from(base64Credentials, 'base64').toString('utf-8')
302+
const [clientId, clientSecret] = credentials.split(':')
303+
304+
expect(clientId).toBe('notion_client_id')
305+
expect(clientSecret).toBe('notion_client_secret')
306+
307+
const bodyParams = JSON.parse(requestOptions.body)
308+
expect(bodyParams).toEqual({
309+
grant_type: 'refresh_token',
310+
refresh_token: refreshToken,
311+
})
312+
})
313+
277314
it.concurrent('should include User-Agent header for Reddit requests', async () => {
278315
const mockFetch = createMockFetch(defaultOAuthResponse)
279316
const refreshToken = 'test_refresh_token'

0 commit comments

Comments
 (0)