Skip to content

Commit

Permalink
fix reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmochu committed Apr 24, 2019
1 parent 4de0341 commit 351dbcf
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
28 changes: 28 additions & 0 deletions src/app/Dashboard/operations/tests/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ export const categories = [{
value: 100,
}];

export const review = {
data: {
activityDate: '2018-08-13',
activityId: '8436db76-8e6b-11e8-80b6-9801a7ae0329',
activityTypeId: '8432b3d4-8e6b-11e8-91dd-9801a7ae0329',
approvedBy: {},
category: 'Open Saturdays Guides',
createdAt: '2018-07-23T11:28:26.571864+00:00',
description: '2018-feb-meetup invictus',
id: 'bnfad176-43cd-11e8-b3b9-9801a7ae0329',
modifiedAt: {},
name: {},
noOfParticipants: {},
owner: 'Test User',
owner_photo: 'https://lh3.googleusercontent.com/-Ke1NKb5MPuk/AAAAAAAAAAI/AAAAAAAAABg/8ofOe_CueLA/photo.jpg?sz=50',
points: 50,
redeemed: false,
reviewedBy: {},
society: {
id: '8431f00c-8e6b-11e8-bdf1-9801a7ae0329',
name: 'invictus',
},
societyId: '8431f00c-8e6b-11e8-bdf1-9801a7ae0329',
status: 'pending',
},
message: 'Activity edited successfully',
};

const activities = [];

for (let i = 0; i < numberOfItems; i += 1) {
Expand Down
7 changes: 6 additions & 1 deletion src/app/Societies/operations/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ const society = (state = initialState.society, { type, payload }) => {
};
}
case types.VERIFY_ACTIVITY_SUCCESS: {
const societyName = payload.data.society.name;
return {
...state,
inReview: [],
[societyName]: {
...state[societyName],
loggedActivities: state[societyName].loggedActivities
.filter(activity => activity.activityId !== payload.data.activityId),
},
};
}

Expand Down
22 changes: 14 additions & 8 deletions src/app/Societies/operations/tests/reducer.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import types from '../types';
import society from '../reducer';
import initialState from '../../../../reducers/initialState';
import activities from '../../../Dashboard/operations/tests/fixtures';
import activities, { review } from '../../../Dashboard/operations/tests/fixtures';
import { redemption } from '../../../Redemptions/components/tests/fixtures';

const defaultState = initialState.society;
Expand All @@ -27,7 +27,7 @@ describe('Society reducer', () => {
const error = 'There is an error in tests';
const action = {
type: types.SOCIETY_PAGE_ERROR,
payload: { error }
payload: { error },
};
expect(society(defaultState, action)).toEqual({ ...defaultState, error });
});
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Society reducer', () => {
remainingPoints: 100,
loggedActivities: activities,
activitiesLogged: activities.length,
}
},
});
});
});
Expand All @@ -78,21 +78,27 @@ describe('Society reducer', () => {
[societyName]: {
...defaultState[societyName],
redemptions: [],
}
},
});
});
});

describe('handles case VERIFY_ACTIVITY_SUCCESS', () => {
it('returns the created society activity', () => {
const inReview = [];
const societyName = 'phoenix';
const action = {
type: types.VERIFY_ACTIVITY_SUCCESS,
payload: inReview,
payload: review,
};
expect(
society(defaultState, action),
).toEqual({ ...defaultState });
).toEqual({
...defaultState,
[societyName]: {
...defaultState[societyName],
loggedActivities: [],
},
});
});
});

Expand All @@ -112,7 +118,7 @@ describe('Society reducer', () => {
[societyName]: {
...defaultState[societyName],
redemptions: [payload.redemption, ...defaultState[societyName].redemptions],
}
},
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export class VerifyActivitiesContainer extends Component {
logPointsComponent = <LogPointsComponent open={logPoints} close={this.logPointsModal} />;
}
if (societyName) {
const { inReview } = society;
const {
usedPoints, pointsEarned, remainingPoints, activitiesLogged,
usedPoints, pointsEarned, remainingPoints, activitiesLogged, loggedActivities,
} = society[
societyName.toLowerCase()
];
const inReview = this.filterActivitiesByInReviewStatus(loggedActivities);
verifyActivitiesHtml = (
<div>
<div className='profile-overview profile-overview--society'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('<VerifyActivitiesContainer />', () => {

it('should open the Log Points Modal', () => {
const instance = shallowWrapper.instance();
instance.setState({ logPoints: false });
expect(instance.state.logPoints).toBe(false);
shallowWrapper.find('.button__add').simulate('click');
expect(instance.state.logPoints).toBe(true);
Expand Down

0 comments on commit 351dbcf

Please sign in to comment.