Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

update dev with master #285

Merged
merged 9 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ 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 auth_service 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 auth_service install
- run: npm --prefix game_service install
- run: npm --prefix userdetails_service install
- run: npm --prefix question_service install
- run: npm --prefix friends_service 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
Expand All @@ -67,7 +71,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [ e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -84,7 +88,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [ e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -101,7 +105,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [ e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -118,7 +122,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [ e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -135,7 +139,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [ e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -149,7 +153,7 @@ jobs:
deploy:
name: Deploy over SSH
runs-on: ubuntu-latest
needs: [docker-push-auth,docker-push-question,docker-push-userdetails,docker-push-webapp,docker-push-game]
needs: [docker-push-auth,docker-push-question,docker-push-userdetails,docker-push-webapp,docker-push-game,docker-push-friends]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
Expand All @@ -170,4 +174,4 @@ jobs:
wget https://raw.githubusercontent.com/arquisoft/wiq_es1c/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_es1c/master/.env -O .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
docker compose --profile prod up -d --pull always
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
friend:
restart: unless-stopped
container_name: friends-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1c/friend:latest
image: ghcr.io/arquisoft/wiq_es1c/friends:latest
profiles: ["dev", "prod"]
build: ./friends_service
environment:
Expand Down
3 changes: 1 addition & 2 deletions game_service/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const YAML = require('yaml')
// My own libs
const authMiddleware = require('./auth/authMiddleware');
const { newGame, next, awnser, update, getGameSettingsByUser, getHistory, getHistoryByUser, setGameSettingsByUser, getNumberOfQuestions,
getQuestion, getGamemodes
getQuestion
} = require("./game/endpoints");
const { saveQuestionsInDB, deleteOlderQuestions, loadInitialQuestions } = require('./services/questionsService');

Expand Down Expand Up @@ -44,7 +44,6 @@ app.post('/api/game/getHistory', getHistory);
app.post('/api/game/getHistoryByUser', getHistoryByUser);
app.post('/api/game/numberofquestions', getNumberOfQuestions);
app.post('/api/game/currentquestion', getQuestion);
app.post('/api/game/gamemodes', getGamemodes);

// Read the OpenAPI YAML file synchronously
openapiPath='./openapi.yaml'
Expand Down
19 changes: 1 addition & 18 deletions game_service/game.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('Game Service', () => {
{
const response = await request(app)
.post('/api/game/getHistory')
.send({ token: validToken, gameMode: 'classic' });
.send({ token: validToken });

expect(response.statusCode).toBe(200);
});
Expand Down Expand Up @@ -199,21 +199,4 @@ describe('Game Service', () => {

expect(response.statusCode).toBe(200);
});

it("Should return 200 with a valid token when get number of questions", async () => {
let response = await request(app)
.post('/api/game/numberofquestions')
.send({ token: validToken });

expect(response.statusCode).toBe(200);
});

it("Should return 200 with a valid token when get gamemodes", async () => {
let response = await request(app)
.post('/api/game/gamemodes')
.send({ token: validToken });

expect(response.statusCode).toBe(200);
});

})
16 changes: 2 additions & 14 deletions game_service/game/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ const getHistory = async (req,res) => {

let games = await Game.findAll({
where: {
user_id: userId,
gameMode: req.body.gameMode
user_id: userId
},
include: [{
model: Question,
Expand Down Expand Up @@ -258,15 +257,4 @@ const setGameSettingsByUser = async (req, res) =>{
res.status(200).send(settings);
}

const getGamemodes = async (req, res) => {

let userId = jwt.verify(req.body.token, privateKey).user_id;

let games = await Game.aggregate('gameMode', 'DISTINCT', { plain: false, where: { user_id: userId } });

res.status(200).send(games.map(game => game.DISTINCT));
};


module.exports = {newGame, next, awnser, update, getHistory, getHistoryByUser, getGameSettingsByUser, setGameSettingsByUser, getNumberOfQuestions, getQuestion, getGamemodes}

module.exports = {newGame, next, awnser, update, getHistory, getHistoryByUser, getGameSettingsByUser, setGameSettingsByUser, getNumberOfQuestions, getQuestion}
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "CI=false && 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:8001/health prod 3000 \"cd e2e && jest\"",
Expand Down
51 changes: 6 additions & 45 deletions webapp/src/components/history/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
import CancelIcon from '@mui/icons-material/Cancel';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import { getHistory } from "../../services/user.service"
import { getGameModes } from "../../services/game.service"
import { Nav } from '../nav/Nav';
import {Footer} from '../footer/Footer';
import {CssBaseline, FormControl, InputLabel, MenuItem, Select} from '@mui/material';
import { CssBaseline } from '@mui/material';
import StringColorChip from './ColorChip';
import { useTranslation } from "react-i18next";
import "../home/Home.css";

function Row(props) {
const { t } = useTranslation();
Expand Down Expand Up @@ -108,62 +106,25 @@ function Row(props) {
export const History = () => {
const { t } = useTranslation();
const [history, setHistory] = useState([]);
const [gamemodes, setGamemodes] = useState([]);
const [gamemodeSelected, setGamemodeSelected] = useState("classic");

useEffect(() => {
getHistory("classic").then(item => setHistory(item));
getHistory().then(item => setHistory(item));
}, [])

useEffect(() => {
getGameModes(localStorage.getItem("token")).then(gamemodes => setGamemodes(gamemodes));
}, []);

const changeGamemode = (event) => {
getHistory(event.target.value).then(item => setHistory(item));
setGamemodeSelected(event.target.value);
console.log("Changing history to " + event.target.value);
}

return (
<>
<Nav/>
<CssBaseline/>
<div className="flex content-center">
<div className="m-2 p-3 content-center rounded-xl bg-white w-fit">
<FormControl className="content-center" sx={{width: '20rem'}}>
<InputLabel id="gamemode-label"
sx={{color: 'black', fontSize: '1.3em'}}>{t("History.gamemode")}</InputLabel>
<Select
labelId="gamemode-cb"
id="gamemode-cb"
value={gamemodeSelected}
label="gamemode"
className="bg-white m-3"
onChange={changeGamemode}
>
{
gamemodes.map((gamemode) =>
<MenuItem value={gamemode} key={gamemode}>{gamemode}</MenuItem>
)
}
</Select>
</FormControl>
</div>
</div>


<Container className="flex flex-col items-center justify-center min-h-screen">

<TableContainer component={Paper} className="mt-8 bg-gray-800">
<Table aria-label="simple table">
<TableHead>
<TableRow>
<TableCell/>
<TableCell>{t('History.date')}</TableCell>
<TableCell>{t('History.successful')}</TableCell>
<TableCell>{t('History.failed')}</TableCell>
<TableCell>{t('History.correctAnswers')}</TableCell>
<TableCell>{ t('History.date') }</TableCell>
<TableCell>{ t('History.successful') }</TableCell>
<TableCell>{ t('History.failed') }</TableCell>
<TableCell>{ t('History.correctAnswers') }</TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand Down
6 changes: 0 additions & 6 deletions webapp/src/components/history/History.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jest.mock('../../services/user.service', () => ({
)
}));

jest.mock('../../services/game.service', () => ({
getGameModes: () => Promise.resolve(
["classic", "SuddenDeath" ]
)
}));

describe('Game Component', () => {
beforeEach(() => localStorage.setItem("token", "manolineldelpino"));

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/home/Home.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

p,h1,h2,h3,h4,h5,h6,span,label {
p,h1,h2,h3,h4,h5,h6,span {
font-family: Consolas, monaco, serif;
/*color:#FFFFFF;*/
}
Expand Down
6 changes: 2 additions & 4 deletions webapp/src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ i18n
correctAnswer: 'Correct answer',
yourAnswer: 'Your answer',
correct: 'Correct',
any: 'Any',
gamemode: 'Game modes'
any: 'Any'
},
Friends: {
friends: 'Friends',
Expand Down Expand Up @@ -176,8 +175,7 @@ i18n
correctAnswer: 'Respuesta correcta',
yourAnswer: 'Tu respuesta',
correct: 'Correcta',
any: 'Cualquiera',
gamemode: 'Modos de juego'
any: 'Cualquiera'
},
Friends: {
friends: 'Amigos',
Expand Down
13 changes: 1 addition & 12 deletions webapp/src/services/game.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,4 @@ const setGameSettings = async (token, duration, len) =>
}
}

const getGameModes = async (token) => {
try {
const response = await axios.post(`${apiEndpoint}:8003/api/game/gamemodes`, { "token" : token});

return response.data;

} catch (error) {
return undefined;
}
}

export {startNewGame, nextQuestion, awnser, getEndTime, getGameSettings, setGameSettings, getNumberOfQuestions, getCurrentQuestion, getGameModes};
export {startNewGame, nextQuestion, awnser, getEndTime, getGameSettings, setGameSettings, getNumberOfQuestions, getCurrentQuestion};
16 changes: 2 additions & 14 deletions webapp/src/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ const getCreationDate = async () =>

}

const getHistory = async (gameMode) =>
const getHistory = async () =>
{
try {

const response = await axios.post(`${apiEndpoint}:8004/api/userdetails/history`, { token: localStorage.getItem("token"), gameMode: gameMode });
const response = await axios.post(`${apiEndpoint}:8004/api/userdetails/history`, { token: localStorage.getItem("token") });
if ( response.status === 200 )
return response.data;
else
Expand Down Expand Up @@ -119,18 +119,6 @@ const getHistoryByUser = async (user) =>
}
}

const getGamemodes = async () => {
try {
const response = await axios.post(`${apiEndpoint}:8003/api/game/gamemodes`, { token: localStorage.getItem("token") });
if ( response.status === 200 )
return response.data;
else
return "Cant load game modes";
} catch(error) {
return "Cant load game modes";
}
}

const getUsers = async () =>
{
try {
Expand Down