From f8a69f070b77009097cdbe2b2657bd419994f615 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com>
Date: Wed, 4 Oct 2023 17:08:31 +0800
Subject: [PATCH] feat(drugs tests): replaced constants with axios http
 response

---
 src/constants/httpResponses.ts         | 2 --
 src/redux/drugs/drugs.reducers.test.ts | 8 ++++----
 src/redux/drugs/drugs.thunks.test.ts   | 6 +++---
 3 files changed, 7 insertions(+), 9 deletions(-)
 delete mode 100644 src/constants/httpResponses.ts

diff --git a/src/constants/httpResponses.ts b/src/constants/httpResponses.ts
deleted file mode 100644
index e017a787..00000000
--- a/src/constants/httpResponses.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export const HTTP_OK = 200;
-export const HTTP_NOT_FOUND = 404;
diff --git a/src/redux/drugs/drugs.reducers.test.ts b/src/redux/drugs/drugs.reducers.test.ts
index d62b3a1e..4bf96500 100644
--- a/src/redux/drugs/drugs.reducers.test.ts
+++ b/src/redux/drugs/drugs.reducers.test.ts
@@ -1,6 +1,6 @@
+import { HttpStatusCode } from 'axios';
 import { PROJECT_ID } from '@/constants/mapId';
 import { drugsFixture } from '@/models/fixtures/drugFixtures';
-import { HTTP_NOT_FOUND, HTTP_OK } from '@/constants/httpResponses';
 import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
 import {
   ToolkitStoreWithSingleSlice,
@@ -33,7 +33,7 @@ describe('drugs reducer', () => {
   it('should update store after succesfull getDrugs query', async () => {
     mockedAxiosClient
       .onGet(`projects/${PROJECT_ID}/drugs:search?query=${SEARCH_QUERY}`)
-      .reply(HTTP_OK, drugsFixture);
+      .reply(HttpStatusCode.Ok, drugsFixture);
 
     const { type } = await store.dispatch(getDrugs(SEARCH_QUERY));
     const { data, loading, error } = store.getState().drugs;
@@ -47,7 +47,7 @@ describe('drugs reducer', () => {
   it('should update store after failed getDrugs query', async () => {
     mockedAxiosClient
       .onGet(`projects/${PROJECT_ID}/drugs:search?query=${SEARCH_QUERY}`)
-      .reply(HTTP_NOT_FOUND, []);
+      .reply(HttpStatusCode.NotFound, []);
 
     const { type } = await store.dispatch(getDrugs(SEARCH_QUERY));
     const { data, loading, error } = store.getState().drugs;
@@ -61,7 +61,7 @@ describe('drugs reducer', () => {
   it('should update store on loading getDrugs query', async () => {
     mockedAxiosClient
       .onGet(`projects/${PROJECT_ID}/drugs:search?query=${SEARCH_QUERY}`)
-      .reply(HTTP_OK, drugsFixture);
+      .reply(HttpStatusCode.Ok, drugsFixture);
 
     const drugsPromise = store.dispatch(getDrugs(SEARCH_QUERY));
 
diff --git a/src/redux/drugs/drugs.thunks.test.ts b/src/redux/drugs/drugs.thunks.test.ts
index a90e8c5e..ee7d1c2e 100644
--- a/src/redux/drugs/drugs.thunks.test.ts
+++ b/src/redux/drugs/drugs.thunks.test.ts
@@ -1,6 +1,6 @@
+import { HttpStatusCode } from 'axios';
 import { PROJECT_ID } from '@/constants/mapId';
 import { drugsFixture } from '@/models/fixtures/drugFixtures';
-import { HTTP_OK } from '@/constants/httpResponses';
 import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
 import {
   ToolkitStoreWithSingleSlice,
@@ -22,7 +22,7 @@ describe('drugs thunks', () => {
     it('should return data when data response from API is valid', async () => {
       mockedAxiosClient
         .onGet(`projects/${PROJECT_ID}/drugs:search?query=${SEARCH_QUERY}`)
-        .reply(HTTP_OK, drugsFixture);
+        .reply(HttpStatusCode.Ok, drugsFixture);
 
       const { payload } = await store.dispatch(getDrugs(SEARCH_QUERY));
       expect(payload).toEqual(drugsFixture);
@@ -30,7 +30,7 @@ describe('drugs thunks', () => {
     it('should return undefined when data response from API is not valid ', async () => {
       mockedAxiosClient
         .onGet(`projects/${PROJECT_ID}/drugs:search?query=${SEARCH_QUERY}`)
-        .reply(HTTP_OK, { randomProperty: 'randomValue' });
+        .reply(HttpStatusCode.Ok, { randomProperty: 'randomValue' });
 
       const { payload } = await store.dispatch(getDrugs(SEARCH_QUERY));
       expect(payload).toEqual(undefined);
-- 
GitLab