Add tests for authorizeFollowRequest() action
This commit is contained in:
parent
7fc43f524a
commit
86d6c519f0
2 changed files with 66 additions and 2 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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)));
|
||||
|
|
Loading…
Reference in a new issue