Skip to content

Commit

Permalink
Merge pull request #158 from Arquisoft/develop-sonarcloud-fixes
Browse files Browse the repository at this point in the history
Fixed multiple sonarcloud issues
  • Loading branch information
algarfer authored Apr 20, 2024
2 parents 3aad7d3 + 5b00213 commit 7ac66d9
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 142 deletions.
4 changes: 2 additions & 2 deletions gatewayservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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-get update && apt-get install filebeat
RUN apt update && apt install filebeat -y --no-install-recommends && apt clean

COPY filebeat.yml /etc/filebeat/filebeat.yml

Expand Down
3 changes: 1 addition & 2 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -42,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');

Expand Down
21 changes: 0 additions & 21 deletions gatewayservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion gatewayservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions jordi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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-get update && apt-get install filebeat
RUN apt update && apt install filebeat -y --no-install-recommends && apt clean

COPY filebeat.yml /etc/filebeat/filebeat.yml

Expand Down
3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ sonar.host.url=https://sonarcloud.io
sonar.language=js
sonar.projectName=wiq_es05b

sonar.coverage.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/**
Expand Down
4 changes: 2 additions & 2 deletions userhistory/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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-get update && apt-get install filebeat
RUN apt update && apt install filebeat -y --no-install-recommends && apt clean

COPY filebeat.yml /etc/filebeat/filebeat.yml

Expand Down
4 changes: 2 additions & 2 deletions users/authservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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-get update && apt-get install filebeat
RUN apt update && apt install filebeat -y --no-install-recommends && apt clean

COPY filebeat.yml /etc/filebeat/filebeat.yml

Expand Down
4 changes: 2 additions & 2 deletions users/userservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && 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-get update && apt-get install filebeat
RUN apt update && apt install filebeat -y --no-install-recommends && apt clean

COPY filebeat.yml /etc/filebeat/filebeat.yml

Expand Down
15 changes: 2 additions & 13 deletions webapp/src/__test__/Account.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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', () => ({
Expand Down
17 changes: 2 additions & 15 deletions webapp/src/__test__/Error.test.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
13 changes: 1 addition & 12 deletions webapp/src/__test__/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down
15 changes: 2 additions & 13 deletions webapp/src/__test__/Menu.test.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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', () => ({
Expand Down
13 changes: 1 addition & 12 deletions webapp/src/__test__/Signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/__test__/components/CustomForm.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 0 additions & 1 deletion webapp/src/__test__/components/ErrorSnackBar.test.js
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/__test__/components/Footer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Footer />);
const appBar = screen.getByRole("navigation");
const appBar = screen.getByTestId("footer");
expect(appBar).toHaveStyle({ top: "auto", bottom: 0, position: "fixed" });
});

Expand Down
16 changes: 1 addition & 15 deletions webapp/src/__test__/components/Nav.draft.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -70,4 +57,3 @@ describe("Nav component", () => {
expect(logoutMenuItem).toBeInTheDocument();
});
});
*/
13 changes: 1 addition & 12 deletions webapp/src/__test__/components/SaveList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
18 changes: 18 additions & 0 deletions webapp/src/__test__/utils/localStorageMock.js
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 12 additions & 9 deletions webapp/src/views/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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( () => {
Expand Down
Loading

0 comments on commit 7ac66d9

Please sign in to comment.