Skip to content

Commit

Permalink
Add onSuccess test
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulAsjes committed Dec 27, 2024
1 parent 8b3dbcc commit b06e771
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions __tests__/authkit-callback-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,30 @@ describe('authkit-callback-route', () => {

expect(response.status).toBe(500);
});

it('should call onSuccess if provided', async () => {
const mockAuthResponse = {
accessToken: 'access123',
refreshToken: 'refresh123',
user: { id: 'user_123' },
oauthTokens: {
access_token: 'access123',
refresh_token: 'refresh123',
expires_at: 1719811200,
scopes: ['foo', 'bar'],
},
};

(workos.userManagement.authenticateWithCode as jest.Mock).mockResolvedValue(mockAuthResponse);

// Set up request with code
request.nextUrl.searchParams.set('code', 'test-code');

const onSuccess = jest.fn();
const handler = handleAuth({ onSuccess: onSuccess });
await handler(request);

expect(onSuccess).toHaveBeenCalledWith(mockAuthResponse);
});
});
});

0 comments on commit b06e771

Please sign in to comment.