Compare commits

...

1 Commits

Author SHA1 Message Date
AhtishamShahid
8ffe3e3d27 fix: resolve tour state update error 2023-01-24 12:17:33 +05:00
2 changed files with 9 additions and 14 deletions

View File

@@ -153,11 +153,10 @@ describe('toursReducer', () => {
it('handles the updateUserDiscussionsTourSuccess action', () => {
const initialState = {
tours: {
tours: [{ id: 1 }, { id: 2 }],
loading: true,
error: null,
},
tours: [
{ id: 1 },
{ id: 2 },
],
};
const updatedTour = {
id: 2,
@@ -165,11 +164,7 @@ describe('toursReducer', () => {
};
const state = toursReducer(initialState, updateUserDiscussionsTourSuccess(updatedTour));
expect(state.tours)
.toEqual({
tours: [{ id: 1 }, updatedTour],
loading: RequestStatus.SUCCESSFUL,
error: null,
});
.toEqual([{ id: 1 }, updatedTour]);
});
it('handles the discussionsToursRequestError action', () => {

View File

@@ -26,10 +26,10 @@ const userDiscussionsToursSlice = createSlice({
state.error = action.payload;
},
updateUserDiscussionsTourSuccess: (state, action) => {
const tourIndex = state.tours.tours.findIndex(tour => tour.id === action.payload.id);
state.tours.tours[tourIndex] = action.payload;
state.tours.loading = RequestStatus.SUCCESSFUL;
state.tours.error = null;
const tourIndex = state.tours.findIndex(tour => tour.id === action.payload.id);
state.tours[tourIndex] = action.payload;
state.loading = RequestStatus.SUCCESSFUL;
state.error = null;
},
},
});