mirror of
https://github.com/supabase/supabase.git
synced 2026-05-23 10:21:37 +08:00
* update gh action, update vitest config * debug * debug cov * idk try something different * test2 * test3 * add base path * rm debug * add apiAuthenticate tests * supabaseClient tests * apiWrappers tests * add apiHelpers tests * add configcat tests * add formatSql tests * add github tests * add cloudprovider utils tests * add helpers tests * fix typeerr * add missing readonly err * fix typeerrrs * fix type errors in apiWrapper tests * fix apiHelpers test * add packages/ui tests * add coveralls flags * try coveralls parallel config * fix coveralls parallel config --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
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()
|
|
})
|
|
|
|
it('should attach user to request and call handler when authentication succeeds', async () => {
|
|
const mockUser = { id: '123', email: 'test@example.com' } as any as any
|
|
vi.mocked(apiAuthenticate).mockResolvedValue(mockUser)
|
|
|
|
await apiWrapper(mockReq, mockRes, mockHandler, { withAuth: true })
|
|
|
|
expect(mockReq.user).toEqual(mockUser)
|
|
expect(mockHandler).toHaveBeenCalledWith(mockReq, mockRes)
|
|
})
|
|
})
|