From 467121c3f43000f4c40940a58df3c3dfc902de63 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Fri, 25 Oct 2024 00:24:30 +0530 Subject: [PATCH] Fix/remove skipped test cases (#472) * fix(skipped testcase): remove skipped testcases and updated testcases for utils * test: removed skip from testcases in util tests * test: updated mock api error message --- __tests__/Util-test.ts | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/__tests__/Util-test.ts b/__tests__/Util-test.ts index 9e1077cc..4be2cb21 100644 --- a/__tests__/Util-test.ts +++ b/__tests__/Util-test.ts @@ -17,6 +17,7 @@ const mockedAxios = axios as jest.Mocked; describe('getUserData util', () => { const token = '12345421ac1aca'; + const invalidToken = 'a1b9c2d8x3y7z4'; const mockUserData = { id: '123abc', @@ -29,12 +30,31 @@ describe('getUserData util', () => { username: 'anish-pawaskar', }; - test.skip('when url passed !== redirect url return null', async () => { - const res = await getUserData('https://www.example.net/'); - expect(res).toEqual(null); + test('when token passed is invalid, axios call returns with 401', async () => { + const errorResponse = { + response: { + status: 401, + data: { + message: 'Unauthenticated User', + }, + }, + }; + mockedAxios.get.mockRejectedValue(errorResponse); + try { + await getUserData(invalidToken); + } catch (err) { + expect(err).toEqual({ + response: { + status: 401, + data: { + message: 'Unauthenticated User', + }, + }, + }); + } }); - test('when redirect url is passed to getUserData && axios call is ok return user name & profileUrl', async () => { + test('when token is passed to getUserData && axios call is ok return user name & profileUrl', async () => { mockedAxios.get.mockResolvedValue({ data: mockUserData }); const res = await getUserData(token); expect(mockedAxios.get).toHaveBeenCalledWith(`${urls.GET_USERS_DATA}`, { @@ -55,17 +75,17 @@ describe('getUserData util', () => { }); }); - test('when redirect url is passed to getUserData && axios call fails return null', async () => { + test('when token is passed to getUserData && axios call fails return null', async () => { mockedAxios.get.mockRejectedValue('500: server error'); try { - await getUserData(urls.REDIRECT_URL); + await getUserData(token); } catch (err) { expect(err).toEqual('500: server error'); } }); }); -describe.skip('updateStatus util', () => { +describe('updateStatus util', () => { test('pass arg undefined receive throw error', async () => { mockedAxios.patch.mockRejectedValue( // eslint-disable-next-line quotes @@ -104,7 +124,7 @@ describe.skip('updateStatus util', () => { }); }); -describe.skip('updateMarkYourSelfAs_ util', () => { +describe('updateMarkYourSelfAs_ util', () => { test('pass arg undefined receive throw error', async () => { mockedAxios.patch.mockRejectedValue( // eslint-disable-next-line quotes