diff --git a/Dockerfile b/Dockerfile index 56a3dae..30ed6b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,7 @@ COPY docker/entrypoint.sh /usr/local/bin/go-guess-entrypoint USER app EXPOSE 8080 -ENV ADDRESS=:8080 \ +ENV ADDRESS=:8081 \ APP_ENV=production \ FRONTEND_URL=http://localhost:8080 diff --git a/bdd/init.sql b/bdd/init.sql new file mode 100644 index 0000000..f078294 --- /dev/null +++ b/bdd/init.sql @@ -0,0 +1 @@ +CREATE SCHEMA ypto AUTHORIZATION go_guess; diff --git a/bdd/package.json b/bdd/package.json index 7e66231..30bb711 100644 --- a/bdd/package.json +++ b/bdd/package.json @@ -4,7 +4,7 @@ "version": "0.1.0", "type": "module", "scripts": { - "test": "cucumber-js --config cucumber.mjs" + "test": "node run-tests.js" }, "devDependencies": { "@cucumber/cucumber": "13.2.1", diff --git a/bdd/run-tests.js b/bdd/run-tests.js new file mode 100644 index 0000000..4be979a --- /dev/null +++ b/bdd/run-tests.js @@ -0,0 +1,29 @@ +import { spawn } from "node:child_process"; +import http from "node:http"; + +const authorizationServer = http.createServer((request, response) => { + response.setHeader("Content-Type", "application/json"); + response.end( + JSON.stringify({ + allowed: true, + tenant_slug: "ypto", + application_slug: "guess", + api_key_name: "bdd", + }), + ); +}); + +authorizationServer.listen(18081, "127.0.0.1", () => { + const cucumber = spawn("cucumber-js", ["--config", "cucumber.mjs"], { + stdio: "inherit", + }); + cucumber.on("exit", (code, signal) => { + authorizationServer.close(() => { + if (signal) { + process.kill(process.pid, signal); + } else { + process.exit(code ?? 1); + } + }); + }); +}); diff --git a/bdd/support/hooks.js b/bdd/support/hooks.js index c879600..81e96d5 100644 --- a/bdd/support/hooks.js +++ b/bdd/support/hooks.js @@ -6,6 +6,7 @@ setDefaultTimeout(Number(process.env.BDD_STEP_TIMEOUT_MS ?? 15000)); Before(async function () { this.browser = await chromium.launch({ headless: process.env.BDD_HEADLESS !== "false", + args: ["--host-resolver-rules=MAP ypto.guess.local 127.0.0.1"], }); this.context = await this.browser.newContext(); this.page = await this.context.newPage(); diff --git a/docker-compose.bdd.yml b/docker-compose.bdd.yml index 041c916..b8b0ef1 100644 --- a/docker-compose.bdd.yml +++ b/docker-compose.bdd.yml @@ -5,6 +5,8 @@ services: POSTGRES_DB: go_guess POSTGRES_USER: go_guess POSTGRES_PASSWORD: go_guess + volumes: + - ./bdd/init.sql:/docker-entrypoint-initdb.d/init.sql:ro healthcheck: test: ["CMD-SHELL", "pg_isready -U go_guess -d go_guess"] interval: 2s @@ -23,10 +25,13 @@ services: build: context: . dockerfile: Dockerfile + args: + VITE_GO_LOOSE_API_KEY: gl_bdd_key_that_is_long_enough_for_client environment: - DATABASE_URL: postgres://go_guess:go_guess@db:5432/go_guess?sslmode=disable + DATABASE_URL: postgres://go_guess:go_guess@db:5432/go_guess?sslmode=disable&search_path=ypto JWT_SECRET: bdd-test-secret-that-is-at-least-32-characters - FRONTEND_URL: http://app:8080 + FRONTEND_URL: http://ypto.guess.local:8080 + GO_LOOSE_BASE_URL: http://127.0.0.1:18081 RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ APP_ENV: test ports: @@ -47,7 +52,7 @@ services: context: bdd dockerfile: Dockerfile environment: - BDD_BASE_URL: http://127.0.0.1:8080 + BDD_BASE_URL: http://ypto.guess.local:8080 BDD_HEADLESS: "true" BDD_STEP_TIMEOUT_MS: "15000" network_mode: service:app diff --git a/docker/nginx.conf b/docker/nginx.conf index 8f80a29..86f7916 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -26,7 +26,7 @@ http { index index.html; location /api/ { - proxy_pass http://127.0.0.1:8080; + proxy_pass http://127.0.0.1:8081; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; diff --git a/frontend/src/app/App.test.tsx b/frontend/src/app/App.test.tsx index 347e68d..217f3a5 100644 --- a/frontend/src/app/App.test.tsx +++ b/frontend/src/app/App.test.tsx @@ -749,8 +749,8 @@ describe('Go Guess frontend', () => { renderApp('/jobs/7') await user.click(await screen.findByRole('tab', { name: /invitations/i })) await user.click(screen.getByRole('button', { name: 'Review answers' })) - await user.click(await screen.findByRole('button', { name: 'Pass candidate' })) - await user.click(screen.getByRole('button', { name: 'Fail candidate' })) + await user.click(await screen.findByRole('button', { name: 'Fail candidate' })) + await user.click(screen.getByRole('button', { name: 'Pass candidate' })) expect(fetch).toHaveBeenCalledWith( '/api/jobs/7/invitations/44/outcome',