From 7c759fae1e811259485dd264a1403e45c1aeb09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20Miesi=C4=85c?= <tadeusz.miesiac@gmail.com> Date: Tue, 3 Oct 2023 05:11:58 +0400 Subject: [PATCH] test: added missing tests --- src/redux/drugs/drugs.thunks.test.ts | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/redux/drugs/drugs.thunks.test.ts diff --git a/src/redux/drugs/drugs.thunks.test.ts b/src/redux/drugs/drugs.thunks.test.ts new file mode 100644 index 00000000..a90e8c5e --- /dev/null +++ b/src/redux/drugs/drugs.thunks.test.ts @@ -0,0 +1,39 @@ +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, + createStoreInstanceUsingSliceReducer, +} from '@/utils/createStoreInstanceUsingSliceReducer'; +import { getDrugs } from './drugs.thunks'; +import drugsReducer from './drugs.slice'; +import { DrugsState } from './drugs.types'; + +const mockedAxiosClient = mockNetworkResponse(); +const SEARCH_QUERY = 'aspirin'; + +describe('drugs thunks', () => { + let store = {} as ToolkitStoreWithSingleSlice<DrugsState>; + beforeEach(() => { + store = createStoreInstanceUsingSliceReducer('drugs', drugsReducer); + }); + describe('getDrugs', () => { + 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); + + const { payload } = await store.dispatch(getDrugs(SEARCH_QUERY)); + expect(payload).toEqual(drugsFixture); + }); + 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' }); + + const { payload } = await store.dispatch(getDrugs(SEARCH_QUERY)); + expect(payload).toEqual(undefined); + }); + }); +}); -- GitLab