diff --git a/docs/images/add100Users.png b/docs/images/add100Users.png new file mode 100644 index 00000000..d220ecdf Binary files /dev/null and b/docs/images/add100Users.png differ diff --git a/docs/images/add1User.png b/docs/images/add1User.png new file mode 100644 index 00000000..b04bf071 Binary files /dev/null and b/docs/images/add1User.png differ diff --git a/docs/images/playGame1.png b/docs/images/playGame1.png new file mode 100644 index 00000000..5deb03b8 Binary files /dev/null and b/docs/images/playGame1.png differ diff --git a/docs/images/playGame20.png b/docs/images/playGame20.png new file mode 100644 index 00000000..46edd6a2 Binary files /dev/null and b/docs/images/playGame20.png differ diff --git a/docs/src/13_testability.adoc b/docs/src/13_testability.adoc index 81074e2f..1907bfd4 100644 --- a/docs/src/13_testability.adoc +++ b/docs/src/13_testability.adoc @@ -5,3 +5,30 @@ ifndef::imagesdir[:imagesdir: ../images] Testability is a crucial aspect of software development. It refers to the ease with which a software system can be tested to ensure its correctness and reliability. By writing tests, developers can verify that their code behaves as expected and identify any potential issues or bugs. There are various types of tests that can be performed, such as unit tests, integration tests, and end-to-end tests. Unit tests focus on testing individual components or functions in isolation, while integration tests verify the interaction between different components. End-to-end tests simulate real-world scenarios to ensure the entire system functions correctly. To achieve good testability, it is important to write code that is modular, decoupled, and follows best practices such as dependency injection. Additionally, using testing frameworks and tools can simplify the process of writing and executing tests. + + +=== Load Testing +These tests will focus on evaluating the performance of our system under high traffic and heavy usage conditions. This type of testing is crucial to identify bottlenecks and ensure that our application can effectively handle the volume of users and transactions expected in production, without compromising performance and stability. + + +Initially, a test was carried out with the following procedure: +1. Create a new user +2. Log in with this new user +3. View the main page + +image::add1User.png[title="1 User"] +image::add20Users.png[title="20 User"] +image::add100Users.png[title="100 User"] + + +Then, a slightly more complex test was then performed, which followed the following procedure: +1. Log in to the app +2. View the main page +3. Play a new game +4. View the game history +5. View the previous game specific data +6. View the history of questions + +image::playGame1.png[title="1 User"] +image::playGame20.png[title="20 User"] +image::playGame100.png[title="100 User"] diff --git a/docs/src/add20Users.png b/docs/src/add20Users.png new file mode 100644 index 00000000..8877e760 Binary files /dev/null and b/docs/src/add20Users.png differ diff --git a/docs/src/playGame100.png b/docs/src/playGame100.png new file mode 100644 index 00000000..64e194d8 Binary files /dev/null and b/docs/src/playGame100.png differ diff --git a/webapp/AddUserSimulation.class b/webapp/AddUserSimulation.class new file mode 100644 index 00000000..96a0b360 Binary files /dev/null and b/webapp/AddUserSimulation.class differ diff --git a/webapp/PlayGameSimulation.class b/webapp/PlayGameSimulation.class new file mode 100644 index 00000000..bcbe2df9 Binary files /dev/null and b/webapp/PlayGameSimulation.class differ diff --git a/webapp/e2e/features/historial-form.feature b/webapp/e2e/features/historial-form.feature new file mode 100644 index 00000000..abcf4554 --- /dev/null +++ b/webapp/e2e/features/historial-form.feature @@ -0,0 +1,11 @@ +Feature: Visible user logged history + +Scenario: The user is not loged in the site + Given A not loged user + When Press history + Then Redirected to login + +Scenario: The user register in the site so he can see history + Given A unregistered user, fill the register + When I press history + Then I see my history \ No newline at end of file diff --git a/webapp/e2e/steps/historial-form.steps.js b/webapp/e2e/steps/historial-form.steps.js new file mode 100644 index 00000000..2f8d1f3d --- /dev/null +++ b/webapp/e2e/steps/historial-form.steps.js @@ -0,0 +1,85 @@ +const puppeteer = require('puppeteer'); +const { defineFeature, loadFeature }=require('jest-cucumber'); +const setDefaultOptions = require('expect-puppeteer').setDefaultOptions +const feature = loadFeature('./features/historial-form.feature'); + +let page; +let browser; + +defineFeature(feature, test => { + + let username = ""; + let password = ""; + + beforeAll(async () => { + browser = process.env.GITHUB_ACTIONS + ? await puppeteer.launch() + : await puppeteer.launch({ headless: false, slowMo: 100 }); + page = await browser.newPage(); + //Way of setting up the timeout + setDefaultOptions({ timeout: 10000 }) + + await page + .goto("http://localhost:3000/", { + waitUntil: "networkidle0", + }) + .catch(() => {}); + }); + + test('The user is not logged in the site', ({given,when,then}) => { + + given('A not logged user', async () => { + username = "pablo"; + password = "12345"; + }); + + when('Press history', async () => { + await page.goto("http://localhost:3000/getgamehistory", { + waitUntil: "networkidle0", + }).catch(() => {}); + }); + + then('Redirected to login', async () => { + await expect(page).toMatchElement('button[title="entrar"]'); + }); + },300000); + + + test('The user is not registered in the site', ({given,when,then}) => { + + + given('A unregistered user, fill the register', async () => { + await page.goto("http://localhost:3000/sign-up", { + waitUntil: "networkidle0", + }).catch(() => {}); + //Registrar al user + await expect(page).toFill('input[name="username"]', username); + await expect(page).toFill('input[name="password"]', password); + await expect(page).toClick('button[name="registrarsePage"]'); + await page.waitForNavigation({ + waitUntil: 'networkidle0' + }); + }); + + when('I fill the data in the form and press submit', async () => { + await page.waitForSelector('[data-testid="historial-user"]', { + visible: true, + }); + await page.click('[data-testid="historial-user"]'); + }); + + then('I see my history', async () => { + await expect(page).toMatchElement('th', { text: 'Fecha'}); + await expect(page).toMatchElement('th', { text: 'Tiempo de partida'}); + await expect(page).toMatchElement('th', { text: 'Porcentaje de aciertos'}); + await expect(page).toMatchElement('th', { text: 'Número de preguntas'}); + await expect(page).toMatchElement('th', { text: 'Número de aciertos'}); + await expect(page).toMatchElement('th', { text: 'Número de fallos'}); + }); + },300000); + + afterAll(async ()=>{ + browser.close() + }) + +}); \ No newline at end of file diff --git a/webapp/e2e/test-environment-setup.js b/webapp/e2e/test-environment-setup.js index 7b7ed511..430c0b4d 100644 --- a/webapp/e2e/test-environment-setup.js +++ b/webapp/e2e/test-environment-setup.js @@ -5,15 +5,21 @@ let mongoserver; let userservice; let authservice; let gatewayservice; +let questionservice; +let questionhistoryservice; async function startServer() { console.log('Starting MongoDB memory server...'); mongoserver = await MongoMemoryServer.create(); const mongoUri = mongoserver.getUri(); process.env.MONGODB_URI = mongoUri; + process.env.SECRET_KEY = '123456789'; + console.log(process.env.MONGODB_URI) userservice = await require("../../users/userservice/user-service"); authservice = await require("../../users/authservice/auth-service"); gatewayservice = await require("../../gatewayservice/gateway-service"); + questionservice = await require("../../questions/creationservice"); + questionhistoryservice = await require("../../questions/retrieveservice"); } startServer();