Merge branch 'lookup-401' into 'develop'
Redirect to /login if viewing an account 401's See merge request soapbox-pub/soapbox-fe!1509
This commit is contained in:
commit
bd95c9f7e8
4 changed files with 19 additions and 26 deletions
|
@ -148,34 +148,24 @@ describe('fetchAccountByUsername()', () => {
|
||||||
const username = 'tiger';
|
const username = 'tiger';
|
||||||
let state, account;
|
let state, account;
|
||||||
|
|
||||||
describe('when the account has already been cached in redux', () => {
|
beforeEach(() => {
|
||||||
beforeEach(() => {
|
account = normalizeAccount({
|
||||||
account = normalizeAccount({
|
id,
|
||||||
id,
|
acct: username,
|
||||||
acct: username,
|
display_name: 'Tiger',
|
||||||
display_name: 'Tiger',
|
avatar: 'test.jpg',
|
||||||
avatar: 'test.jpg',
|
birthday: undefined,
|
||||||
birthday: undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
state = rootReducer(undefined, {})
|
|
||||||
.set('accounts', ImmutableMap({
|
|
||||||
[id]: account,
|
|
||||||
}));
|
|
||||||
|
|
||||||
store = mockStore(state);
|
|
||||||
|
|
||||||
__stub((mock) => {
|
|
||||||
mock.onGet(`/api/v1/accounts/${id}`).reply(200, account);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null', async() => {
|
state = rootReducer(undefined, {})
|
||||||
const result = await store.dispatch(fetchAccountByUsername(username));
|
.set('accounts', ImmutableMap({
|
||||||
const actions = store.getActions();
|
[id]: account,
|
||||||
|
}));
|
||||||
|
|
||||||
expect(actions).toEqual([]);
|
store = mockStore(state);
|
||||||
expect(result).toBeNull();
|
|
||||||
|
__stub((mock) => {
|
||||||
|
mock.onGet(`/api/v1/accounts/${id}`).reply(200, account);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -12,9 +12,12 @@ const isRememberFailType = (type: string): boolean => type.endsWith('_REMEMBER_F
|
||||||
/** Whether the error contains an Axios response. */
|
/** Whether the error contains an Axios response. */
|
||||||
const hasResponse = (error: any): boolean => Boolean(error && error.response);
|
const hasResponse = (error: any): boolean => Boolean(error && error.response);
|
||||||
|
|
||||||
|
/** Don't show 401's. */
|
||||||
|
const authorized = (error: any): boolean => error?.response?.status !== 401;
|
||||||
|
|
||||||
/** Whether the error should be shown to the user. */
|
/** Whether the error should be shown to the user. */
|
||||||
const shouldShowError = ({ type, skipAlert, error }: AnyAction): boolean => {
|
const shouldShowError = ({ type, skipAlert, error }: AnyAction): boolean => {
|
||||||
return !skipAlert && hasResponse(error) && isFailType(type) && !isRememberFailType(type);
|
return !skipAlert && hasResponse(error) && authorized(error) && isFailType(type) && !isRememberFailType(type);
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Middleware to display Redux errors to the user. */
|
/** Middleware to display Redux errors to the user. */
|
||||||
|
|
Loading…
Reference in a new issue