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

Diff for: .env.example

-7
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
##########################################################################

Diff for: .github/workflows/playwright.yml

+2-17
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()

Diff for: .gitignore

+3
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/*

Diff for: Playwright.Dockerfile

+35
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

Diff for: README.md

-2
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.

Diff for: apps/api/playwright.config.ts

+2-2
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('/')`. */

Diff for: apps/api/tests/e2e/api.spec.ts

+21-17
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

Diff for: apps/clearance_ui/package.json

+2-1
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",

Diff for: apps/clearance_ui/playwright.config.ts

+5-2
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",

Diff for: apps/clearance_ui/tests/e2e/global.setup.ts

+2-7
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"]');

Diff for: docker-compose.yml

+41-15
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,8 @@ services:
112112
- 3001:3001
113113
environment:
114114
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/postgres
115-
- KEYCLOAK_URL=$KEYCLOAK_URL
116-
- KEYCLOAK_REALM=$KEYCLOAK_REALM
117-
- KEYCLOAK_CLIENT_ID_API=$KEYCLOAK_CLIENT_ID_API
118-
- KEYCLOAK_CLIENT_SECRET_API=$KEYCLOAK_CLIENT_SECRET_API
119-
- ALLOWED_ORIGINS=http://localhost:3002,http://localhost:3000
115+
- KEYCLOAK_URL=http://keycloak:8080
116+
- ALLOWED_ORIGINS=http://clearance-ui:3000
120117
- SPACES_ENDPOINT=http://minio:9000
121118
- REDIS_URL=redis://redis:6379
122119
- PORT=3001
@@ -138,6 +135,15 @@ services:
138135
minio:
139136
condition: service_healthy
140137
required: true
138+
createbuckets:
139+
condition: service_completed_successfully
140+
required: true
141+
keycloak:
142+
condition: service_healthy
143+
required: true
144+
terraform:
145+
condition: service_completed_successfully
146+
required: true
141147

142148
scanner-worker:
143149
build:
@@ -154,17 +160,37 @@ services:
154160
build:
155161
dockerfile: UI.Dockerfile
156162
args:
157-
- NEXT_PUBLIC_API_URL=http://localhost:3001/api/
163+
- NEXT_PUBLIC_API_URL=http://api:3001/api/
158164
environment:
159-
- NEXTAUTH_URL=http://localhost:3002
160-
- NEXTAUTH_SECRET=$NEXTAUTH_SECRET
161-
- KEYCLOAK_URL=$KEYCLOAK_URL
162-
- KEYCLOAK_CLIENT_ID_UI=$KEYCLOAK_CLIENT_ID_UI
163-
- KEYCLOAK_CLIENT_ID_API=$KEYCLOAK_CLIENT_ID_API
164-
- KEYCLOAK_CLIENT_SECRET_UI=$KEYCLOAK_CLIENT_SECRET_UI
165-
- KEYCLOAK_REALM=dos-dev
166-
ports:
167-
- 3002:3000
165+
- NEXTAUTH_URL=http://clearance-ui:3000
166+
- NEXTAUTH_SECRET=secret
167+
- KEYCLOAK_URL=http://keycloak:8080
168+
169+
playwright-tests:
170+
build:
171+
context: .
172+
dockerfile: Playwright.Dockerfile
173+
args:
174+
- NEXT_PUBLIC_API_URL=http://api:3001/api/
175+
environment:
176+
- KEYCLOAK_URL=http://keycloak:8080
177+
- E2E_API_BASE_URL=http://api:3001
178+
- E2E_UI_BASE_URL=http://clearance-ui:3000
179+
depends_on:
180+
api:
181+
condition: service_healthy
182+
clearance-ui:
183+
condition: service_started
184+
volumes:
185+
- ./playwright-artifacts/clearance_ui:/workspace/apps/clearance_ui/playwright-report
186+
working_dir: /workspace
187+
command: >
188+
bash -c "
189+
echo 'Waiting for services...';
190+
until curl -s http://api:3001/api/health; do echo 'Waiting for API...'; sleep 2; done;
191+
echo 'API is up!';
192+
npm run test:e2e;
193+
"
168194
169195
volumes:
170196
db-data:

Diff for: terraform/keycloak.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ resource "keycloak_openid_client" "dos_ui_openid_client" {
169169
}
170170

171171
root_url = "http://localhost:3000"
172-
valid_redirect_uris = ["/*", "http://localhost:3002/*"]
173-
valid_post_logout_redirect_uris = ["/*", "http://localhost:3002/*"]
172+
valid_redirect_uris = ["/*", "http://clearance-ui:3000/*"]
173+
valid_post_logout_redirect_uris = ["/*", "http://clearance-ui:3000/*"]
174174
web_origins = ["+"] # + means all origins of Valid Redirect URIs
175175
}
176176

Diff for: turbo.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"DB_RETRY_INTERVAL",
1212
"DEBUG",
1313
"DL_CONCURRENCY",
14-
"E2E_USER_USERNAME",
15-
"E2E_USER_PASSWORD",
14+
"E2E_API_BASE_URL",
15+
"E2E_UI_BASE_URL",
1616
"KEYCLOAK_CLIENT_ID_API",
1717
"KEYCLOAK_CLIENT_ID_UI",
1818
"KEYCLOAK_CLIENT_SECRET_API",

0 commit comments

Comments
 (0)