From a3b813506d64f9a0bfc8a40e9270a74375d52eb4 Mon Sep 17 00:00:00 2001 From: algarfer Date: Sat, 20 Apr 2024 15:34:50 +0200 Subject: [PATCH 1/6] Dockerfile's security hotspots fixed --- gatewayservice/Dockerfile | 4 ++-- jordi/Dockerfile | 4 ++-- userhistory/Dockerfile | 4 ++-- users/authservice/Dockerfile | 4 ++-- users/userservice/Dockerfile | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gatewayservice/Dockerfile b/gatewayservice/Dockerfile index d789b3cd..d45fb05b 100644 --- a/gatewayservice/Dockerfile +++ b/gatewayservice/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt-get install apt-transport-https +RUN apt install apt-transport-https -y --no-install-recommends RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt-get update && apt-get install filebeat +RUN apt update && apt install filebeat -y --no-install-recommends COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/jordi/Dockerfile b/jordi/Dockerfile index ccbc539e..b367782f 100644 --- a/jordi/Dockerfile +++ b/jordi/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt-get install apt-transport-https +RUN apt install apt-transport-https -y --no-install-recommends RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt-get update && apt-get install filebeat +RUN apt update && apt install filebeat -y --no-install-recommends COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/userhistory/Dockerfile b/userhistory/Dockerfile index b4549407..6f05fed6 100644 --- a/userhistory/Dockerfile +++ b/userhistory/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt-get install apt-transport-https +RUN apt install apt-transport-https -y --no-install-recommends RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt-get update && apt-get install filebeat +RUN apt update && apt install filebeat -y --no-install-recommends COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/users/authservice/Dockerfile b/users/authservice/Dockerfile index 8f50e162..b51a520d 100644 --- a/users/authservice/Dockerfile +++ b/users/authservice/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt-get install apt-transport-https +RUN apt install apt-transport-https -y --no-install-recommends RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt-get update && apt-get install filebeat +RUN apt update && apt install filebeat -y --no-install-recommends COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/users/userservice/Dockerfile b/users/userservice/Dockerfile index c56b97f6..606f84e8 100644 --- a/users/userservice/Dockerfile +++ b/users/userservice/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt-get install apt-transport-https +RUN apt install apt-transport-https -y --no-install-recommends RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt-get update && apt-get install filebeat +RUN apt update && apt install filebeat -y --no-install-recommends COPY filebeat.yml /etc/filebeat/filebeat.yml From 5ae5ad23de79638e46bbaa55214bcb3406d95f52 Mon Sep 17 00:00:00 2001 From: algarfer Date: Sat, 20 Apr 2024 16:35:34 +0200 Subject: [PATCH 2/6] Fixed duplicated code on tests --- sonar-project.properties | 1 + webapp/src/__test__/Account.test.js | 15 ++------------- webapp/src/__test__/Error.test.js | 17 ++--------------- webapp/src/__test__/Login.test.js | 13 +------------ webapp/src/__test__/Menu.test.js | 15 ++------------- webapp/src/__test__/Signup.test.js | 13 +------------ .../src/__test__/components/SaveList.test.js | 13 +------------ webapp/src/__test__/utils/localStorageMock.js | 18 ++++++++++++++++++ 8 files changed, 28 insertions(+), 77 deletions(-) create mode 100644 webapp/src/__test__/utils/localStorageMock.js diff --git a/sonar-project.properties b/sonar-project.properties index b491886f..1b9197f0 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -11,6 +11,7 @@ sonar.language=js sonar.projectName=wiq_es05b sonar.coverage.exclusions=**/*.test.js +sonar.cpd.exclusions=**/*.test.js sonar.sources=users/authservice,users/userservice,gatewayservice,webapp/src,userhistory,jordi sonar.sourceEncoding=UTF-8 sonar.exclusions=node_modules/** diff --git a/webapp/src/__test__/Account.test.js b/webapp/src/__test__/Account.test.js index 6e5ca174..10fb3d8b 100644 --- a/webapp/src/__test__/Account.test.js +++ b/webapp/src/__test__/Account.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, screen, waitFor, act } from '@testing-library/react'; +import { render, screen, waitFor, act } from '@testing-library/react'; import axios from 'axios'; import Account from '../views/Account.jsx'; import { AuthContext } from "../views/context/AuthContext.jsx"; @@ -9,18 +9,7 @@ import '@testing-library/jest-dom'; jest.mock('axios'); jest.mock('../views/context/AuthContext'); - -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); +require("./utils/localStorageMock")() // Configura una implementación simulada de axios jest.mock('../App.jsx', () => ({ diff --git a/webapp/src/__test__/Error.test.js b/webapp/src/__test__/Error.test.js index fb82d701..173b321c 100644 --- a/webapp/src/__test__/Error.test.js +++ b/webapp/src/__test__/Error.test.js @@ -1,27 +1,14 @@ import React from 'react'; -import { render, fireEvent, screen, waitFor, act } from '@testing-library/react'; +import { render, screen, act } from '@testing-library/react'; import '@testing-library/jest-dom'; -import axios from 'axios'; import Error from '../views/Error.jsx'; import { useAuth } from "../App.jsx"; import { AuthContext } from "../views/context/AuthContext.jsx"; import {MemoryRouter} from "react-router"; -import Menu from "../views/Menu"; jest.mock('axios'); jest.mock('../views/context/AuthContext'); - -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); +require("./utils/localStorageMock")() jest.mock('../App.jsx', () => ({ useAuth: jest.fn().mockReturnValue({ diff --git a/webapp/src/__test__/Login.test.js b/webapp/src/__test__/Login.test.js index eee29171..bd4cba49 100644 --- a/webapp/src/__test__/Login.test.js +++ b/webapp/src/__test__/Login.test.js @@ -9,18 +9,7 @@ import '@testing-library/jest-dom'; jest.mock('axios'); jest.mock('../views/context/AuthContext'); - -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); +require("./utils/localStorageMock")() // Configura una implementación simulada de axios jest.mock('../App.jsx', () => ({ diff --git a/webapp/src/__test__/Menu.test.js b/webapp/src/__test__/Menu.test.js index 2e96b348..dae2e762 100644 --- a/webapp/src/__test__/Menu.test.js +++ b/webapp/src/__test__/Menu.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, fireEvent, screen, waitFor, act } from '@testing-library/react'; +import { render, screen, waitFor, act } from '@testing-library/react'; import axios from 'axios'; import Menu from '../views/Menu.jsx'; import { AuthContext } from "../views/context/AuthContext"; @@ -9,18 +9,7 @@ import '@testing-library/jest-dom'; jest.mock('axios'); jest.mock('../views/context/AuthContext'); - -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); +require("./utils/localStorageMock")() // Configura una implementación simulada de axios jest.mock('../App.jsx', () => ({ diff --git a/webapp/src/__test__/Signup.test.js b/webapp/src/__test__/Signup.test.js index f8c01e30..337e59b9 100644 --- a/webapp/src/__test__/Signup.test.js +++ b/webapp/src/__test__/Signup.test.js @@ -9,18 +9,7 @@ import '@testing-library/jest-dom'; jest.mock('axios'); jest.mock('../views/context/AuthContext'); - -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); +require("./utils/localStorageMock")() // Configura una implementación simulada de axios jest.mock('../App.jsx', () => ({ diff --git a/webapp/src/__test__/components/SaveList.test.js b/webapp/src/__test__/components/SaveList.test.js index a1bbdc34..62206cc7 100644 --- a/webapp/src/__test__/components/SaveList.test.js +++ b/webapp/src/__test__/components/SaveList.test.js @@ -8,18 +8,7 @@ import { MemoryRouter } from "react-router"; jest.mock('axios'); jest.mock('../../views/context/AuthContext'); - -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); - -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); +require("../utils/localStorageMock")() describe('SaveList component', () => { const mockSaves = [ diff --git a/webapp/src/__test__/utils/localStorageMock.js b/webapp/src/__test__/utils/localStorageMock.js new file mode 100644 index 00000000..e71403d1 --- /dev/null +++ b/webapp/src/__test__/utils/localStorageMock.js @@ -0,0 +1,18 @@ +const localStorageMock = (() => { + let store = {}; + Object.defineProperty(window, 'localStorage', {value: localStorageMock}); + return { + getItem: key => store[key], + setItem: (key, value) => { + store[key] = value + }, + removeItem: key => { + delete store[key] + }, + clear: () => { + store = {} + } + }; +}); + +module.exports = localStorageMock; \ No newline at end of file From 2a1b35ed6011f3b320be7765353f6001a60a5ea9 Mon Sep 17 00:00:00 2001 From: algarfer Date: Sat, 20 Apr 2024 17:27:31 +0200 Subject: [PATCH 3/6] Fixed apt cache dockerfiles --- gatewayservice/Dockerfile | 4 ++-- jordi/Dockerfile | 4 ++-- userhistory/Dockerfile | 4 ++-- users/authservice/Dockerfile | 4 ++-- users/userservice/Dockerfile | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gatewayservice/Dockerfile b/gatewayservice/Dockerfile index d45fb05b..ecc8d18a 100644 --- a/gatewayservice/Dockerfile +++ b/gatewayservice/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt install apt-transport-https -y --no-install-recommends +RUN apt install apt-transport-https -y --no-install-recommends && apt clean RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt update && apt install filebeat -y --no-install-recommends +RUN apt update && apt install filebeat -y --no-install-recommends && apt clean COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/jordi/Dockerfile b/jordi/Dockerfile index b367782f..4a8d9641 100644 --- a/jordi/Dockerfile +++ b/jordi/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt install apt-transport-https -y --no-install-recommends +RUN apt install apt-transport-https -y --no-install-recommends && apt clean RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt update && apt install filebeat -y --no-install-recommends +RUN apt update && apt install filebeat -y --no-install-recommends && apt clean COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/userhistory/Dockerfile b/userhistory/Dockerfile index 6f05fed6..cf2f03f7 100644 --- a/userhistory/Dockerfile +++ b/userhistory/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt install apt-transport-https -y --no-install-recommends +RUN apt install apt-transport-https -y --no-install-recommends && apt clean RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt update && apt install filebeat -y --no-install-recommends +RUN apt update && apt install filebeat -y --no-install-recommends && apt clean COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/users/authservice/Dockerfile b/users/authservice/Dockerfile index b51a520d..8e9d9091 100644 --- a/users/authservice/Dockerfile +++ b/users/authservice/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt install apt-transport-https -y --no-install-recommends +RUN apt install apt-transport-https -y --no-install-recommends && apt clean RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt update && apt install filebeat -y --no-install-recommends +RUN apt update && apt install filebeat -y --no-install-recommends && apt clean COPY filebeat.yml /etc/filebeat/filebeat.yml diff --git a/users/userservice/Dockerfile b/users/userservice/Dockerfile index 606f84e8..9f4072d6 100644 --- a/users/userservice/Dockerfile +++ b/users/userservice/Dockerfile @@ -2,9 +2,9 @@ FROM node:20 RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add - -RUN apt install apt-transport-https -y --no-install-recommends +RUN apt install apt-transport-https -y --no-install-recommends && apt clean RUN echo "deb https://artifacts.elastic.co/packages/8.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-8.x.list -RUN apt update && apt install filebeat -y --no-install-recommends +RUN apt update && apt install filebeat -y --no-install-recommends && apt clean COPY filebeat.yml /etc/filebeat/filebeat.yml From ae85f34b80129c69403524680f1ba2862013d0eb Mon Sep 17 00:00:00 2001 From: algarfer Date: Sat, 20 Apr 2024 17:27:58 +0200 Subject: [PATCH 4/6] Removed unnecessary dependency --- gatewayservice/gateway-service.js | 1 - gatewayservice/package-lock.json | 21 --------------------- gatewayservice/package.json | 1 - 3 files changed, 23 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 6f859df6..19350cc2 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -1,5 +1,4 @@ const express = require('express'); -const cors = require('cors'); const promBundle = require('express-prom-bundle'); const axios = require('axios'); const { loggerFactory, requestLoggerMiddleware, responseLoggerMiddleware, errorHandlerMiddleware } = require("cyt-utils") diff --git a/gatewayservice/package-lock.json b/gatewayservice/package-lock.json index 7182d60d..3778ca2c 100644 --- a/gatewayservice/package-lock.json +++ b/gatewayservice/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "dependencies": { "axios": "^1.6.5", - "cors": "^2.8.5", "cyt-utils": "*2.0.9", "express": "^4.18.2", "express-openapi": "^12.1.3", @@ -1851,18 +1850,6 @@ "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", "dev": true }, - "node_modules/cors": { - "version": "2.8.5", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", - "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - } - }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -3785,14 +3772,6 @@ "node": ">=8" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", diff --git a/gatewayservice/package.json b/gatewayservice/package.json index 213256a2..749b70f8 100644 --- a/gatewayservice/package.json +++ b/gatewayservice/package.json @@ -20,7 +20,6 @@ "homepage": "https://github.com/arquisoft/wiq_es05b#readme", "dependencies": { "axios": "^1.6.5", - "cors": "^2.8.5", "cyt-utils": "*2.0.9", "express": "^4.18.2", "express-openapi": "^12.1.3", From 55c8799517cbfbdeeca22d1e3402b17902577ffd Mon Sep 17 00:00:00 2001 From: algarfer Date: Sat, 20 Apr 2024 17:40:30 +0200 Subject: [PATCH 5/6] Fixed sonarcloud issues --- gatewayservice/gateway-service.js | 2 +- sonar-project.properties | 4 ++-- .../__test__/components/CustomForm.test.js | 2 +- .../__test__/components/ErrorSnackBar.test.js | 1 - webapp/src/__test__/components/Nav.draft.js | 16 +------------- webapp/src/views/Game.jsx | 21 +++++++++++-------- webapp/src/views/components/Footer.jsx | 2 +- 7 files changed, 18 insertions(+), 30 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 19350cc2..1328fa39 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -41,7 +41,7 @@ require("./routes/authRoutes")(app, axios) require("./routes/historyRoutes")(app, axios, authTokenMiddleware) // Open API -openapiPath='./GatewayAPI.yaml' +const openapiPath='./GatewayAPI.yaml' if (fs.existsSync(openapiPath)) { const file = fs.readFileSync(openapiPath, 'utf8'); diff --git a/sonar-project.properties b/sonar-project.properties index 1b9197f0..05da4bd9 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -10,8 +10,8 @@ sonar.host.url=https://sonarcloud.io sonar.language=js sonar.projectName=wiq_es05b -sonar.coverage.exclusions=**/*.test.js -sonar.cpd.exclusions=**/*.test.js +sonar.coverage.exclusions=**/*.test.js,**/*.draft.js +sonar.cpd.exclusions=**/*.test.js,**/*.draft.js sonar.sources=users/authservice,users/userservice,gatewayservice,webapp/src,userhistory,jordi sonar.sourceEncoding=UTF-8 sonar.exclusions=node_modules/** diff --git a/webapp/src/__test__/components/CustomForm.test.js b/webapp/src/__test__/components/CustomForm.test.js index 648d8894..2e46b153 100644 --- a/webapp/src/__test__/components/CustomForm.test.js +++ b/webapp/src/__test__/components/CustomForm.test.js @@ -1,5 +1,5 @@ import React from "react"; -import { render, fireEvent, screen } from "@testing-library/react"; +import { render, screen } from "@testing-library/react"; import { MemoryRouter } from "react-router-dom"; import CustomForm from "../../views/components/CustomForm"; import '@testing-library/jest-dom'; diff --git a/webapp/src/__test__/components/ErrorSnackBar.test.js b/webapp/src/__test__/components/ErrorSnackBar.test.js index 597746ac..e7764f82 100644 --- a/webapp/src/__test__/components/ErrorSnackBar.test.js +++ b/webapp/src/__test__/components/ErrorSnackBar.test.js @@ -1,7 +1,6 @@ import React from "react"; import { render, fireEvent, screen } from "@testing-library/react"; import ErrorSnackBar from "../../views/components/ErrorSnackBar"; -import { Snackbar } from "@mui/material"; import '@testing-library/jest-dom'; describe("ErrorSnackBar component", () => { diff --git a/webapp/src/__test__/components/Nav.draft.js b/webapp/src/__test__/components/Nav.draft.js index 8c524ccc..014375f1 100644 --- a/webapp/src/__test__/components/Nav.draft.js +++ b/webapp/src/__test__/components/Nav.draft.js @@ -1,28 +1,15 @@ -/* import React from "react"; import {render, screen, fireEvent, act} from "@testing-library/react"; import Nav from "../../views/components/Nav"; import {AuthContext} from "../../views/context/AuthContext"; import {MemoryRouter} from "react-router"; -import Menu from "../../views/Menu"; import { useAuth } from "../../App.jsx"; -import axios from "axios"; -import { ConfigContext } from '../../views/context/ConfigContext'; jest.mock('axios'); jest.mock('../../views/context/AuthContext'); -const localStorageMock = (() => { - let store = {}; - return { - getItem: key => store[key], - setItem: (key, value) => { store[key] = value }, - removeItem: key => { delete store[key] }, - clear: () => { store = {} } - }; -})(); +require("../utils/localStorageMock"); -Object.defineProperty(window, 'localStorage', { value: localStorageMock }); jest.mock('../../App.jsx', () => ({ useAuth: jest.fn().mockReturnValue({ getUser: jest.fn().mockReturnValue({ @@ -70,4 +57,3 @@ describe("Nav component", () => { expect(logoutMenuItem).toBeInTheDocument(); }); }); -*/ diff --git a/webapp/src/views/Game.jsx b/webapp/src/views/Game.jsx index b97423cc..fe9b3e39 100644 --- a/webapp/src/views/Game.jsx +++ b/webapp/src/views/Game.jsx @@ -208,15 +208,18 @@ const Game = () => { .catch(e => setHistorialError(e.response.data.error)) } - const createSave = () => { - axios - .post("/history/create", { - token: getUser().token, - category: category, - userId: getUser().userId - }) - .then(response => saveId.current = response.data.id) - .catch(err => setHistorialError(err.response.data.error)) + const createSave = async () => { + try { + const response = await axios + .post("/history/create", { + token: getUser().token, + category: category, + userId: getUser().userId + }) + saveId.current = response.data.id + } catch (err) { + setHistorialError(err.response.data.error) + } } useEffect( () => { diff --git a/webapp/src/views/components/Footer.jsx b/webapp/src/views/components/Footer.jsx index d663bb64..5e2d66fc 100644 --- a/webapp/src/views/components/Footer.jsx +++ b/webapp/src/views/components/Footer.jsx @@ -7,7 +7,7 @@ import { Container } from "@mui/material"; export default function Footer() { return ( - + © {new Date().getFullYear()} ASW - WIQ05b From 5b00213183d4151f42113886caa7d32293d7f1b9 Mon Sep 17 00:00:00 2001 From: algarfer Date: Sat, 20 Apr 2024 17:48:44 +0200 Subject: [PATCH 6/6] Fixed footer tests --- webapp/src/__test__/components/Footer.test.js | 6 +++--- webapp/src/views/components/Footer.jsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/src/__test__/components/Footer.test.js b/webapp/src/__test__/components/Footer.test.js index 95da4cc4..4d0e3861 100644 --- a/webapp/src/__test__/components/Footer.test.js +++ b/webapp/src/__test__/components/Footer.test.js @@ -9,14 +9,14 @@ describe("Footer component", () => { const currentYear = new Date().getFullYear(); expect(screen.getByText(`© ${currentYear} ASW - WIQ05b`)).toBeInTheDocument(); - expect(screen.getByRole("navigation")).toBeInTheDocument(); - const appBar = screen.getByRole("navigation"); + expect(screen.getByTestId("footer")).toBeInTheDocument(); + const appBar = screen.getByTestId("footer"); expect(appBar).toHaveStyle({ backgroundColor: "primary" }); }); test("has fixed position at the bottom of the page", () => { render(