reducers.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { keyBy } from 'lodash';
  2. import { getMockInvitees } from 'app/features/users/__mocks__/userMocks';
  3. import { reducerTester } from '../../../../test/core/redux/reducerTester';
  4. import { fetchInvitees, revokeInvite } from './actions';
  5. import { initialState, invitesReducer } from './reducers';
  6. describe('inviteesReducer', () => {
  7. describe('when fetchInvitees is dispatched', () => {
  8. it('then state should be correct', () => {
  9. const invitees = getMockInvitees(1);
  10. reducerTester<typeof initialState>()
  11. .givenReducer(invitesReducer, { ...initialState })
  12. .whenActionIsDispatched(fetchInvitees.fulfilled(invitees, ''))
  13. .thenStateShouldEqual({
  14. entities: keyBy(invitees, 'code'),
  15. ids: invitees.map((i) => i.code),
  16. status: 'succeeded',
  17. });
  18. });
  19. });
  20. describe('when revokeInvite is dispatched', () => {
  21. it('then state should be correct', () => {
  22. const invitees = getMockInvitees(1);
  23. const fakeInitialState: typeof initialState = {
  24. entities: keyBy(invitees, 'code'),
  25. ids: invitees.map((i) => i.code),
  26. status: 'succeeded',
  27. };
  28. reducerTester<typeof initialState>()
  29. .givenReducer(invitesReducer, fakeInitialState)
  30. .whenActionIsDispatched(revokeInvite.fulfilled(invitees[0].code, '', ''))
  31. .thenStateShouldEqual({
  32. entities: {
  33. [invitees[1].code]: invitees[1],
  34. },
  35. ids: [invitees[1].code],
  36. status: 'succeeded',
  37. });
  38. });
  39. });
  40. });