Skip to content

Commit c316d62

Browse files
authored
Merge pull request #19 from WillSams/refactor/actioncreators-back-to-actiontype
Use actionCreators term correctly
2 parents d6628bd + a8ba512 commit c316d62

33 files changed

+145
-141
lines changed

frontend/specs/screens/home/reducers/homeReducer.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { actionCreators, onSuccessful } from '@/shared/base';
1+
import { actionTypes, onSuccessful } from '@/shared/base';
22
import { homeReducer } from '@/screens/home/reducers';
33

44
describe('home/reducers/homeReducer tests', () => {
@@ -19,7 +19,7 @@ describe('home/reducers/homeReducer tests', () => {
1919
const initialState = { loading: true, reservations: [] };
2020

2121
const action = {
22-
type: onSuccessful(actionCreators.GET_RESERVATIONS),
22+
type: onSuccessful(actionTypes.GET_RESERVATIONS),
2323
response,
2424
};
2525

frontend/specs/screens/home/sagas/cancelReservation.spec.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { call } from 'redux-saga/effects';
33
import { throwError } from 'redux-saga-test-plan/providers';
44

55
import {
6-
actionCreators,
6+
actionTypes,
77
onCancellation,
88
onFailure,
99
onSuccessful,
@@ -18,7 +18,7 @@ describe('cancelReservation Saga', () => {
1818
let scenario;
1919

2020
const action = {
21-
type: actionCreators.DELETE_RESERVATION,
21+
type: actionTypes.DELETE_RESERVATION,
2222
reservationId: 999,
2323
};
2424
const expectedRequestParams = { reservationId: action.reservationId };
@@ -56,13 +56,13 @@ describe('cancelReservation Saga', () => {
5656
[call(confirmation, action.reservationId), true],
5757
])
5858
.put({
59-
type: onSuccessful(actionCreators.DELETE_RESERVATION),
59+
type: onSuccessful(actionTypes.DELETE_RESERVATION),
6060
response: {
6161
data: expectedApiResponse,
6262
},
6363
})
6464
.put({
65-
type: actionCreators.SET_ALERT,
65+
type: actionTypes.SET_ALERT,
6666
alertType: 'success',
6767
message: 'Reservation cancelled.',
6868
})
@@ -73,7 +73,7 @@ describe('cancelReservation Saga', () => {
7373
return scenario
7474
.provide([[call(confirmation, action.reservationId), false]])
7575
.put({
76-
type: onCancellation(actionCreators.REJECT_CONFIRMATION_MODAL),
76+
type: onCancellation(actionTypes.REJECT_CONFIRMATION_MODAL),
7777
})
7878
.silentRun();
7979
});
@@ -98,12 +98,12 @@ describe('cancelReservation Saga', () => {
9898
],
9999
])
100100
.put({
101-
type: onFailure(actionCreators.DELETE_RESERVATION),
101+
type: onFailure(actionTypes.DELETE_RESERVATION),
102102
alertType: 'danger',
103103
message: expectedErrMessage,
104104
})
105105
.put({
106-
type: actionCreators.SET_ALERT,
106+
type: actionTypes.SET_ALERT,
107107
alertType: 'danger',
108108
message: expectedErrMessage,
109109
})
@@ -122,12 +122,12 @@ describe('cancelReservation Saga', () => {
122122
[call(confirmation, action.reservationId), true],
123123
])
124124
.put({
125-
type: onFailure(actionCreators.DELETE_RESERVATION),
125+
type: onFailure(actionTypes.DELETE_RESERVATION),
126126
alertType: 'danger',
127127
message: expectedErrMessage,
128128
})
129129
.put({
130-
type: actionCreators.SET_ALERT,
130+
type: actionTypes.SET_ALERT,
131131
alertType: 'danger',
132132
message: expectedErrMessage,
133133
})

frontend/specs/screens/home/sagas/getAllReservations.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expectSaga } from 'redux-saga-test-plan';
22
import { call } from 'redux-saga/effects';
33
import { throwError } from 'redux-saga-test-plan/providers';
44

5-
import { actionCreators, onFailure, onSuccessful } from '@/shared/base';
5+
import { actionTypes, onFailure, onSuccessful } from '@/shared/base';
66
import { fetchQuery, getExistingReservationsQuery } from '@/shared/graphql';
77

88
import getAllReservations from '@/screens/home/sagas/getAllReservations';
@@ -11,7 +11,7 @@ describe('getAllReservations Saga', () => {
1111
let scenario;
1212

1313
const action = {
14-
type: actionCreators.GET_RESERVATIONS,
14+
type: actionTypes.GET_RESERVATIONS,
1515
};
1616
const expectedRequestParams = {};
1717

@@ -77,7 +77,7 @@ describe('getAllReservations Saga', () => {
7777
message: expectedErrMessage,
7878
})
7979
.put({
80-
type: actionCreators.SET_ALERT,
80+
type: actionTypes.SET_ALERT,
8181
alertType,
8282
message: expectedErrMessage,
8383
})
@@ -101,7 +101,7 @@ describe('getAllReservations Saga', () => {
101101
message: expectedErrMessage,
102102
})
103103
.put({
104-
type: actionCreators.SET_ALERT,
104+
type: actionTypes.SET_ALERT,
105105
alertType,
106106
message: expectedErrMessage,
107107
})

frontend/specs/screens/reservations/reducers/newReducer.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { actionCreators, onSuccessful } from '@/shared/base';
1+
import { actionTypes, onSuccessful } from '@/shared/base';
22

33
import { newReducer } from '@/screens/reservations/reducers';
44

@@ -17,7 +17,7 @@ describe('reservations/reducers/newReducer tests', () => {
1717
const initialState = { loading: true, roomIds: [] };
1818

1919
const action = {
20-
type: onSuccessful(actionCreators.GET_ROOM_IDS),
20+
type: onSuccessful(actionTypes.GET_ROOM_IDS),
2121
response,
2222
};
2323

frontend/specs/screens/reservations/sagas/getAllRoomIds.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { expectSaga } from 'redux-saga-test-plan';
22
import { call } from 'redux-saga/effects';
33
import { throwError } from 'redux-saga-test-plan/providers';
44

5-
import { actionCreators, onFailure, onSuccessful } from '@/shared/base';
5+
import { actionTypes, onFailure, onSuccessful } from '@/shared/base';
66
import { fetchQuery, getRoomIdsQuery } from '@/shared/graphql';
77

88
import getAllRoomIds from '@/screens/reservations/sagas/getAllRoomIds';
99

1010
describe('getAllRoomIds Saga', () => {
1111
let scenario;
1212

13-
const action = { type: actionCreators.GET_ROOM_IDS };
13+
const action = { type: actionTypes.GET_ROOM_IDS };
1414
const expectedRequestParams = {};
1515
const mockRooms = [{ id: 'room1' }, { id: 'room2' }, { id: 'room3' }];
1616

@@ -72,7 +72,7 @@ describe('getAllRoomIds Saga', () => {
7272
message: expectedErrMessage,
7373
})
7474
.put({
75-
type: actionCreators.SET_ALERT,
75+
type: actionTypes.SET_ALERT,
7676
alertType,
7777
message: expectedErrMessage,
7878
})
@@ -98,7 +98,7 @@ describe('getAllRoomIds Saga', () => {
9898
message: expectedErrMessage,
9999
})
100100
.put({
101-
type: actionCreators.SET_ALERT,
101+
type: actionTypes.SET_ALERT,
102102
alertType,
103103
message: expectedErrMessage,
104104
})

frontend/specs/screens/reservations/sagas/newReservation.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expectSaga } from 'redux-saga-test-plan';
22
import { call } from 'redux-saga/effects';
33
import { throwError } from 'redux-saga-test-plan/providers';
44

5-
import { actionCreators, onFailure, onSuccessful } from '@/shared/base';
5+
import { actionTypes, onFailure, onSuccessful } from '@/shared/base';
66
import { fetchQuery, createReservationMutation } from '@/shared/graphql';
77

88
import newReservation from '@/screens/reservations/sagas/newReservation';
@@ -17,7 +17,7 @@ describe('newReservation Saga', () => {
1717
};
1818

1919
const action = {
20-
type: actionCreators.CREATE_RESERVATION,
20+
type: actionTypes.CREATE_RESERVATION,
2121
...input,
2222
};
2323

@@ -50,12 +50,12 @@ describe('newReservation Saga', () => {
5050
],
5151
])
5252
.put({
53-
type: actionCreators.SET_ALERT,
53+
type: actionTypes.SET_ALERT,
5454
alertType: 'success',
5555
message: 'Reservation created.',
5656
})
5757
.put({
58-
type: onSuccessful(actionCreators.CREATE_RESERVATION),
58+
type: onSuccessful(actionTypes.CREATE_RESERVATION),
5959
response: {
6060
data: mockResponse.data.createReservation.reservations,
6161
},
@@ -83,12 +83,12 @@ describe('newReservation Saga', () => {
8383
],
8484
])
8585
.put({
86-
type: onFailure(actionCreators.CREATE_RESERVATION),
86+
type: onFailure(actionTypes.CREATE_RESERVATION),
8787
alertType,
8888
message: expectedErrMessage,
8989
})
9090
.put({
91-
type: actionCreators.SET_ALERT,
91+
type: actionTypes.SET_ALERT,
9292
alertType,
9393
message: expectedErrMessage,
9494
})
@@ -113,7 +113,7 @@ describe('newReservation Saga', () => {
113113
message: expectedErrMessage,
114114
})
115115
.put({
116-
type: actionCreators.SET_ALERT,
116+
type: actionTypes.SET_ALERT,
117117
alertType,
118118
message: expectedErrMessage,
119119
})

frontend/specs/shared/base/baseApi.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { waitFor } from '@testing-library/react';
33
import axios from 'axios';
44
import MockAdapter from 'axios-mock-adapter';
55

6-
import { actionCreators, createBaseApi } from '@/shared/base';
6+
import { actionTypes, createBaseApi } from '@/shared/base';
77

88
describe('baseApi', () => {
99
const url = process.env.RESERVATION_API || '';
@@ -36,10 +36,10 @@ describe('baseApi', () => {
3636
await baseApi.get('/test');
3737
await waitFor(() => {
3838
expect(mockStore.dispatch).toHaveBeenCalledWith({
39-
type: actionCreators.API_REQUEST,
39+
type: actionTypes.API_REQUEST,
4040
});
4141
expect(mockStore.dispatch).toHaveBeenCalledWith({
42-
type: actionCreators.API_REQUEST_DONE,
42+
type: actionTypes.API_REQUEST_DONE,
4343
});
4444
});
4545
});

frontend/specs/shared/sagas/handleApiRequestError.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { takeLatest } from 'redux-saga/effects';
33

44
import { default as sharedSagas } from '../../../src/shared/sagas';
55
import { handleApiRequestError } from '../../../src/shared/sagas/handleApiRequestError';
6-
import { actionCreators, } from '../../../src/shared/base';
6+
import { actionTypes, } from '../../../src/shared/base';
77

88
describe('handleApiRequestError Saga', () => {
99
it('should dispatch SET_ALERT action with error message', () => {
@@ -14,7 +14,7 @@ describe('handleApiRequestError Saga', () => {
1414

1515
return expectSaga(handleApiRequestError, { error })
1616
.put({
17-
type: actionCreators.SET_ALERT,
17+
type: actionTypes.SET_ALERT,
1818
message: `Oops! Something went wrong. ${error.name}: ${error.message}`,
1919
alertType: 'danger',
2020
})
@@ -29,7 +29,7 @@ describe('handleApiRequestError Saga', () => {
2929

3030
return expectSaga(sharedSagas)
3131
.provide([
32-
[takeLatest(actionCreators.API_REQUEST_ERROR, handleApiRequestError), error],
32+
[takeLatest(actionTypes.API_REQUEST_ERROR, handleApiRequestError), error],
3333
])
3434
.silentRun();
3535
});

frontend/specs/shared/sagas/handleApiRequestUnauthorized.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { takeLatest } from 'redux-saga/effects';
33

44
import { default as sharedSagas } from '../../../src/shared/sagas';
55
import { handleApiRequestUnauthorized } from '../../../src/shared/sagas/handleApiRequestUnauthorized';
6-
import { actionCreators } from '../../../src/shared/base';
6+
import { actionTypes } from '../../../src/shared/base';
77

88
describe('handleApiRequestUnauthorized Saga', () => {
99
it('should dispatch the LOGOUT action', () => {
1010
return expectSaga(handleApiRequestUnauthorized)
11-
.put({ type: actionCreators.LOGOUT })
11+
.put({ type: actionTypes.LOGOUT })
1212
.run();
1313
});
1414

1515
it('should be invoked by latest API_REQUEST_UNAUTHORIZED dispatch', () => {
1616
return expectSaga(sharedSagas)
1717
.provide([
18-
[takeLatest(actionCreators.API_REQUEST_UNAUTHORIZED, handleApiRequestUnauthorized)],
18+
[takeLatest(actionTypes.API_REQUEST_UNAUTHORIZED, handleApiRequestUnauthorized)],
1919
])
2020
.silentRun();
2121
});

frontend/specs/shared/sagas/logout.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { takeLatest } from 'redux-saga/effects';
33

44
import { default as sharedSagas } from '../../../src/shared/sagas';
55
import { logout } from '../../../src/shared/sagas/logout';
6-
import { actionCreators, } from '../../../src/shared/base';
6+
import { actionTypes, } from '../../../src/shared/base';
77

88
describe('logout Saga', () => {
99

1010
it('should be invoked by latest LOGOUT dispatch', () => {
1111
return expectSaga(sharedSagas)
1212
.provide([
13-
[takeLatest(actionCreators.LOGOUT, logout),],
13+
[takeLatest(actionTypes.LOGOUT, logout),],
1414
])
1515
.silentRun();
1616
});

frontend/specs/shared/sharedReducer.spec.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import reducer, { initialState } from '@/shared/sharedReducer'; // Replace 'yourReducer' with the actual file path
2-
import { actionCreators } from '@/shared/base';
2+
import { actionTypes } from '@/shared/base';
33

44
describe('sharedReducer tests', () => {
55
beforeEach(() => {
66
jest.clearAllMocks();
77
});
88

99
it('should handle API_REQUEST action', () => {
10-
const action = { type: actionCreators.API_REQUEST };
10+
const action = { type: actionTypes.API_REQUEST };
1111
const newState = reducer(initialState, action);
1212

1313
expect(newState.requestInProgress).toBe(true);
1414
expect(newState.count).toBe(1);
1515
});
1616

1717
it('should handle API_REQUEST_DONE action', () => {
18-
const action = { type: actionCreators.API_REQUEST_DONE };
18+
const action = { type: actionTypes.API_REQUEST_DONE };
1919

2020
const newState = reducer(initialState, action);
2121

@@ -25,7 +25,7 @@ describe('sharedReducer tests', () => {
2525

2626
it('should handle SET_ALERT action', () => {
2727
const action = {
28-
type: actionCreators.SET_ALERT,
28+
type: actionTypes.SET_ALERT,
2929
message: 'Sample alert message',
3030
alertType: 'success',
3131
};
@@ -38,7 +38,7 @@ describe('sharedReducer tests', () => {
3838

3939
it('should handle CLEAR_ALERT action', () => {
4040
const action = {
41-
type: actionCreators.CLEAR_ALERT,
41+
type: actionTypes.CLEAR_ALERT,
4242
};
4343

4444
const stateWithAlert = {
@@ -55,7 +55,7 @@ describe('sharedReducer tests', () => {
5555

5656
it('should handle OPEN_CONFIRMATION_MODAL action', () => {
5757
const action = {
58-
type: actionCreators.OPEN_CONFIRMATION_MODAL,
58+
type: actionTypes.OPEN_CONFIRMATION_MODAL,
5959
title: 'Confirmation Title',
6060
message: 'Are you sure?',
6161
text: 'Confirm',
@@ -82,7 +82,7 @@ describe('sharedReducer tests', () => {
8282

8383
it('should handle LOAD_COMPONENT action', () => {
8484
const action = {
85-
type: actionCreators.LOAD_COMPONENT,
85+
type: actionTypes.LOAD_COMPONENT,
8686
};
8787

8888
const newState = reducer(initialState, action);
@@ -93,7 +93,7 @@ describe('sharedReducer tests', () => {
9393

9494
it('should handle COMPONENT_NOT_FOUND action', () => {
9595
const action = {
96-
type: actionCreators.COMPONENT_NOT_FOUND,
96+
type: actionTypes.COMPONENT_NOT_FOUND,
9797
};
9898

9999
const newState = reducer(initialState, action);

0 commit comments

Comments
 (0)