-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playwright tests for approve and reject change request (#452)
* add playwright tests for systemuser change request * refactor * type fix * Update build-deploy-at.yml * fixes * set correct env values in AT24 * remove unused import * check for change request status after approve/reject * Disable deploy and testing in AT24
- Loading branch information
Showing
6 changed files
with
184 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
frontend/playwright/e2eTests/approveSystemUserChangeRequest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import test, { expect } from '@playwright/test'; | ||
import { ApiRequests } from '../api-requests/ApiRequests'; | ||
import { TestdataApi } from 'playwright/util/TestdataApi'; | ||
|
||
test.describe('Godkjenn og avvis Systembruker endringsforespørsel', () => { | ||
let api: ApiRequests; | ||
|
||
test.beforeEach(async () => { | ||
api = new ApiRequests(); | ||
}); | ||
|
||
test('Avvis Systembruker endringsforespørsel', async ({ page }): Promise<void> => { | ||
//Generate confirmUrl from API | ||
const externalRef = TestdataApi.generateExternalRef(); | ||
const response = await api.postSystemuserRequest(externalRef); | ||
|
||
await api.approveSystemuserRequest(response.id); | ||
|
||
const confirmUrlChangeRequest = await api.postSystemuserChangeRequest(externalRef); | ||
|
||
await page.goto(confirmUrlChangeRequest); | ||
await page.getByRole('button', { name: 'Avvis' }).click(); | ||
|
||
//Expect user to be logged out | ||
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 api.getStatusForSystemUserRequest<{ status: string }>( | ||
response.id, | ||
); | ||
expect(statusApiRequest.status).toBe('Accepted'); | ||
}); | ||
|
||
test('Godkjenn Systembruker endringsforespørsel', async ({ page }): Promise<void> => { | ||
const externalRef = TestdataApi.generateExternalRef(); | ||
const response = await api.postSystemuserRequest(externalRef); | ||
|
||
await api.approveSystemuserRequest(response.id); | ||
|
||
const confirmUrlChangeRequest = await api.postSystemuserChangeRequest(externalRef); | ||
|
||
await page.goto(confirmUrlChangeRequest); | ||
await page.getByRole('button', { name: 'Godkjenn' }).click(); | ||
|
||
//Expect user to be logged out | ||
await expect(page).toHaveURL('https://info.altinn.no'); | ||
}); | ||
}); |
53 changes: 15 additions & 38 deletions
53
frontend/playwright/e2eTests/approveSystemUserRequest.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,46 @@ | ||
import test, { expect } from '@playwright/test'; | ||
import { ApiRequests } from '../api-requests/ApiRequests'; | ||
import { Token } from 'playwright/api-requests/Token'; | ||
import { LoginWithUserPage } from 'playwright/pages/loginPage'; | ||
import { TestdataApi } from 'playwright/util/TestdataApi'; | ||
|
||
test.describe('Godkjenn og avvis Systembrukerforespørsel', () => { | ||
let token: Token; | ||
let loginPage: LoginWithUserPage; | ||
let api: ApiRequests; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
test.beforeEach(async () => { | ||
api = new ApiRequests(); | ||
token = new Token(); | ||
loginPage = new LoginWithUserPage(page); | ||
}); | ||
|
||
test('Avvis Systembrukerforespørsel', async ({ page }): Promise<void> => { | ||
//Generate confirmUrl from API | ||
const systemUserRequestResponse = await prepareSystemUserRequest(api, token); | ||
const externalRef = TestdataApi.generateExternalRef(); | ||
const response = await api.postSystemuserRequest(externalRef); | ||
|
||
await page.goto(systemUserRequestResponse.confirmUrl); | ||
await page.goto(response.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); | ||
const statusApiRequest = await api.getStatusForSystemUserRequest<{ status: string }>( | ||
response.id, | ||
); | ||
expect(statusApiRequest.status).toBe('Rejected'); | ||
}); | ||
|
||
test('Godkjenn Systembrukerforespørsel', async ({ page }): Promise<void> => { | ||
const systemUserRequestResponse = await prepareSystemUserRequest(api, token); | ||
const externalRef = TestdataApi.generateExternalRef(); | ||
const response = await api.postSystemuserRequest(externalRef); | ||
|
||
await page.goto(systemUserRequestResponse.confirmUrl); | ||
await page.goto(response.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); | ||
const statusApiRequest = await api.getStatusForSystemUserRequest<{ status: string }>( | ||
response.id, | ||
); | ||
expect(statusApiRequest.status).toBe('Accepted'); | ||
}); | ||
|
||
async function prepareSystemUserRequest(api: ApiRequests, tokenclass: Token) { | ||
const payload = api.generatePayloadSystemUserRequest(); | ||
const scopes = | ||
'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; 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; | ||
} | ||
}); | ||
}); |
Oops, something went wrong.