mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
Sorted all imports in all packages, `cms`, `design-system` and `ui-library` apps by running `pnpm format` on them. All changes in this PR are done by the script.
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import * as configcat from 'configcat-js'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { getFlags } from './configcat'
|
|
|
|
vi.mock('data/fetchers', () => ({
|
|
fetchHandler: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('configcat-js', () => ({
|
|
getClient: vi.fn(),
|
|
PollingMode: {
|
|
AutoPoll: 'AutoPoll',
|
|
},
|
|
User: vi.fn(),
|
|
}))
|
|
|
|
describe('configcat', () => {
|
|
const mockClient = {
|
|
getAllValuesAsync: vi.fn(),
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
;(configcat.getClient as any).mockReturnValue(mockClient)
|
|
})
|
|
|
|
it('should return empty array when no email is provided', async () => {
|
|
const result = await getFlags()
|
|
expect(result).toEqual([])
|
|
})
|
|
|
|
it('should call getAllValuesAsync with user when email is provided', async () => {
|
|
const email = 'test@example.com'
|
|
const mockValues = { flag1: true, flag2: false }
|
|
mockClient.getAllValuesAsync.mockResolvedValue(mockValues)
|
|
|
|
const { fetchHandler } = await import('./configcat')
|
|
const mockFetchHandler = fetchHandler as unknown as ReturnType<typeof vi.fn>
|
|
mockFetchHandler.mockResolvedValueOnce(
|
|
new Response(JSON.stringify({}), {
|
|
status: 200,
|
|
})
|
|
)
|
|
|
|
const result = await getFlags(email)
|
|
|
|
expect(configcat.User).toHaveBeenCalledWith(email)
|
|
expect(mockClient.getAllValuesAsync).toHaveBeenCalled()
|
|
expect(result).toEqual(mockValues)
|
|
})
|
|
})
|