UNPKG

@telstra/messaging

Version:
77 lines (68 loc) 3.04 kB
import { AssertionError } from '@telstra/core'; import { VirtualNumbers } from '../../../src/classes/index.js'; import { Constants } from '../../shared/Constants.js'; import AUTH_CONFIG from '../../shared/credentials.json' with { type: 'json' }; import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest'; import { server } from '../../shared/mswServer.js'; beforeAll(() => server.listen()); afterEach(() => server.resetHandlers()); afterAll(() => server.close()); describe('VirtualNumber', () => { const virtualNumbers = new VirtualNumbers(AUTH_CONFIG); describe('assign a virtualNumber', () => { describe('when the client sends a valid request', () => { it('should pass', async () => { await expect(virtualNumbers.assign()).resolves.toEqual(Constants.ASSIGN_VIRTUAL_NUMBER_RESPONSE); }); }); }); describe('get all virtualNumbers', () => { describe('when the client sends a valid request', () => { it('should pass', async () => { await expect(virtualNumbers.getAll()).resolves.toEqual(Constants.GET_ALL_VIRTUAL_NUMBERS_RESPONSE); }); }); describe('when the client sends a valid request - with params', () => { it('should pass', async () => { const data = { limit: 5, offset: 0 }; await expect(virtualNumbers.getAll(data)).resolves.toEqual(Constants.GET_ALL_VIRTUAL_NUMBERS_RESPONSE); }); }); describe('when the client sends [limit] as string', () => { it('should throw an assertion error', async () => { const data = { limit: '5', offset: 0 } as any; const callback = async () => virtualNumbers.getAll(data); await expect(callback).rejects.toThrow(AssertionError); }); }); describe('when the client sends [offset] as string', () => { it('should throw an assertion error', async () => { const data = { limit: 5, offset: '0' } as any; const callback = async () => virtualNumbers.getAll(data); await expect(callback).rejects.toThrow(AssertionError); }); }); describe('when the client sends [filter] as integer', () => { it('should throw an assertion error', async () => { const data = { limit: 5, offset: 0, filter: 412345678 } as any; const callback = async () => virtualNumbers.getAll(data); await expect(callback).rejects.toThrow(AssertionError); }); }); }); describe('get a virtualNumber', () => { describe('when the client sends a valid request', () => { it('should pass', async () => { await expect(virtualNumbers.get('0412345678')).resolves.toEqual( Constants.GET_ALL_VIRTUAL_NUMBERS_RESPONSE.virtualNumbers[0], ); }); }); describe('when the client sends [virtualNumber] as integer', () => { it('should throw an assertion error', async () => { const callback = async () => virtualNumbers.get(412345678 as any); await expect(callback).rejects.toThrow(AssertionError); }); }); }); });