diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ffdd54bb..d202c549 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -25,27 +25,32 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - # e2e-tests: - # needs: [unit-tests] - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v4 - # - uses: actions/setup-node@v4 - # with: - # node-version: 20 - # - run: npm --prefix users/authservice install - # - run: npm --prefix users/userservice install - # - run: npm --prefix gatewayservice install - # - run: npm --prefix webapp install - # - run: npm --prefix webapp run build - # - run: npm --prefix webapp run test:e2e + e2e-tests: + needs: [unit-tests] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - run: npm --prefix users/authservice install + - run: npm --prefix users/userservice install + - run: npm --prefix gatewayservice install + - run: npm --prefix game/gameservice install + - run: npm --prefix game/groupservice install + - run: npm --prefix game/qgservice install + - run: npm --prefix multiplayerservice install + - run: npm --prefix webapp install + - run: npm --prefix webapp run build + - run: npm --prefix webapp run test:e2e + docker-push-webapp: name: Push webapp Docker Image to GitHub Packages runs-on: ubuntu-latest permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -69,7 +74,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -87,7 +92,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -105,7 +110,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -123,7 +128,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -141,7 +146,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -162,7 +167,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry @@ -180,7 +185,7 @@ jobs: permissions: contents: read packages: write - needs: [unit-tests] + needs: [e2e-tests] steps: - uses: actions/checkout@v4 - name: Publish to Registry diff --git a/webapp/e2e/features/register-form.feature b/webapp/e2e/features/register-form.feature index aad790a5..0c588ad8 100644 --- a/webapp/e2e/features/register-form.feature +++ b/webapp/e2e/features/register-form.feature @@ -3,4 +3,4 @@ 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 Should be inside the game route \ No newline at end of file diff --git a/webapp/e2e/singlePlayer.js b/webapp/e2e/singlePlayer.js deleted file mode 100644 index 103869f0..00000000 --- a/webapp/e2e/singlePlayer.js +++ /dev/null @@ -1,71 +0,0 @@ - -const puppeteer = require('puppeteer'); - -function delay(time) { - return new Promise(function(resolve) { - setTimeout(resolve, time) - }); -} - -(async () => { - // Abrir un navegador Puppeteer - const browser = await puppeteer.launch({ headless: false }); - const page = await browser.newPage(); - const timeout = 5000; - - // Configurar un tiempo de espera predeterminado para las acciones de la página - page.setDefaultTimeout(timeout); - - // Ir a la página de inicio de sesión - await page.goto('http://localhost:3000/'); - - // Esperar a que aparezca el botón de inicio de sesión y hacer clic en él - await page.waitForSelector('button.MuiButtonBase-root:nth-child(2)'); - await page.click('button.MuiButtonBase-root:nth-child(2)'); - - // Esperar a que aparezca el campo de nombre de usuario, escribir el nombre de usuario y esperar - await page.waitForSelector('div.MuiFormControl-root:nth-child(2) > div:nth-child(2)'); - await page.click('div.MuiFormControl-root:nth-child(2) > div:nth-child(2)'); // Hacer clic en el campo de usuario - await page.type('div.MuiFormControl-root:nth-child(2) > div:nth-child(2)', 'PabloS',{ delay: 100 }); - - // Esperar a que aparezca el campo de contraseña, escribir la contraseña y esperar - await page.waitForSelector('div.MuiFormControl-root:nth-child(3) > div:nth-child(2)'); - await page.click('div.MuiFormControl-root:nth-child(3) > div:nth-child(2)'); // Hacer clic en el campo de contraseña - await page.type('div.MuiFormControl-root:nth-child(3) > div:nth-child(2)', 'PabloPassword',{ delay: 100 }); - - // Esperar a que aparezca el botón de inicio de sesión y hacer clic en él - await page.waitForSelector('button.MuiButtonBase-root:nth-child(1)'); - await page.click('button.MuiButtonBase-root:nth-child(1)'); - - // Esperar a que aparezca el botón de juego individual y hacer clic en él - await page.waitForSelector('a.game-page-button:nth-child(1)'); - await page.click('a.game-page-button:nth-child(1)'); - - // Esperar a que aparezca el botón "add bot" y hacer clic en él - await page.waitForSelector('.add-bot-button'); - await page.click('.add-bot-button'); - await delay(6000); - // Esperar a que aparezca el botón "start game" y hacer clic en él - await page.waitForSelector('.start-game-button'); - await page.click('.start-game-button'); - await delay(1500); - // Selector base para el botón de respuesta - const answerSelector = '.answer-grid > button:nth-child'; - - // Hacer clic en el botón de respuesta 13 veces utilizando un bucle for - for (let i = 1; i <= 13; i++) { - const fullSelector = `${answerSelector}(${1})`; // Selector completo para cada botón de respuesta - await page.waitForSelector(fullSelector); // Esperar a que aparezca el botón de respuesta actual - await page.click(fullSelector); // Hacer clic en el botón de respuesta actual - console.log('Clicked answer', i); // Imprimir un mensaje en la consola - await delay(5000); - - } - - // Cerrar el navegador - await browser.close(); - -})().catch(err => { - console.error(err); - process.exit(1); -}); diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/register-form.steps.js index d80bd443..02190835 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/register-form.steps.js @@ -29,8 +29,8 @@ defineFeature(feature, test => { let password; given('An unregistered user', async () => { - username = "pablo" - password = "pabloasw" + username = "conoceryvenceruser" + password = "conoceryvencerpass" await page.waitFor('button') await page.click("button", {id: "registerButton"}); }); @@ -41,11 +41,9 @@ defineFeature(feature, test => { await page.click('button', { text: 'Add User' }) }); - then('A confirmation message should be shown in the screen', async () => { - const confirmationMessage = await page.waitForSelector('div',"#successUserAdd"); - - const messageText = await page.evaluate(confirmationMessage => confirmationMessage.innerText, confirmationMessage); - expect(messageText).toContain('User added successfully'); + then('Should be inside the game route', async () => { + await page.waitForSelector('div', '.game-container'); + expect(page.url()).toContain('/game'); }); }) diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 7b7ed511..a4091ea3 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -1,19 +1,19 @@ const { MongoMemoryServer } = require('mongodb-memory-server'); -let mongoserver; -let userservice; -let authservice; -let gatewayservice; async function startServer() { console.log('Starting MongoDB memory server...'); - mongoserver = await MongoMemoryServer.create(); + const 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"); + require("../../users/userservice/user-service"); + require("../../users/authservice/auth-service"); + require("../../gatewayservice/gateway-service"); + require("../../game/gameservice/gameservice"); + require("../../game/groupservice/group-service"); + require("../../game/qgservice/qg-service"); + require("../../multiplayerservice/server") } startServer(); diff --git a/webapp/package.json b/webapp/package.json index 24f7cfed..9bf06060 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -32,7 +32,7 @@ "build": "react-scripts build", "prod": "cross-env REACT_APP_API_ENDPOINT=http://localhost:8000 REACT_APP_MULTIPLAYER_ENDPOINT=http://localhost:8006 serve -s build -l 80", "test": "react-scripts test --silent --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:8000/health prod 80 \"cd e2e && jest\"", "eject": "react-scripts eject", "test-only:e2e": "cd e2e && jest" },