Skip to content

Commit

Permalink
Merge pull request #165 from nada-deriv/nada/FEQ-2397/is-advertiser-b…
Browse files Browse the repository at this point in the history
…arred

Nada/FEQ 2397/is advertiser barred + sendbirdservice token
  • Loading branch information
farrah-deriv authored Jun 26, 2024
2 parents 30bfef8 + ab128bc commit 7cd309b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts
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 src/hooks/custom-hooks/__tests__/useIsAdvertiserBarred.spec.ts
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);
});
});

0 comments on commit 7cd309b

Please sign in to comment.