|
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(() => { |
@@ -180,21 +182,19 @@ describe('Monday OAuth connector', () => { |
180 | 182 | redirectURI: 'http://localhost:3000/api/auth/oauth2/callback/monday', |
181 | 183 | authorizationUrlParams: { force_install_if_needed: 'true' }, |
182 | 184 | }) |
183 | | - const authorizationUrl = await createAuthorizationURL({ |
184 | | - id: connector.providerId, |
185 | | - options: { |
186 | | - clientId: connector.clientId, |
187 | | - clientSecret: connector.clientSecret, |
188 | | - 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', |
189 | 194 | }, |
190 | | - authorizationEndpoint: connector.authorizationUrl!, |
191 | | - state: 'state-1', |
192 | | - codeVerifier: 'a'.repeat(128), |
193 | | - scopes: connector.scopes, |
194 | | - redirectURI: connector.redirectURI!, |
195 | | - responseType: connector.responseType, |
196 | | - additionalParams: connector.authorizationUrlParams, |
| 195 | + headers, |
197 | 196 | }) |
| 197 | + const authorizationUrl = new URL(url) |
198 | 198 |
|
199 | 199 | expect(authorizationUrl.searchParams.get('redirect_uri')).toBe( |
200 | 200 | 'http://localhost:3000/api/auth/oauth2/callback/monday' |
|
0 commit comments