Skip to content

Commit baf0804

Browse files
committed
#RI-4506 - Update recommendations without the code change
1 parent fe14ebe commit baf0804

File tree

1 file changed

+112
-2
lines changed

1 file changed

+112
-2
lines changed

redisinsight/ui/src/slices/tests/recommendations/recommendations.spec.ts

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { AxiosError } from 'axios'
22
import { cloneDeep, set } from 'lodash'
3+
import { MOCK_RECOMMENDATIONS } from 'uiSrc/constants/mocks/mock-recommendations'
34
import { Vote } from 'uiSrc/constants/recommendations'
4-
import { apiService } from 'uiSrc/services'
5+
import { apiService, resourcesService } from 'uiSrc/services'
56
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
67
import reducer, {
78
initialState,
@@ -19,7 +20,12 @@ import reducer, {
1920
updateLiveRecommendation,
2021
updateRecommendation,
2122
setTotalUnread,
22-
deleteLiveRecommendations, deleteRecommendations,
23+
deleteLiveRecommendations,
24+
deleteRecommendations,
25+
getContentRecommendations,
26+
getContentRecommendationsSuccess,
27+
getContentRecommendationsFailure,
28+
fetchContentRecommendations,
2329
} from 'uiSrc/slices/recommendations/recommendations'
2430
import { cleanup, initialStateDefault, mockStore, mockedStore } from 'uiSrc/utils/test-utils'
2531

@@ -261,6 +267,67 @@ describe('recommendations slice', () => {
261267
})
262268
expect(recommendationsSelector(rootState)).toEqual(state)
263269
})
270+
271+
describe('getContentRecommendations', () => {
272+
it('should properly set loading: true', () => {
273+
// Arrange
274+
const state = {
275+
...initialState,
276+
loading: true,
277+
error: '',
278+
}
279+
280+
// Act
281+
const nextState = reducer(initialState, getContentRecommendations())
282+
283+
// Assert
284+
const rootState = Object.assign(initialStateDefault, {
285+
recommendations: nextState,
286+
})
287+
expect(recommendationsSelector(rootState)).toEqual(state)
288+
})
289+
})
290+
291+
describe('getContentRecommendationsFailure', () => {
292+
it('should properly set error', () => {
293+
// Arrange
294+
const error = 'Some error'
295+
const state = {
296+
...initialState,
297+
loading: false,
298+
}
299+
300+
// Act
301+
const nextState = reducer(initialState, getContentRecommendationsFailure())
302+
303+
// Assert
304+
const rootState = Object.assign(initialStateDefault, {
305+
recommendations: nextState,
306+
})
307+
expect(recommendationsSelector(rootState)).toEqual(state)
308+
})
309+
})
310+
311+
describe('getContentRecommendationsSuccess', () => {
312+
it('should properly set loading: true', () => {
313+
const payload = MOCK_RECOMMENDATIONS
314+
// Arrange
315+
const state = {
316+
...initialState,
317+
loading: false,
318+
content: MOCK_RECOMMENDATIONS
319+
}
320+
321+
// Act
322+
const nextState = reducer(initialState, getContentRecommendationsSuccess(payload))
323+
324+
// Assert
325+
const rootState = Object.assign(initialStateDefault, {
326+
recommendations: nextState,
327+
})
328+
expect(recommendationsSelector(rootState)).toEqual(state)
329+
})
330+
})
264331
})
265332

266333
// thunks
@@ -495,5 +562,48 @@ describe('recommendations slice', () => {
495562
expect(store.getActions()).toEqual(expectedActions)
496563
})
497564
})
565+
566+
describe('fetchContentRecommendations', () => {
567+
it('succeed to get content recommendations', async () => {
568+
const data = MOCK_RECOMMENDATIONS
569+
const responsePayload = { status: 200, data }
570+
571+
resourcesService.get = jest.fn().mockResolvedValue(responsePayload)
572+
573+
// Act
574+
await store.dispatch<any>(fetchContentRecommendations())
575+
576+
// Assert
577+
const expectedActions = [
578+
getContentRecommendations(),
579+
getContentRecommendationsSuccess(data),
580+
]
581+
582+
expect(store.getActions()).toEqual(expectedActions)
583+
})
584+
585+
it('failed to get content recommendations', async () => {
586+
const errorMessage = 'Something was wrong!'
587+
const responsePayload = {
588+
response: {
589+
status: 500,
590+
data: { message: errorMessage },
591+
},
592+
}
593+
594+
resourcesService.get = jest.fn().mockRejectedValue(responsePayload)
595+
596+
// Act
597+
await store.dispatch<any>(fetchContentRecommendations())
598+
599+
// Assert
600+
const expectedActions = [
601+
getContentRecommendations(),
602+
getContentRecommendationsFailure()
603+
]
604+
605+
expect(store.getActions()).toEqual(expectedActions)
606+
})
607+
})
498608
})
499609
})

0 commit comments

Comments
 (0)