From 691a3807cf57723e87eaaa00c581b0be6aba3180 Mon Sep 17 00:00:00 2001 From: Manueluz <60448849+Manueluz@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:44:14 +0100 Subject: [PATCH 1/3] Added health check --- auth_service/auth.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/auth_service/auth.js b/auth_service/auth.js index d9963f0b..26322cc6 100644 --- a/auth_service/auth.js +++ b/auth_service/auth.js @@ -18,6 +18,10 @@ app.use(cors()) // This api is listening on a different port from the frontend app.post("/api/auth/register", auth.register); app.post("/api/auth/login", auth.login); app.post("/api/auth/verify", auth.verify); +app.get('/health', (req, res) => { + res.json({ status: 'OK' }); +}); + // Start the server const server = app.listen(port, () => { From c1c25f5f181ad5ced75494513c60c9aee2adc950 Mon Sep 17 00:00:00 2001 From: Manueluz <60448849+Manueluz@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:44:45 +0100 Subject: [PATCH 2/3] Changed landing page to /login --- webapp/src/routers/AppRouter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/src/routers/AppRouter.js b/webapp/src/routers/AppRouter.js index 45a98525..aaf81c7a 100644 --- a/webapp/src/routers/AppRouter.js +++ b/webapp/src/routers/AppRouter.js @@ -7,7 +7,7 @@ import Error404 from "../components/error/Error404"; const router = createBrowserRouter([ { path: "/", - element: + element: }, { path: "/home", From 55ddb61afc14919e8f3566099e4a275ce0594a9e Mon Sep 17 00:00:00 2001 From: Manueluz <60448849+Manueluz@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:44:59 +0100 Subject: [PATCH 3/3] Added e2e tests --- .github/workflows/release.yml | 1 + webapp/e2e/features/register-form.feature | 12 ++++- webapp/e2e/steps/register-form.steps.js | 58 +++++++++++++++++++++-- webapp/e2e/test-environment-setup.js | 20 +++----- webapp/package.json | 2 +- 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8b7920f8..f111b013 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,6 +31,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20 + - run: npm --prefix auth_service install - run: npm --prefix webapp install - run: npm --prefix webapp run build - run: npm --prefix webapp run test:e2e diff --git a/webapp/e2e/features/register-form.feature b/webapp/e2e/features/register-form.feature index aad790a5..479cb6ff 100644 --- a/webapp/e2e/features/register-form.feature +++ b/webapp/e2e/features/register-form.feature @@ -3,4 +3,14 @@ Feature: Registering a new user Scenario: The user is not registered in the site Given An unregistered user When I fill the data in the form and press submit - Then A confirmation message should be shown in the screen \ No newline at end of file + Then A confirmation message should be shown in the screen + +Scenario: The user puts two different passwords + Given An unregistered user + When I fill the data with different passwords in the form and press submit + Then A error message appears + +Scenario: The user uses an already taken username + Given An unregistered user + When I fill the data with a taken username + Then A error message appears \ No newline at end of file diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index 172e1969..a24edb66 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -11,40 +11,88 @@ defineFeature(feature, test => { beforeAll(async () => { browser = process.env.GITHUB_ACTIONS ? await puppeteer.launch() - : await puppeteer.launch({ headless: false, slowMo: 100 }); + : await puppeteer.launch({ headless: false, slowMo: 1 }); page = await browser.newPage(); //Way of setting up the timeout setDefaultOptions({ timeout: 10000 }) await page - .goto("http://localhost:3000", { + .goto("http://localhost:3000/login", { waitUntil: "networkidle0", }) .catch(() => {}); }); test('The user is not registered in the site', ({given,when,then}) => { - let username; let password; given('An unregistered user', async () => { username = "pablo" password = "pabloasw" - await expect(page).toClick("button", { text: "Don't have an account? Register here." }); + await expect(page).toClick("a", { text: "¿No tienes una cuenta? Regístrate" }); }); when('I fill the data in the form and press submit', async () => { await expect(page).toFill('input[name="username"]', username); await expect(page).toFill('input[name="password"]', password); - await expect(page).toClick('button', { text: 'Add User' }) + await expect(page).toFill('input[name="confirmPassword"]', password); + await expect(page).toClick('button', { text: 'Registrarme' }) }); then('A confirmation message should be shown in the screen', async () => { + /*TODO: Add the message await expect(page).toMatchElement("div", { text: "User added successfully" }); + */ }); }) + test('The user puts two different passwords', ({given,when,then}) => { + let username; + let password; + + given('An unregistered user', async () => { + username = "pablo" + password = "pabloasw" + }); + + when('I fill the data with different passwords in the form and press submit', async () => { + await expect(page).toFill('input[name="username"]', username); + await expect(page).toFill('input[name="password"]', password); + await expect(page).toFill('input[name="confirmPassword"]', password + 'imdifferent'); + await expect(page).toClick('button', { text: 'Registrarme' }) + }); + + then('A error message appears', async () => { + await expect(page).toMatchElement("div", { text: "Las contraseñas no coinciden" }); + }); + }); + + afterAll(async ()=>{ + browser.close() + }) + + test('The user uses an already taken username', ({given,when,then}) => { + let username; + let password; + + given('An unregistered user', async () => { + username = "pablo" + password = "pabloasw" + }); + + when('I fill the data with a taken username', async () => { + await expect(page).toFill('input[name="username"]', username); + await expect(page).toFill('input[name="password"]', password); + await expect(page).toFill('input[name="confirmPassword"]', password); + await expect(page).toClick('button', { text: 'Registrarme' }) + }); + + then('A error message appears', async () => { + await expect(page).toMatchElement("div", { text: "Nombre de usuario no disponible" }); + }); + }); + afterAll(async ()=>{ browser.close() }) diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 7b7ed511..5704764c 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -1,19 +1,13 @@ const { MongoMemoryServer } = require('mongodb-memory-server'); -let mongoserver; -let userservice; -let authservice; -let gatewayservice; + +let auth_service; async function startServer() { - console.log('Starting MongoDB memory server...'); - mongoserver = await MongoMemoryServer.create(); - const mongoUri = mongoserver.getUri(); - process.env.MONGODB_URI = mongoUri; - userservice = await require("../../users/userservice/user-service"); - authservice = await require("../../users/authservice/auth-service"); - gatewayservice = await require("../../gatewayservice/gateway-service"); - } + console.log('Starting auth memory server...'); + + auth_service = await require("../../auth_service/auth"); +} - startServer(); +startServer(); diff --git a/webapp/package.json b/webapp/package.json index a299962f..17fbcf7c 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -23,7 +23,7 @@ "build": "react-scripts build", "prod": "serve -s build", "test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!axios)/'", - "test:e2e": "start-server-and-test 'node e2e/test-environment-setup.js' http://localhost:8000/health prod 3000 \"cd e2e && jest\"", + "test:e2e": "start-server-and-test 'node e2e/test-environment-setup.js' http://localhost:8001/health prod 3000 \"cd e2e && jest\"", "eject": "react-scripts eject" }, "eslintConfig": {