sforkowany z mirror/soapbox
Add tests for fetchFollowRequests() action
rodzic
ba595259c1
commit
6775beba93
|
@ -14,6 +14,7 @@ import {
|
||||||
fetchAccountByUsername,
|
fetchAccountByUsername,
|
||||||
fetchFollowers,
|
fetchFollowers,
|
||||||
fetchFollowing,
|
fetchFollowing,
|
||||||
|
fetchFollowRequests,
|
||||||
fetchRelationships,
|
fetchRelationships,
|
||||||
followAccount,
|
followAccount,
|
||||||
muteAccount,
|
muteAccount,
|
||||||
|
@ -1402,3 +1403,77 @@ describe('fetchRelationships()', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('fetchFollowRequests()', () => {
|
||||||
|
describe('when logged out', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const state = rootReducer(undefined, {}).set('me', null);
|
||||||
|
store = mockStore(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do nothing', async() => {
|
||||||
|
await store.dispatch(fetchFollowRequests());
|
||||||
|
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(() => {
|
||||||
|
const state = rootReducer(undefined, {})
|
||||||
|
.set('relationships', ImmutableMap({}))
|
||||||
|
.set('me', '123');
|
||||||
|
store = mockStore(state);
|
||||||
|
|
||||||
|
__stub((mock) => {
|
||||||
|
mock.onGet('/api/v1/follow_requests').reply(200, [], {
|
||||||
|
link: '<https://example.com/api/v1/follow_requests?since_id=1>; rel=\'prev\'',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch the correct actions', async() => {
|
||||||
|
const expectedActions = [
|
||||||
|
{ type: 'FOLLOW_REQUESTS_FETCH_REQUEST' },
|
||||||
|
{ type: 'ACCOUNTS_IMPORT', accounts: [] },
|
||||||
|
{
|
||||||
|
type: 'FOLLOW_REQUESTS_FETCH_SUCCESS',
|
||||||
|
accounts: [],
|
||||||
|
next: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
await store.dispatch(fetchFollowRequests());
|
||||||
|
const actions = store.getActions();
|
||||||
|
|
||||||
|
expect(actions).toEqual(expectedActions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('with an unsuccessful API request', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
__stub((mock) => {
|
||||||
|
mock.onGet('/api/v1/follow_requests').networkError();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should dispatch the correct actions', async() => {
|
||||||
|
const expectedActions = [
|
||||||
|
{ type: 'FOLLOW_REQUESTS_FETCH_REQUEST' },
|
||||||
|
{ type: 'FOLLOW_REQUESTS_FETCH_FAIL', error: new Error('Network Error') },
|
||||||
|
];
|
||||||
|
await store.dispatch(fetchFollowRequests());
|
||||||
|
const actions = store.getActions();
|
||||||
|
|
||||||
|
expect(actions).toEqual(expectedActions);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -693,15 +693,18 @@ const fetchRelationshipsFail = (error: AxiosError) => ({
|
||||||
|
|
||||||
const fetchFollowRequests = () =>
|
const fetchFollowRequests = () =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
if (!isLoggedIn(getState)) return;
|
if (!isLoggedIn(getState)) return null;
|
||||||
|
|
||||||
dispatch(fetchFollowRequestsRequest());
|
dispatch(fetchFollowRequestsRequest());
|
||||||
|
|
||||||
api(getState).get('/api/v1/follow_requests').then(response => {
|
return api(getState)
|
||||||
|
.get('/api/v1/follow_requests')
|
||||||
|
.then(response => {
|
||||||
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
||||||
dispatch(importFetchedAccounts(response.data));
|
dispatch(importFetchedAccounts(response.data));
|
||||||
dispatch(fetchFollowRequestsSuccess(response.data, next ? next.uri : null));
|
dispatch(fetchFollowRequestsSuccess(response.data, next ? next.uri : null));
|
||||||
}).catch(error => dispatch(fetchFollowRequestsFail(error)));
|
})
|
||||||
|
.catch(error => dispatch(fetchFollowRequestsFail(error)));
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchFollowRequestsRequest = () => ({
|
const fetchFollowRequestsRequest = () => ({
|
||||||
|
|
Ładowanie…
Reference in New Issue