Skip to content

Commit e3cb918

Browse files
committed
WIP
1 parent 1db5810 commit e3cb918

File tree

12 files changed

+115
-71
lines changed

12 files changed

+115
-71
lines changed

.env.example

Lines changed: 8 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
##########################################################################
@@ -122,3 +115,11 @@ WEB_CONCURRENCY= # default 1
122115

123116
# Refetch interval used to refresh session (seconds)
124117
REFETCH_INTERVAL= # default 60
118+
119+
##################################
120+
# Special for Docker Compose
121+
##################################
122+
123+
# This determines the issuer of the JWT token. In the Playwright tests, and when using the
124+
# API in the Docker container locally, this should be set to "http://keycloak:8080".
125+
KC_HOSTNAME= # by default resolves to http://localhost:8083

.github/workflows/playwright.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,9 @@ 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
20+
#NEXTAUTH_URL: http://localhost:3000
2921
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
30-
NEXT_PUBLIC_API_URL: http://localhost:3001/api/
22+
#NEXT_PUBLIC_API_URL: http://localhost:3001/api/
3123
steps:
3224
- uses: actions/checkout@v4
3325
- uses: actions/setup-node@v4
@@ -36,19 +28,18 @@ jobs:
3628
cache: "npm"
3729
- name: Install dependencies
3830
run: npm ci
39-
- name: Install Playwright Browsers
40-
working-directory: apps/clearance_ui
41-
run: npx playwright install --with-deps
4231
- name: Run prisma generate
4332
run: npm run db:generate
44-
- name: Build project
45-
run: npm run build
33+
#- name: Build project
34+
# run: npm run build
4635
- name: Start the testing environment
47-
run: docker compose up -d
36+
run: docker compose up postgres minio createbuckets run-migrations -d
4837
- name: Seed the database and populate the spaces bucket
4938
run: npm run db:migrate:reset
50-
- name: Run Playwright tests
51-
run: npm run test:e2e
39+
- name: Start
40+
run: docker compose up --abort-on-container-exit --exit-code-from playwright-tests
41+
#- name: Run Playwright tests
42+
# run: npm run test:e2e
5243
- name: Print Docker Compose logs
5344
run: docker compose logs
5445
if: failure()

Playwright.Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
RUN npm run build:cui
29+
30+
# Install browsers for UI tests
31+
WORKDIR /workspace/apps/clearance_ui
32+
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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 */

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ export default defineConfig({
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"]');

docker-compose.yml

Lines changed: 32 additions & 13 deletions
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:3002
120117
- SPACES_ENDPOINT=http://minio:9000
121118
- REDIS_URL=redis://redis:6379
122119
- PORT=3001
@@ -138,6 +135,12 @@ services:
138135
minio:
139136
condition: service_healthy
140137
required: true
138+
keycloak:
139+
condition: service_healthy
140+
required: true
141+
terraform:
142+
condition: service_completed_successfully
143+
required: true
141144

142145
scanner-worker:
143146
build:
@@ -154,17 +157,33 @@ services:
154157
build:
155158
dockerfile: UI.Dockerfile
156159
args:
157-
- NEXT_PUBLIC_API_URL=http://localhost:3001/api/
160+
- NEXT_PUBLIC_API_URL=http://api:3001/api/
158161
environment:
159162
- NEXTAUTH_URL=http://localhost:3002
160163
- 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
164+
- KEYCLOAK_URL=http://keycloak:8080
165+
166+
playwright-tests:
167+
build:
168+
context: .
169+
dockerfile: Playwright.Dockerfile
170+
environment:
171+
- KEYCLOAK_URL=http://keycloak:8080
172+
- E2E_API_BASE_URL=http://api:3001
173+
- E2E_UI_BASE_URL=http://localhost:3002
174+
depends_on:
175+
api:
176+
condition: service_healthy
177+
clearance-ui:
178+
condition: service_started
179+
working_dir: /workspace
180+
command: >
181+
bash -c "
182+
echo 'Waiting for services...';
183+
until curl -s http://api:3001/api/health; do echo 'Waiting for API...'; sleep 2; done;
184+
echo 'API is up!';
185+
npm run test:e2e;
186+
"
168187
169188
volumes:
170189
db-data:

0 commit comments

Comments
 (0)