|
1 | 1 | import { createMockFetch, resetEnvMock, setEnv } from '@sim/testing' |
2 | | -import { createAuthorizationURL, getOAuth2Tokens } from 'better-auth/oauth2' |
| 2 | +import { getOAuth2Tokens } from 'better-auth/oauth2' |
| 3 | +import { genericOAuth } from 'better-auth/plugins' |
| 4 | +import { getTestInstance } from 'better-auth/test' |
3 | 5 | import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' |
4 | 6 |
|
5 | 7 | beforeAll(() => { |
@@ -178,26 +180,27 @@ describe('Monday OAuth connector', () => { |
178 | 180 | pkce: true, |
179 | 181 | authentication: 'post', |
180 | 182 | redirectURI: 'http://localhost:3000/api/auth/oauth2/callback/monday', |
| 183 | + authorizationUrlParams: { force_install_if_needed: 'true' }, |
181 | 184 | }) |
182 | | - const authorizationUrl = await createAuthorizationURL({ |
183 | | - id: connector.providerId, |
184 | | - options: { |
185 | | - clientId: connector.clientId, |
186 | | - clientSecret: connector.clientSecret, |
187 | | - redirectURI: connector.redirectURI, |
| 185 | + const { auth, signInWithTestUser } = await getTestInstance({ |
| 186 | + baseURL: 'http://localhost:3000', |
| 187 | + plugins: [genericOAuth({ config: [connector] })], |
| 188 | + }) |
| 189 | + const { headers } = await signInWithTestUser() |
| 190 | + const { url } = await auth.api.oAuth2LinkAccount({ |
| 191 | + body: { |
| 192 | + providerId: connector.providerId, |
| 193 | + callbackURL: 'http://localhost:3000/workspace', |
188 | 194 | }, |
189 | | - authorizationEndpoint: connector.authorizationUrl!, |
190 | | - state: 'state-1', |
191 | | - codeVerifier: 'a'.repeat(128), |
192 | | - scopes: connector.scopes, |
193 | | - redirectURI: connector.redirectURI!, |
194 | | - responseType: connector.responseType, |
| 195 | + headers, |
195 | 196 | }) |
| 197 | + const authorizationUrl = new URL(url) |
196 | 198 |
|
197 | 199 | expect(authorizationUrl.searchParams.get('redirect_uri')).toBe( |
198 | 200 | 'http://localhost:3000/api/auth/oauth2/callback/monday' |
199 | 201 | ) |
200 | 202 | expect(authorizationUrl.searchParams.get('scope')).toBe(connector.scopes?.join(' ')) |
| 203 | + expect(authorizationUrl.searchParams.get('force_install_if_needed')).toBe('true') |
201 | 204 | expect(authorizationUrl.searchParams.get('code_challenge_method')).toBe('S256') |
202 | 205 | expect(authorizationUrl.searchParams.get('code_challenge')).toBeTruthy() |
203 | 206 | }) |
|
0 commit comments