Skip to content

Commit

Permalink
OY-4713 Lisätty end-to-end Playwright -testi
Browse files Browse the repository at this point in the history
  • Loading branch information
jkorri committed Feb 29, 2024
1 parent b4e83fc commit 2191022
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,45 @@ jobs:
path: target
key: ${{ github.sha }}

test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
run: |
npm ci --no-audit --prefer-offline
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').dependencies['@playwright/test'].version)")" >> $GITHUB_ENV
- name: Cache playwright binaries
uses: actions/cache@v3
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- run: npx playwright install --with-deps chromium
if: steps.playwright-cache.outputs.cache-hit != 'true'
# - name: Check code
# run: |
# npm run tsc
# npm run lint
- name: Add hosts to /etc/hosts
run: |
sudo echo 127.0.0.1 maksut-local.test | sudo tee -a /etc/hosts
- name: Run tests
run: |
# npm run build
npm run playwright

deploy-container:
needs: [ test-and-build ]
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"scripts": {
"lint:clj": "clj-kondo --config oph-configuration/clj-kondo.config.edn --fail-level error --lint src",
"lint:clj:lint-staged": "clj-kondo --config oph-configuration/clj-kondo.config.edn --lint"
"lint:clj:lint-staged": "clj-kondo --config oph-configuration/clj-kondo.config.edn --lint",
"playwright": "playwright test"
},
"engines": {
"node": ">=14"
Expand All @@ -27,6 +28,8 @@
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@playwright/test": "^1.40.1",
"uuid": "^9.0.1",
"babel-loader": "^8.1.0",
"clj-kondo": "^2024.02.12",
"husky": "^4.3.0",
Expand Down
16 changes: 16 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
// All requests we send go to this API endpoint.
baseURL: 'https://maksut-local.test:9000',
/*
extraHTTPHeaders: {
// We set this header per GitHub guidelines.
'Accept': 'application/vnd.github.v3+json',
// Add authorization token to all requests.
// Assuming personal access token available in the environment.
'Authorization': `token ${process.env.API_TOKEN}`,
},
*/
}
});
69 changes: 69 additions & 0 deletions playwright/tests/fullflow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { test, Page, expect, chromium } from '@playwright/test';
import { v4 as uuid } from 'uuid';

test.describe.configure({ mode: 'serial' })

let userPage: Page
let apiPage: Page

test.beforeAll(async () => {
const browser = await chromium.launch({ headless: false, args: ['--disable-web-security'] })
const context = await browser.newContext({ ignoreHTTPSErrors: true });
userPage = await context.newPage();
apiPage = await context.newPage();

// kirjaudutaan ataruna sisään apiin
await apiPage.goto(
'/maksut/auth/cas?ticket=abc'
);

/*
await page.route(
'**!/lomake-editori/api/tarjonta/haku/1.2.246.562.29.00000000000000009710',
async (route) => {
await route.fulfill({
json: { yhteishaku: true, 'kohdejoukko-uri': 'haunkohdejoukko_11#1' },
})
}
)
*/

})

test.afterAll(async ({ request }) => {
await userPage.close()
})

test('Paytrail maksuflow', async ( { request } ) => {
// luodaan ataruna uusi lasku
await userPage.bringToFront()
const newInvoice = await userPage.context().request.post(`/maksut/api/lasku-tutu`, {
data: {
"application-key": `${uuid()}`,
"first-name": "test1",
"last-name": "test1",
"email": "[email protected]",
"amount": "256",
"due-date": "2030-03-03",
"index": 1
}
});
expect(newInvoice.ok()).toBeTruthy();
const json = await newInvoice.json()

// mennään käyttäjänä maksusivulle
await userPage.goto(
`/maksut/?secret=${json.secret}&locale=fi`
);

// käynnistetään käyttäjänä maksuflow
await userPage.getByRole('link', { name: 'Siirry maksamaan' }).click();

// maksetaan käyttäjänä
await userPage.getByRole('img', { name: 'OP', exact: true }).click();
await userPage.getByRole('button', { name: 'OP', exact: true}).click();

// varmistetaan että ollaan käyttäjänä palattu maksuihin tehdyn maksun sivulle
await expect(userPage).toHaveURL(`/maksut/?secret=${json.secret}&locale=fi`, { timeout: 20000 });
await expect(userPage.getByText("Maksettu", { exact: true })).toBeVisible();
})

0 comments on commit 2191022

Please sign in to comment.