Add tests for authorizeFollowRequest() action

environments/review-add-accoun-5o034k/deployments/362
Justin 2022-06-23 15:37:21 -04:00
rodzic 7fc43f524a
commit 86d6c519f0
2 zmienionych plików z 66 dodań i 2 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import rootReducer from 'soapbox/reducers';
import { normalizeAccount } from '../../normalizers';
import {
authorizeFollowRequest,
blockAccount,
createAccount,
expandFollowers,
@ -1572,3 +1573,66 @@ describe('expandFollowRequests()', () => {
});
});
});
describe('authorizeFollowRequest()', () => {
const id = '1';
describe('when logged out', () => {
beforeEach(() => {
const state = rootReducer(undefined, {}).set('me', null);
store = mockStore(state);
});
it('should do nothing', async() => {
await store.dispatch(authorizeFollowRequest(id));
const actions = store.getActions();
expect(actions).toEqual([]);
});
});
describe('when logged in', () => {
beforeEach(() => {
const state = rootReducer(undefined, {}).set('me', '123');
store = mockStore(state);
});
describe('with a successful API request', () => {
beforeEach(() => {
__stub((mock) => {
mock.onPost(`/api/v1/follow_requests/${id}/authorize`).reply(200);
});
});
it('should dispatch the correct actions', async() => {
const expectedActions = [
{ type: 'FOLLOW_REQUEST_AUTHORIZE_REQUEST', id },
{ type: 'FOLLOW_REQUEST_AUTHORIZE_SUCCESS', id },
];
await store.dispatch(authorizeFollowRequest(id));
const actions = store.getActions();
expect(actions).toEqual(expectedActions);
});
});
describe('with an unsuccessful API request', () => {
beforeEach(() => {
__stub((mock) => {
mock.onPost(`/api/v1/follow_requests/${id}/authorize`).networkError();
});
});
it('should dispatch the correct actions', async() => {
const expectedActions = [
{ type: 'FOLLOW_REQUEST_AUTHORIZE_REQUEST', id },
{ type: 'FOLLOW_REQUEST_AUTHORIZE_FAIL', id, error: new Error('Network Error') },
];
await store.dispatch(authorizeFollowRequest(id));
const actions = store.getActions();
expect(actions).toEqual(expectedActions);
});
});
});
});

Wyświetl plik

@ -761,11 +761,11 @@ const expandFollowRequestsFail = (error: AxiosError) => ({
const authorizeFollowRequest = (id: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
if (!isLoggedIn(getState)) return;
if (!isLoggedIn(getState)) return null;
dispatch(authorizeFollowRequestRequest(id));
api(getState)
return api(getState)
.post(`/api/v1/follow_requests/${id}/authorize`)
.then(() => dispatch(authorizeFollowRequestSuccess(id)))
.catch(error => dispatch(authorizeFollowRequestFail(id, error)));