Skip to content

Commit

Permalink
feat: try localStorage solution for continuous user testing
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Nov 12, 2024
1 parent 4121696 commit 531cd90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,28 @@ let currentlyLoggedInUser = buildUnauthenticatedUserInfo();
*/
export const updateLoggedInUser = (patcher: Patcher<UserInfo>) => {
currentlyLoggedInUser = patchObj<UserInfo>(currentlyLoggedInUser, patcher);
localStorage.setItem(
'fakeUserId',
JSON.stringify(currentlyLoggedInUser.userId),
);
};

export const updateLoggedInUserById = (userId: string) => {
currentlyLoggedInUser = buildUserInfo(ALL_USERS[userId]);
localStorage.setItem('fakeUserId', JSON.stringify(userId));
};

export const fakeLogin = (userId?: string) => {
if (userId && Object.keys(ALL_USERS).includes(userId)) {
currentlyLoggedInUser = buildUserInfo(ALL_USERS[userId]);
updateLoggedInUserById(userId);
} else {
currentlyLoggedInUser = buildUserInfo(
ALL_USERS['00000000-0000-0000-0000-000000000001'],
);
updateLoggedInUserById('00000000-0000-0000-0000-000000000001');
}
};

export const fakeLogout = () => {
currentlyLoggedInUser = buildUnauthenticatedUserInfo();
localStorage.removeItem('fakeUserId');
};

/**
Expand Down Expand Up @@ -505,6 +513,7 @@ const patchUser = (userId: string, patcher: Patcher<UserDetailDto>) => {
};

function buildUserInfo(user: UserDetailDto): UserInfo {
console.log('user?' + user.userId);
return {
authenticationStatus: 'AUTHENTICATED',
userId: user.userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import {
REJECTED_ROUTES,
UNAUTHENTICATED_ROUTES,
} from '../../../app-routing.module';
import {
updateLoggedInUser,
updateLoggedInUserById,
} from '../../api/fake-backend/impl/fake-users';
import {ActiveFeatureSet} from '../../services/config/active-feature-set';
import {AuthorityPortalPageSet} from './authority-portal-page-set';
import {UrlBeforeLoginService} from './url-before-login.service';
Expand All @@ -48,7 +52,17 @@ export class RouteConfigService {
private router: Router,
private urlBeforeLoginService: UrlBeforeLoginService,
private activeFeatureSet: ActiveFeatureSet,
) {}
) {
console.log('RouteConfigService created');
try {
let fakeUserId = localStorage.getItem('fakeUserId');
if (fakeUserId) {
updateLoggedInUserById(JSON.parse(fakeUserId));
}
} catch (e) {
console.error(e);
}
}

decidePageSet(userInfoFetched: Fetched<UserInfo>): AuthorityPortalPageSet {
if (!userInfoFetched.isReady) {
Expand Down

0 comments on commit 531cd90

Please sign in to comment.