Files
supabase/apps/studio/lib/configcat.test.ts
T
Jordi EnricandJoshen Lim 6e91494b16 Add coveralls integration (#35424)
* 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>
2025-05-08 12:23:37 +02:00

40 lines
1.0 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import * as configcat from 'configcat-js'
import { getFlags } from './configcat'
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 result = await getFlags(email)
expect(configcat.User).toHaveBeenCalledWith(email)
expect(mockClient.getAllValuesAsync).toHaveBeenCalled()
expect(result).toEqual(mockValues)
})
})