mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 10:02:27 -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
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
jest.mock('shared/supabase/init')
|
|
|
|
import * as freeLikeModule from 'api/has-free-like'
|
|
import {AuthedUser} from 'api/helpers/endpoint'
|
|
import * as supabaseInit from 'shared/supabase/init'
|
|
|
|
describe('hasFreeLike', () => {
|
|
let mockPg = {} as any
|
|
beforeEach(() => {
|
|
jest.resetAllMocks()
|
|
mockPg = {
|
|
oneOrNone: jest.fn(),
|
|
}
|
|
;(supabaseInit.createSupabaseDirectClient as jest.Mock).mockReturnValue(mockPg)
|
|
})
|
|
afterEach(() => {
|
|
jest.restoreAllMocks()
|
|
})
|
|
|
|
describe('when given valid input', () => {
|
|
it('should return if the user has a free like', async () => {
|
|
const mockAuth = {uid: '321'} as AuthedUser
|
|
const mockReq = {} as any
|
|
const mockProps = {} as any
|
|
|
|
jest.spyOn(freeLikeModule, 'getHasFreeLike')
|
|
;(mockPg.oneOrNone as jest.Mock).mockResolvedValue(false)
|
|
|
|
const result: any = await freeLikeModule.hasFreeLike(mockProps, mockAuth, mockReq)
|
|
|
|
expect(result.status).toBe('success')
|
|
expect(result.hasFreeLike).toBeTruthy()
|
|
expect(freeLikeModule.getHasFreeLike).toBeCalledTimes(1)
|
|
expect(freeLikeModule.getHasFreeLike).toBeCalledWith(mockAuth.uid)
|
|
expect(mockPg.oneOrNone).toBeCalledTimes(1)
|
|
expect(mockPg.oneOrNone).toBeCalledWith(expect.stringContaining('from profile_likes'), [
|
|
mockAuth.uid,
|
|
])
|
|
})
|
|
|
|
it('should return if the user does not have a free like', async () => {
|
|
const mockAuth = {uid: '321'} as AuthedUser
|
|
const mockReq = {} as any
|
|
const mockProps = {} as any
|
|
|
|
jest.spyOn(freeLikeModule, 'getHasFreeLike')
|
|
;(mockPg.oneOrNone as jest.Mock).mockResolvedValue(true)
|
|
|
|
const result: any = await freeLikeModule.hasFreeLike(mockProps, mockAuth, mockReq)
|
|
|
|
expect(result.hasFreeLike).toBeFalsy()
|
|
})
|
|
})
|
|
})
|