Files
Compass/backend/api/tests/unit/get-profile-answers.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

52 lines
1.5 KiB
TypeScript

import {getProfileAnswers} from 'api/get-profile-answers'
import {AuthedUser} from 'api/helpers/endpoint'
import {sqlMatch} from 'common/test-utils'
import * as supabaseInit from 'shared/supabase/init'
jest.mock('shared/supabase/init')
describe('getProfileAnswers', () => {
let mockPg = {} as any
beforeEach(() => {
jest.resetAllMocks()
mockPg = {
manyOrNone: jest.fn(),
}
;(supabaseInit.createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg)
})
afterEach(() => {
jest.restoreAllMocks()
})
describe('when given valid input', () => {
it('should get the answers for the userId', async () => {
const mockProps = {userId: 'mockUserId'}
const mockAuth = {uid: '321'} as AuthedUser
const mockReq = {} as any
const mockAnswers = [
{
created_time: 'mockCreatedTime',
creator_id: 'mockCreatorId',
explanation: 'mockExplanation',
id: 123,
importance: 10,
multiple_choice: 1234,
pref_choices: [1, 2, 3],
question_id: 12345,
},
]
;(mockPg.manyOrNone as jest.Mock).mockResolvedValue(mockAnswers)
const result: any = await getProfileAnswers(mockProps, mockAuth, mockReq)
expect(result.status).toBe('success')
expect(result.answers).toBe(mockAnswers)
expect(mockPg.manyOrNone).toBeCalledTimes(1)
expect(mockPg.manyOrNone).toBeCalledWith(sqlMatch('select * from compatibility_answers'), [
mockProps.userId,
])
})
})
})