-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from nada-deriv/nada/FEQ-2397/is-advertiser-b…
…arred Nada/FEQ 2397/is advertiser barred + sendbirdservice token
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useGetSettings, useServiceToken } from '@deriv-com/api-hooks'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useSendbirdServiceToken } from '..'; | ||
|
||
jest.mock('@deriv-com/api-hooks', () => ({ | ||
useGetSettings: jest.fn(() => ({ isSuccess: true })), | ||
useServiceToken: jest.fn(() => ({})), | ||
})); | ||
|
||
describe('useSendbirdServiceToken', () => { | ||
it('should return a service token', async () => { | ||
(useServiceToken as jest.Mock).mockReturnValueOnce({ | ||
data: { | ||
sendbird: { | ||
app_id: 'A123-456-789', | ||
expiry_time: 1234567890, | ||
token: '0123445678901234567890', | ||
}, | ||
}, | ||
}); | ||
const { result } = renderHook(() => useSendbirdServiceToken()); | ||
expect(result.current.data?.app_id).toBe('A123-456-789'); | ||
}); | ||
|
||
it('should return undefined if isSuccess is false', async () => { | ||
(useGetSettings as jest.Mock).mockReturnValue({ isSuccess: false }); | ||
const { result } = renderHook(() => useSendbirdServiceToken()); | ||
expect(result.current.data).toBeUndefined(); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/hooks/custom-hooks/__tests__/useIsAdvertiserBarred.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { api } from '@/hooks'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useIsAdvertiserBarred } from '..'; | ||
|
||
jest.mock('@/hooks', () => ({ | ||
api: { | ||
advertiser: { | ||
useGetInfo: jest.fn().mockReturnValue({ data: {} }), | ||
}, | ||
}, | ||
})); | ||
|
||
const mockUseGetInfo = api.advertiser.useGetInfo as jest.Mock; | ||
|
||
describe('useIsAdvertiserBarred', () => { | ||
it('should return false if the user is not barred', () => { | ||
const { result } = renderHook(() => useIsAdvertiserBarred()); | ||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it('should return true if the user is barred', () => { | ||
mockUseGetInfo.mockReturnValue({ data: { blocked_until: 123456789 } }); | ||
|
||
const { result } = renderHook(() => useIsAdvertiserBarred()); | ||
expect(result.current).toBe(true); | ||
}); | ||
}); |