Skip to content

Commit 3ab9b4b

Browse files
committed
Created unit tests for leaderboardDataReducer.
1 parent 0ff7f74 commit 3ab9b4b

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { leaderboardDataReducer } from '../leaderboardDataReducer';
2+
3+
describe('leaderboardDataReducer', () => {
4+
it('should return default state when no action is passed', () => {
5+
const initialState = [];
6+
const newState = leaderboardDataReducer(undefined, {});
7+
expect(newState).toEqual(initialState);
8+
});
9+
10+
it('should return updated state when GET_LEADERBOARD_DATA action is passed', () => {
11+
const action = {
12+
type: 'GET_LEADERBOARD_DATA',
13+
payload: [{ name: 'John', score: 100 }, { name: 'Doe', score: 90 }],
14+
};
15+
const newState = leaderboardDataReducer([], action);
16+
expect(newState).toEqual(action.payload);
17+
});
18+
19+
it('should not mutate state when unknown action type is passed', () => {
20+
const initialState = [{ name: 'John', score: 100 }];
21+
const action = { type: 'UNKNOWN_ACTION', payload: [] };
22+
const newState = leaderboardDataReducer(initialState, action);
23+
expect(newState).toEqual(initialState);
24+
});
25+
});
26+
27+
28+
29+
import { orgDataReducer } from '../leaderboardDataReducer';
30+
31+
describe('orgDataReducer', () => {
32+
it('should return default state when no action is passed', () => {
33+
const initialState = {};
34+
const newState = orgDataReducer(undefined, {});
35+
expect(newState).toEqual(initialState);
36+
});
37+
38+
it('should return updated state when GET_ORG_DATA action is passed', () => {
39+
const action = {
40+
type: 'GET_ORG_DATA',
41+
payload: { id: 1, name: 'Organization' },
42+
};
43+
const newState = orgDataReducer({}, action);
44+
expect(newState).toEqual(action.payload);
45+
});
46+
47+
it('should not mutate state when unknown action type is passed', () => {
48+
const initialState = { id: 1, name: 'Organization' };
49+
const action = { type: 'UNKNOWN_ACTION', payload: {} };
50+
const newState = orgDataReducer(initialState, action);
51+
expect(newState).toEqual(initialState);
52+
});
53+
});

0 commit comments

Comments
 (0)