mirror of
https://github.com/supabase/supabase.git
synced 2026-05-14 14:49:37 +08:00
Use getClaims instead of getUser which avoids a network call to GoTrue to validate the user in case of asymmetric keys - this shaves off a good amount of latency for every API call.
32 lines
836 B
TypeScript
32 lines
836 B
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import apiWrapper from './apiWrapper'
|
|
import { apiAuthenticate } from './apiAuthenticate'
|
|
|
|
vi.mock('lib/constants', () => ({
|
|
IS_PLATFORM: true,
|
|
API_URL: 'https://api.example.com',
|
|
}))
|
|
|
|
vi.mock('./apiAuthenticate', () => ({
|
|
apiAuthenticate: vi.fn(),
|
|
}))
|
|
|
|
describe('apiWrapper', () => {
|
|
const mockReq = {} as any
|
|
const mockRes = {
|
|
status: vi.fn().mockReturnThis(),
|
|
json: vi.fn().mockReturnThis(),
|
|
} as any
|
|
const mockHandler = vi.fn()
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('should call handler directly when withAuth is false', async () => {
|
|
await apiWrapper(mockReq, mockRes, mockHandler, { withAuth: false })
|
|
expect(mockHandler).toHaveBeenCalledWith(mockReq, mockRes)
|
|
expect(apiAuthenticate).not.toHaveBeenCalled()
|
|
})
|
|
})
|