From d61c8d13e1540b211957ef3ed0b31449ec73b02a Mon Sep 17 00:00:00 2001 From: Nada Date: Tue, 25 Jun 2024 10:20:40 +0400 Subject: [PATCH 1/2] chore: add unit test for useisadvertiserbarred --- .../__tests__/useSendbirdServiceToken.spec.ts | 0 .../__tests__/useIsAdvertiserBarred.spec.ts | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts create mode 100644 src/hooks/custom-hooks/__tests__/useIsAdvertiserBarred.spec.ts diff --git a/src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts b/src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/hooks/custom-hooks/__tests__/useIsAdvertiserBarred.spec.ts b/src/hooks/custom-hooks/__tests__/useIsAdvertiserBarred.spec.ts new file mode 100644 index 00000000..6e1c1a25 --- /dev/null +++ b/src/hooks/custom-hooks/__tests__/useIsAdvertiserBarred.spec.ts @@ -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); + }); +}); From d21fdd526b04612cd2d4e8c9ad96bcbae0ab5575 Mon Sep 17 00:00:00 2001 From: Nada Date: Tue, 25 Jun 2024 10:35:48 +0400 Subject: [PATCH 2/2] chore: add unit tests for sendbird service token --- .../__tests__/useSendbirdServiceToken.spec.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts b/src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts index e69de29b..349bf5a4 100644 --- a/src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts +++ b/src/hooks/api/account/__tests__/useSendbirdServiceToken.spec.ts @@ -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(); + }); +});