Skip to content

Commit

Permalink
Merge pull request #2913 from OneCommunityGlobal/vijay-anand-unit-tes…
Browse files Browse the repository at this point in the history
…t-weekly-summaries-reducer

Vijay Anand - Add unit tests for weeklySummariesReducer
  • Loading branch information
one-community authored Dec 6, 2024
2 parents 2ea8d03 + 5ccd2f1 commit 5838621
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/reducers/__tests__/weeklySummariesReducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { weeklySummariesReducer } from '../weeklySummariesReducer';
import * as actions from '../../constants/weeklySummaries';

describe('weeklySummariesReducer', () => {
const initialState = {
summaries: {},
loading: false,
fetchError: null,
};

it('should return the initial state when no action is provided', () => {
expect(weeklySummariesReducer(undefined, {})).toEqual(initialState);
});

it('should handle FETCH_WEEKLY_SUMMARIES_BEGIN', () => {
const action = { type: actions.FETCH_WEEKLY_SUMMARIES_BEGIN };
const expectedState = {
...initialState,
loading: true,
fetchError: null,
};
expect(weeklySummariesReducer(initialState, action)).toEqual(expectedState);
});

it('should handle FETCH_WEEKLY_SUMMARIES_SUCCESS', () => {
const mockData = {
weeklySummariesData: {
week1: { summary: 'Test Summary 1' },
week2: { summary: 'Test Summary 2' },
},
};
const action = {
type: actions.FETCH_WEEKLY_SUMMARIES_SUCCESS,
payload: mockData,
};
const expectedState = {
...initialState,
loading: false,
summaries: mockData.weeklySummariesData,
};
expect(weeklySummariesReducer(initialState, action)).toEqual(expectedState);
});

it('should handle FETCH_WEEKLY_SUMMARIES_ERROR', () => {
const mockError = new Error('Failed to fetch data');
const action = {
type: actions.FETCH_WEEKLY_SUMMARIES_ERROR,
payload: { error: mockError },
};
const expectedState = {
...initialState,
loading: false,
fetchError: mockError,
};
expect(weeklySummariesReducer(initialState, action)).toEqual(expectedState);
});
});

0 comments on commit 5838621

Please sign in to comment.