mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-29 12:04:04 -04:00
* 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
52 lines
1.5 KiB
TypeScript
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,
|
|
])
|
|
})
|
|
})
|
|
})
|