Files
Compass/backend/api/tests/unit/compatible-profiles.unit.test.ts
Martin Braquet ba9b3cfb06 Add pretty formatting (#29)
* Test

* Add pretty formatting

* Fix Tests

* Fix Tests

* Fix Tests

* Fix

* Add pretty formatting fix

* Fix

* Test

* Fix tests

* Clean typeckech

* Add prettier check

* Fix api tsconfig

* Fix api tsconfig

* Fix tsconfig

* Fix

* Fix

* Prettier
2026-02-20 17:32:27 +01:00

40 lines
1.3 KiB
TypeScript

jest.mock('shared/supabase/init')
import {getCompatibleProfiles} from 'api/compatible-profiles'
import * as supabaseInit from 'shared/supabase/init'
describe('getCompatibleProfiles', () => {
let mockPg = {} as any
beforeEach(() => {
jest.resetAllMocks()
mockPg = {
map: jest.fn().mockResolvedValue([]),
}
;(supabaseInit.createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg)
})
afterEach(() => {
jest.restoreAllMocks()
})
describe('when given valid input', () => {
it('should successfully get compatible profiles', async () => {
const mockProps = '123'
const mockScores = ['abc', {score: 0.69}]
const mockScoresFromEntries = {abc: {score: 0.69}}
;(mockPg.map as jest.Mock).mockResolvedValue([mockScores])
const results = await getCompatibleProfiles(mockProps)
const [sql, param, fn] = mockPg.map.mock.calls[0]
expect(results.status).toEqual('success')
expect(results.profileCompatibilityScores).toEqual(mockScoresFromEntries)
expect(mockPg.map).toBeCalledTimes(1)
expect(sql).toContain('select *')
expect(sql).toContain('from compatibility_scores')
expect(param).toStrictEqual([mockProps])
expect(fn).toEqual(expect.any(Function))
})
})
})