Add tests for removeFromFollowers() action
This commit is contained in:
parent
0a9e1c808b
commit
931f2e16d8
|
@ -12,6 +12,7 @@ import {
|
||||||
fetchAccountByUsername,
|
fetchAccountByUsername,
|
||||||
followAccount,
|
followAccount,
|
||||||
muteAccount,
|
muteAccount,
|
||||||
|
removeFromFollowers,
|
||||||
subscribeAccount,
|
subscribeAccount,
|
||||||
unblockAccount,
|
unblockAccount,
|
||||||
unfollowAccount,
|
unfollowAccount,
|
||||||
|
@ -921,3 +922,69 @@ describe('unsubscribeAccount()', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('removeFromFollowers()', () => {
|
||||||
|
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(removeFromFollowers(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/accounts/${id}/remove_from_followers`).reply(200, {});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch the correct actions', async() => {
|
||||||
|
const expectedActions = [
|
||||||
|
{ type: 'ACCOUNT_REMOVE_FROM_FOLLOWERS_REQUEST', id },
|
||||||
|
{
|
||||||
|
type: 'ACCOUNT_REMOVE_FROM_FOLLOWERS_SUCCESS',
|
||||||
|
relationship: {},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
await store.dispatch(removeFromFollowers(id));
|
||||||
|
const actions = store.getActions();
|
||||||
|
|
||||||
|
expect(actions).toEqual(expectedActions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with an unsuccessful API request', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
__stub((mock) => {
|
||||||
|
mock.onPost(`/api/v1/accounts/${id}/remove_from_followers`).networkError();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch the correct actions', async() => {
|
||||||
|
const expectedActions = [
|
||||||
|
{ type: 'ACCOUNT_REMOVE_FROM_FOLLOWERS_REQUEST', id },
|
||||||
|
{ type: 'ACCOUNT_REMOVE_FROM_FOLLOWERS_FAIL', id, error: new Error('Network Error') },
|
||||||
|
];
|
||||||
|
await store.dispatch(removeFromFollowers(id));
|
||||||
|
const actions = store.getActions();
|
||||||
|
|
||||||
|
expect(actions).toEqual(expectedActions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -468,15 +468,14 @@ const unsubscribeAccountFail = (error: AxiosError) => ({
|
||||||
|
|
||||||
const removeFromFollowers = (id: string) =>
|
const removeFromFollowers = (id: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return null;
|
||||||
|
|
||||||
dispatch(muteAccountRequest(id));
|
dispatch(removeFromFollowersRequest(id));
|
||||||
|
|
||||||
api(getState).post(`/api/v1/accounts/${id}/remove_from_followers`).then(response => {
|
return api(getState)
|
||||||
dispatch(removeFromFollowersSuccess(response.data));
|
.post(`/api/v1/accounts/${id}/remove_from_followers`)
|
||||||
}).catch(error => {
|
.then(response => dispatch(removeFromFollowersSuccess(response.data)))
|
||||||
dispatch(removeFromFollowersFail(id, error));
|
.catch(error => dispatch(removeFromFollowersFail(id, error)));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeFromFollowersRequest = (id: string) => ({
|
const removeFromFollowersRequest = (id: string) => ({
|
||||||
|
|
Loading…
Reference in New Issue