diff --git a/frontend/playwright/api-requests/ApiRequests.tsx b/frontend/playwright/api-requests/ApiRequests.tsx index c63b973c..237f67ef 100644 --- a/frontend/playwright/api-requests/ApiRequests.tsx +++ b/frontend/playwright/api-requests/ApiRequests.tsx @@ -38,7 +38,6 @@ export class ApiRequests { } const errorText = await response.text(); console.error('Failed to fetch system users:', response.status, errorText); - console.log(response.status); throw new Error(`Failed to fetch system users: ${response.statusText}`); } @@ -134,6 +133,29 @@ export class ApiRequests { } } + public async getStatusForSystemUserRequest( + token: string, + systemRequestId: string, + ): Promise { + //Hardcode for now to test: + const endpoint = `v1/systemuser/request/vendor/${systemRequestId}`; + const url = `${process.env.API_BASE_URL}${endpoint}`; + + const response = await fetch(url, { + method: 'GET', + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + if (!response.ok) { + throw new Error(`Failed to fetch status for system user request. Status: ${response.status}`); + } + + const data = await response.json(); + return data; + } + generatePayloadSystemUserRequest(): PostSystemUserRequestPayload { const randomString = Date.now(); // Current timestamp in milliseconds const randomNum = Math.random().toString(36); diff --git a/frontend/playwright/e2eTests/approveSystemUserRequest.spec.ts b/frontend/playwright/e2eTests/approveSystemUserRequest.spec.ts index c4f602ac..c29ad3d4 100644 --- a/frontend/playwright/e2eTests/approveSystemUserRequest.spec.ts +++ b/frontend/playwright/e2eTests/approveSystemUserRequest.spec.ts @@ -16,25 +16,33 @@ test.describe('Godkjenn og avvis Systembrukerforespørsel', () => { test('Avvis Systembrukerforespørsel', async ({ page }): Promise => { //Generate confirmUrl from API - const confirmUrl = await prepareSystemUserRequest(api, token); + const systemUserRequestResponse = await prepareSystemUserRequest(api, token); - await page.goto(confirmUrl); + await page.goto(systemUserRequestResponse.confirmUrl); await page.getByRole('button', { name: 'Avvis' }).click(); //Expect user to be logged out await expect(loginPage.LOGIN_BUTTON).toBeVisible(); await expect(page).toHaveURL('https://info.altinn.no'); + + //Read from status api to verify that status is not rejected after clicking "Avvis" + const statusApiRequest = await getStatusForRequestApi(systemUserRequestResponse.id, token); + expect(statusApiRequest.status).toBe('Rejected'); }); test('Godkjenn Systembrukerforespørsel', async ({ page }): Promise => { - const confirmUrl = await prepareSystemUserRequest(api, token); + const systemUserRequestResponse = await prepareSystemUserRequest(api, token); - await page.goto(confirmUrl); + await page.goto(systemUserRequestResponse.confirmUrl); await page.getByRole('button', { name: 'Godkjenn' }).click(); //Expect user to be logged out await expect(loginPage.LOGIN_BUTTON).toBeVisible(); await expect(page).toHaveURL('https://info.altinn.no'); + + //Read from status api to verify that status is not Accepted after clicking "Avvis" + const statusApiRequest = await getStatusForRequestApi(systemUserRequestResponse.id, token); + expect(statusApiRequest.status).toBe('Accepted'); }); async function prepareSystemUserRequest(api: ApiRequests, tokenclass: Token) { @@ -43,7 +51,19 @@ test.describe('Godkjenn og avvis Systembrukerforespørsel', () => { 'altinn:authentication/systemuser.request.read altinn:authentication/systemuser.request.write'; const token = await tokenclass.getEnterpriseAltinnToken(scopes); const endpoint = 'v1/systemuser/request/vendor'; - const apiResponse = await api.sendPostRequest<{ confirmUrl: string }>(payload, endpoint, token); - return apiResponse.confirmUrl; // Return the Confirmation URL to use in the test + const apiResponse = await api.sendPostRequest<{ confirmUrl: string; id: string }>( + payload, + endpoint, + token, + ); + return { confirmUrl: apiResponse.confirmUrl, id: apiResponse.id }; // Return the Confirmation URL and the ID to use in the test + } + + async function getStatusForRequestApi(id: string, tokenclass: Token) { + const scopes = + 'altinn:authentication/systemuser.request.read altinn:authentication/systemuser.request.write'; + const token = await tokenclass.getEnterpriseAltinnToken(scopes); + const statusResponse = api.getStatusForSystemUserRequest<{ status: string }>(token, id); + return statusResponse; } }); \ No newline at end of file