Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti@veritasgenetics.com>
import createBrowserHistory from "history/createBrowserHistory";
import { Config, mockConfig } from '~/common/config';
import { ApiActions } from "~/services/api/api-actions";
import createBrowserHistory from "history/createBrowserHistory";
import { Config, mockConfig } from '~/common/config';
import { ApiActions } from "~/services/api/api-actions";
+import { ACCOUNT_LINK_STATUS_KEY} from '~/services/link-account-service/link-account-service';
describe('auth-actions', () => {
let reducer: (state: AuthState | undefined, action: AuthAction) => any;
describe('auth-actions', () => {
let reducer: (state: AuthState | undefined, action: AuthAction) => any;
it('should initialise state with user and api token from local storage', () => {
it('should initialise state with user and api token from local storage', () => {
+ // Only test the case when a link account operation is not being cancelled
+ sessionStorage.setItem(ACCOUNT_LINK_STATUS_KEY, "0");
localStorage.setItem(API_TOKEN_KEY, "token");
localStorage.setItem(USER_EMAIL_KEY, "test@test.com");
localStorage.setItem(USER_FIRST_NAME_KEY, "John");
localStorage.setItem(API_TOKEN_KEY, "token");
localStorage.setItem(USER_EMAIL_KEY, "test@test.com");
localStorage.setItem(USER_FIRST_NAME_KEY, "John");
}
export const initAuth = (config: Config) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
}
export const initAuth = (config: Config) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- // Cancel any link account ops in progess unless the user has
+ // Cancel any link account ops in progress unless the user has
// just logged in or there has been a successful link operation
const data = services.linkAccountService.getLinkOpStatus();
if (!matchTokenRoute(location.pathname) && (!matchFedTokenRoute(location.pathname)) && data === undefined) {
// just logged in or there has been a successful link operation
const data = services.linkAccountService.getLinkOpStatus();
if (!matchTokenRoute(location.pathname) && (!matchFedTokenRoute(location.pathname)) && data === undefined) {
else {
dispatch<any>(init(config));
}
else {
dispatch<any>(init(config));
}
};
const init = (config: Config) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
};
const init = (config: Config) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
setAuthorizationHeader(services, linkAccountData.token);
user = await services.userService.get(linkAccountData.userUuid);
dispatch(switchUser(user, linkAccountData.token));
setAuthorizationHeader(services, linkAccountData.token);
user = await services.userService.get(linkAccountData.userUuid);
dispatch(switchUser(user, linkAccountData.token));
+ services.linkAccountService.saveLinkOpStatus(LinkAccountStatus.CANCELLED);
}
}
finally {
if (reload) {
}
}
finally {
if (reload) {
- services.linkAccountService.saveLinkOpStatus(LinkAccountStatus.CANCELLED);
location.reload();
}
else {
dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
location.reload();
}
else {
dispatch(progressIndicatorActions.STOP_WORKING(WORKBENCH_LOADING_SCREEN));
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Account link cancelled!", kind: SnackbarKind.INFO, hideDuration: 3000 }));