Skip to content

Commit 6d2d291

Browse files
committed
WIP
1 parent 1db5810 commit 6d2d291

File tree

13 files changed

+117
-74
lines changed

13 files changed

+117
-74
lines changed

.env.example

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ DATABASE_URL=
1313
# API URL
1414
NEXT_PUBLIC_API_URL=http://localhost:5000/api/
1515

16-
##########################################################################
17-
# Compulsory when running Playwright tests:
18-
##########################################################################
19-
# E2E test user credentials
20-
E2E_USER_USERNAME=
21-
E2E_USER_PASSWORD=
22-
2316
##########################################################################
2417
# Compulsory in production (aka when NODE_ENV=production):
2518
##########################################################################

.github/workflows/playwright.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,7 @@ jobs:
1717
environment: test-environment
1818
env:
1919
DATABASE_URL: ${{ vars.DATABASE_URL }}
20-
E2E_USER_USERNAME: ${{ secrets.E2E_USER_USERNAME }}
21-
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
22-
KEYCLOAK_URL: ${{ vars.KEYCLOAK_URL }}
23-
KEYCLOAK_REALM: ${{ secrets.KEYCLOAK_REALM }}
24-
KEYCLOAK_CLIENT_ID_UI: ${{ secrets.KEYCLOAK_CLIENT_ID_UI }}
25-
KEYCLOAK_CLIENT_SECRET_UI: ${{ secrets.KEYCLOAK_CLIENT_SECRET_UI }}
26-
KEYCLOAK_CLIENT_ID_API: ${{ secrets.KEYCLOAK_CLIENT_ID_API }}
27-
KEYCLOAK_CLIENT_SECRET_API: ${{ secrets.KEYCLOAK_CLIENT_SECRET_API }}
28-
NEXTAUTH_URL: http://localhost:3000
2920
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
30-
NEXT_PUBLIC_API_URL: http://localhost:3001/api/
3121
steps:
3222
- uses: actions/checkout@v4
3323
- uses: actions/setup-node@v4
@@ -36,19 +26,14 @@ jobs:
3626
cache: "npm"
3727
- name: Install dependencies
3828
run: npm ci
39-
- name: Install Playwright Browsers
40-
working-directory: apps/clearance_ui
41-
run: npx playwright install --with-deps
4229
- name: Run prisma generate
4330
run: npm run db:generate
44-
- name: Build project
45-
run: npm run build
4631
- name: Start the testing environment
47-
run: docker compose up -d
32+
run: docker compose up api clearance-ui scanner-worker -d
4833
- name: Seed the database and populate the spaces bucket
4934
run: npm run db:migrate:reset
5035
- name: Run Playwright tests
51-
run: npm run test:e2e
36+
run: docker compose up playwright-tests
5237
- name: Print Docker Compose logs
5338
run: docker compose logs
5439
if: failure()

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,6 @@ yarn.lock
158158
# Terraform
159159
terraform/.terraform/*
160160
terraform/terraform.tfstate*
161+
162+
# Playwright artifacts
163+
playwright-artifacts/*

Playwright.Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: 2025 Double Open Oy
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
FROM node:22.14.0
6+
7+
WORKDIR /workspace
8+
9+
RUN npm i -g turbo
10+
11+
COPY package.json ./package.json
12+
COPY apps/api/package.json ./apps/api/package.json
13+
COPY apps/clearance_ui/package.json ./apps/clearance_ui/package.json
14+
COPY packages/database/package.json ./packages/database/package.json
15+
COPY packages/s3-helpers/package.json ./packages/s3-helpers/package.json
16+
COPY packages/spdx-validation/package.json ./packages/spdx-validation/package.json
17+
COPY packages/validation-helpers/package.json ./packages/validation-helpers/package.json
18+
COPY package-lock.json ./package-lock.json
19+
20+
RUN npm ci
21+
22+
COPY . .
23+
24+
RUN npm run db:generate
25+
26+
RUN npm run build:api
27+
28+
ARG NEXT_PUBLIC_API_URL
29+
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
30+
31+
RUN npm run build:cui
32+
33+
# Install browsers for UI tests
34+
WORKDIR /workspace/apps/clearance_ui
35+
RUN npm run install-browsers

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ To run this project you will need Node.js, npm and Docker installed.
4242

4343
```shell
4444
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
45-
E2E_USER_USERNAME=
46-
E2E_USER_PASSWORD=
4745
```
4846

4947
See [.env.example](https://github.com/doubleopen-project/dos/blob/main/.env.example) file for other non-compulsory configurable variables.

apps/api/playwright.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ export default defineConfig({
1919

2020
testDir: "./tests/e2e",
2121
/* Run tests in files in parallel */
22-
fullyParallel: true,
22+
//fullyParallel: true,
2323
/* Fail the build on CI if you accidentally left test.only in the source code. */
2424
forbidOnly: !!process.env.CI,
2525
/* Retry on CI only */
2626
retries: process.env.CI ? 2 : 0,
2727
/* Opt out of parallel tests on CI. */
2828
workers: process.env.CI ? 1 : undefined,
2929
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
30-
reporter: "html",
30+
reporter: [["html", { open: "never" }]],
3131
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3232
use: {
3333
/* Base URL to use in actions like `await page.goto('/')`. */

apps/api/tests/e2e/api.spec.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,31 @@ import {
1111
import test, { expect } from "@playwright/test";
1212
import { Zodios, ZodiosInstance } from "@zodios/core";
1313
import AdmZip from "adm-zip";
14-
import { getPresignedPutUrl, S3Client } from "s3-helpers";
14+
import { authConfig } from "common-helpers";
15+
//import { getPresignedPutUrl, S3Client } from "s3-helpers";
1516
import { dosAPI, userAPI } from "validation-helpers";
1617

1718
/**
1819
* Construct Zodios callers for the API endpoints to easily call them in the tests.
1920
*/
2021

21-
const server = process.env.KEYCLOAK_URL;
22-
const realm = process.env.KEYCLOAK_REALM;
23-
const clientId = process.env.KEYCLOAK_CLIENT_ID_API;
24-
const clientSecret = process.env.KEYCLOAK_CLIENT_SECRET_API;
25-
const username = process.env.E2E_USER_USERNAME;
26-
const password = process.env.E2E_USER_PASSWORD;
27-
28-
if (!server || !realm || !clientId || !clientSecret || !username || !password) {
29-
throw new Error(
30-
"KEYCLOAK_URL, KEYCLOAK_REALM, KEYCLOAK_CLIENT_ID_API, KEYCLOAK_CLIENT_SECRET_API, E2E_USER_USERNAME and E2E_USER_PASSWORD environment variables must be set",
31-
);
32-
}
22+
const server = authConfig.url;
23+
const realm = authConfig.realm;
24+
const clientId = authConfig.clientIdUI;
25+
const clientSecret = authConfig.clientSecretUI;
26+
const username = "test-user";
27+
const password = "test-user";
28+
const apiUrl = process.env.E2E_API_BASE_URL || "http://localhost:5000";
3329

30+
/*
3431
const s3Client = S3Client(
3532
process.env.NODE_ENV !== "production",
3633
// This needs to be localhost instead of SPACES_ENDPOINT due to the containers needing to access
3734
// Minio with SPACES_ENDPOINT, but the tests needing to access Minio with localhost.
3835
"http://localhost:9000",
3936
process.env.SPACES_KEY,
4037
process.env.SPACES_SECRET,
41-
);
38+
);*/
4239

4340
test.describe("API lets authenticated users to", () => {
4441
let keycloakToken: string;
@@ -72,7 +69,7 @@ test.describe("API lets authenticated users to", () => {
7269
const body = await result.json();
7370
keycloakToken = (body as { access_token: string }).access_token;
7471

75-
userZodios = new Zodios("http://localhost:3001/api/user/", userAPI, {
72+
userZodios = new Zodios(`${apiUrl}/api/user/`, userAPI, {
7673
axiosConfig: {
7774
headers: {
7875
Authorization: `Bearer ${keycloakToken}`,
@@ -88,7 +85,7 @@ test.describe("API lets authenticated users to", () => {
8885

8986
dosToken = userToken.token;
9087

91-
dosZodios = new Zodios("http://localhost:3001/api/", dosAPI, {
88+
dosZodios = new Zodios(`${apiUrl}/api/`, dosAPI, {
9289
axiosConfig: {
9390
headers: {
9491
Authorization: `Bearer ${dosToken}`,
@@ -133,11 +130,18 @@ test.describe("API lets authenticated users to", () => {
133130
* running on host. This means that we need to create the presigned URL with an external S3
134131
* client that can access the Minio on localhost.
135132
*/
133+
/*
136134
const presignedUrl = await getPresignedPutUrl(
137135
s3Client,
138136
"doubleopen",
139137
zipKey,
140-
);
138+
);*/
139+
140+
const presignedUrl = (
141+
await dosZodios.post("/upload-url", {
142+
key: zipKey,
143+
})
144+
).presignedUrl;
141145

142146
expect(presignedUrl).toBeDefined();
143147

apps/clearance_ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"test:watch": "jest --watchAll --verbose",
1212
"test:e2e": "playwright test",
1313
"test:e2e:report": "playwright show-report",
14-
"test:e2e:ui": "playwright test --ui"
14+
"test:e2e:ui": "playwright test --ui",
15+
"install-browsers": "playwright install --with-deps"
1516
},
1617
"dependencies": {
1718
"@hookform/resolvers": "5.0.1",

apps/clearance_ui/playwright.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ export default defineConfig({
2929
/* Opt out of parallel tests on CI. */
3030
workers: process.env.CI ? 1 : undefined,
3131
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
32-
reporter: "html",
32+
reporter: [["html", { open: "never" }]],
3333
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3434
use: {
3535
/* Base URL to use in actions like `await page.goto('/')`. */
36+
/*
3637
baseURL: process.env.CI
3738
? "http://localhost:3002"
38-
: "http://localhost:3000",
39+
: "http://localhost:3000",*/
40+
41+
baseURL: process.env.E2E_UI_BASE_URL || "http://localhost:3000",
3942

4043
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
4144
trace: "on-first-retry",

apps/clearance_ui/tests/e2e/global.setup.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { expect, test as setup } from "@playwright/test";
66
import { STORAGE_STATE } from "../../playwright.config";
77

88
setup("logs in", async ({ page }) => {
9-
if (!process.env.E2E_USER_USERNAME || !process.env.E2E_USER_PASSWORD) {
10-
throw new Error(
11-
"E2E_USER_USERNAME and E2E_USER_PASSWORD environment variables must be set",
12-
);
13-
}
149
// Clear old session cookie from the browser
1510
await page.goto("/api/auth/signout");
1611

@@ -24,8 +19,8 @@ setup("logs in", async ({ page }) => {
2419
await page.click("button:has-text('Sign in with Keycloak')");
2520

2621
// Fill the login form
27-
await page.fill("#username", process.env.E2E_USER_USERNAME);
28-
await page.fill("#password", process.env.E2E_USER_PASSWORD);
22+
await page.fill("#username", "test-user");
23+
await page.fill("#password", "test-user");
2924

3025
// Submit login form
3126
await page.click('button[type="submit"]');

0 commit comments

Comments
 (0)