Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAI-1941 Show hanke name and tunnus in user identification success notification #375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/domain/auth/components/UserIdentify.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { store } from '../../../common/redux/store';
import i18n from '../../../locales/i18n';
import authService from '../authService';
import { REDIRECT_PATH_KEY } from '../../../common/routes/constants';
import * as hankeUsersApi from '../../hanke/hankeUsers/hankeUsersApi';

afterEach(() => {
sessionStorage.clear();
});

const path = '/fi/kutsu?id=5ArrqPT6kW97QTK7t7ya9PA2';
const id = '5ArrqPT6kW97QTK7t7ya9PA2';
const path = `/fi/kutsu?id=${id}`;

const mockUser: Partial<User> = {
id_token: 'fffff-aaaaaa-11111',
Expand Down Expand Up @@ -72,9 +74,15 @@ test('Should save path with query string to session storage and navigate to logi
test('Should identify user after login', async () => {
sessionStorage.setItem(REDIRECT_PATH_KEY, path);
jest.spyOn(authService.userManager, 'getUser').mockResolvedValue(mockUser as User);
const identifyUser = jest.spyOn(hankeUsersApi, 'identifyUser');

getWrapper();

await waitFor(() => expect(window.document.title).toBe('Haitaton - Etusivu'));
expect(screen.queryByText('Tunnistautuminen onnistui')).toBeInTheDocument();
expect(identifyUser).toHaveBeenCalledWith(id);
expect(
screen.queryByText(
'Tunnistautuminen onnistui. Sinut on nyt lisätty hankkeelle (Aidasmäentien vesihuollon rakentaminen HAI22-2).',
),
).toBeInTheDocument();
});
4 changes: 2 additions & 2 deletions src/domain/auth/components/UserIdentify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function UserIdentify() {
useEffect(() => {
if (isAuthenticated && id !== null && !identifyUserCalled.current) {
mutate(id, {
onSuccess() {
onSuccess({ hankeNimi, hankeTunnus }) {
setNotification(true, {
label: t('hankeUsers:notifications:userIdentifiedLabel'),
message: t('hankeUsers:notifications:userIdentifiedText'),
message: t('hankeUsers:notifications:userIdentifiedText', { hankeNimi, hankeTunnus }),
type: 'success',
dismissible: true,
closeButtonLabelText: t('common:components:notification:closeButtonLabelText'),
Expand Down
6 changes: 6 additions & 0 deletions src/domain/hanke/hankeUsers/hankeUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ export type SignedInUser = {
kayttooikeustaso: keyof typeof AccessRightLevel;
kayttooikeudet: UserRights;
};

export type IdentificationResponse = {
kayttajaId: string;
hankeTunnus: string;
hankeNimi: string;
};
4 changes: 2 additions & 2 deletions src/domain/hanke/hankeUsers/hankeUsersApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import api from '../../api/api';
import { HankeUser, SignedInUser } from './hankeUser';
import { HankeUser, IdentificationResponse, SignedInUser } from './hankeUser';

export async function getHankeUsers(hankeTunnus: string) {
const { data } = await api.get<{ kayttajat: HankeUser[] }>(`hankkeet/${hankeTunnus}/kayttajat`);
Expand All @@ -24,6 +24,6 @@ export async function getSignedInUser(hankeTunnus?: string): Promise<SignedInUse
}

export async function identifyUser(id: string) {
const { data } = await api.post('kayttajat', { tunniste: id });
const { data } = await api.post<IdentificationResponse>('kayttajat', { tunniste: id });
return data;
}
11 changes: 9 additions & 2 deletions src/domain/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as hankkeetDB from './data/hankkeet';
import * as hakemuksetDB from './data/hakemukset';
import * as usersDB from './data/users';
import ApiError from './apiError';
import { SignedInUser } from '../hanke/hankeUsers/hankeUser';
import { IdentificationResponse, SignedInUser } from '../hanke/hankeUsers/hankeUser';

const apiUrl = '/api';

Expand Down Expand Up @@ -206,6 +206,13 @@ export const handlers = [
}),

rest.post(`${apiUrl}/kayttajat`, async (req, res, ctx) => {
return res(ctx.status(204));
return res(
ctx.status(200),
ctx.json<IdentificationResponse>({
kayttajaId: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
hankeTunnus: 'HAI22-2',
hankeNimi: 'Aidasmäentien vesihuollon rakentaminen',
}),
);
}),
];
2 changes: 1 addition & 1 deletion src/locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@
"rightsUpdatedErrorLabel": "Virhe päivityksessä",
"rightsUpdatedErrorText": "<0>Käyttöoikeuksien päivityksessä tapahtui virhe. Yritä myöhemmin uudelleen tai ota yhteyttä Haitattoman tekniseen tukeen sähköpostiosoitteessa <1>[email protected]</1>.</0>",
"userIdentifiedLabel": "Tunnistautuminen onnistui",
"userIdentifiedText": "Tunnistautuminen onnistui. Sinut on nyt lisätty hankkeelle.",
"userIdentifiedText": "Tunnistautuminen onnistui. Sinut on nyt lisätty hankkeelle ({{hankeNimi}} {{hankeTunnus}}).",
"userIdentifiedError": "Tunnistautuminen epäonnistui"
}
},
Expand Down
Loading