Cover change username page with e2e tests and fix minor bugs

This commit is contained in:
SleepWalker
2019-12-29 13:57:44 +02:00
parent b2c072e5e1
commit f284664818
15 changed files with 230 additions and 156 deletions

View File

@@ -1,8 +1,6 @@
import {
getInfo as getInfoEndpoint,
changeLang as changeLangEndpoint,
acceptRules as acceptRulesEndpoint,
UserResponse,
} from 'app/services/api/accounts';
import { setLocale } from 'app/components/i18n/actions';
import { ThunkAction } from 'app/reducers';
@@ -39,9 +37,9 @@ export function setUser(payload: Partial<User>) {
}
export const CHANGE_LANG = 'USER_CHANGE_LANG';
export function changeLang(lang: string): ThunkAction<Promise<void>> {
return (dispatch, getState) =>
dispatch(setLocale(lang)).then((lang: string) => {
export function changeLang(targetLang: string): ThunkAction<Promise<void>> {
return async (dispatch, getState) =>
dispatch(setLocale(targetLang)).then((lang: string) => {
const { id, isGuest, lang: oldLang } = getState().user;
if (oldLang === lang) {
@@ -72,28 +70,6 @@ export function setGuest(): ThunkAction<Promise<void>> {
};
}
export function fetchUserData(): ThunkAction<Promise<UserResponse>> {
return async (dispatch, getState) => {
const { id } = getState().user;
if (!id) {
throw new Error('Can not fetch user data. No user.id available');
}
const resp = await getInfoEndpoint(id);
dispatch(
updateUser({
isGuest: false,
...resp,
}),
);
dispatch(changeLang(resp.lang));
return resp;
};
}
export function acceptRules(): ThunkAction<Promise<{ success: boolean }>> {
return (dispatch, getState) => {
const { id } = getState().user;