Skip to content

Commit

Permalink
Merge branch 'dev' into fix-internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed May 7, 2024
2 parents 09eaf15 + aef775c commit 6d25c00
Show file tree
Hide file tree
Showing 19 changed files with 9,160 additions and 5,678 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ jobs:
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix game/gameservice test -- --coverage
- run: npm --prefix game/groupservice test -- --coverage

- run: npm --prefix game/qgservice test -- --coverage
- run: npm --prefix multiplayerservice test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
Expand Down
57 changes: 35 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,49 @@ jobs:
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix webapp ci
- run: npm --prefix game/gameservice ci
- run: npm --prefix game/groupservice ci
- run: npm --prefix game/qgservice ci
- run: npm --prefix multiplayerservice ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- run: npm --prefix game/gameservice test -- --coverage
- run: npm --prefix game/groupservice test -- --coverage
- run: npm --prefix game/qgservice test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
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: sudo setcap 'cap_net_bind_service=+ep' `which node`
- 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 @@ -69,7 +82,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -87,7 +100,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -105,7 +118,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -123,7 +136,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -141,7 +154,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -162,7 +175,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand All @@ -180,7 +193,7 @@ jobs:
permissions:
contents: read
packages: write
needs: [unit-tests]
needs: [e2e-tests]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# wiq_en2a
# Conocer y Vencer

[![Deploy on release](https://github.com/Arquisoft/wiq_en2a/actions/workflows/release.yml/badge.svg)](https://github.com/Arquisoft/wiq_en2a/actions/workflows/release.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Arquisoft_wiq_en2a&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Arquisoft_wiq_en2a)
Expand All @@ -8,12 +8,15 @@ This is a base repo for the [Software Architecture course](http://arquisoft.gith

The application is deployed at: http://conoceryvencer.xyz

This repo is a basic application composed of several components.
This repo is a basic application composed of several components:

- **Gateway service**. Express service that is exposed to the public and serves as a proxy to the two previous ones.
- **User service**. Express service that handles the insertion of new users in the system.
- **Auth service**. Express service that handles the authentication of users.
- **Webapp**. React web application that uses the gateway service to allow basic login and new user features.
- **Game service**. Express service that creates, delivers the logic and stores information about the last game played by the user.
- **Group service**. Express service responsible for the management of user groups.
- **Question generation service**. Express service that generates the question for the new game by retrieving data from Wikidata.
- **Gateway service**. Express service that is exposed to the public and serves as a proxy to the two previous ones. It is also in charge of the application's monitoring process.
- **User service**. Express service handling the insertion of new users in the system.
- **Auth service**. Express service that deals with the authentication of users.
- **Webapp**. React web application using the gateway service to allow basic login and new user features.

Both the user and auth service share a Mongo database that is accessed with mongoose.

Expand All @@ -28,7 +31,7 @@ Both the user and auth service share a Mongo database that is accessed with mong

## Quick start guide

### Using docker
### Using Docker

The fastest way for launching this sample project is using docker. Just clone the project:

Expand Down
2 changes: 1 addition & 1 deletion game/groupservice/GroupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ let GroupController = {

async function getGroupByName(name) {
try {
const group = await Group.findOne({ groupName: name });
const group = await Group.findOne({ groupName: name.toString() });
if (!group) {
throw new Error('This group does not exist');
}
Expand Down
35 changes: 4 additions & 31 deletions game/groupservice/group-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('Group Service API Tests', () => {
});

it('should return message when user is already in the group', async () => {
const group = await Group.create({
await Group.create({
uuid: 'user_already_in_group_uuid',
groupName: 'User already in group Test Group',
members: ['userInGroup_id', 'admin_id'],
Expand All @@ -124,7 +124,7 @@ it('should return message when user is already in the group', async () => {
});

it('should return message when group is full', async () => {
const group = await Group.create({
await Group.create({
uuid: 'full_group_uuid',
groupName: 'Full group Test Group',
members: Array(30).fill("member_uuid"),
Expand All @@ -144,7 +144,7 @@ it('should return message when group is full', async () => {
});

it('should return message when join code is incorrect for a private group', async () => {
const group = await Group.create({
await Group.create({
uuid: 'incorrect_join_code_group_uuid',
groupName: 'Test Group Incorrect Join Code',
members: ['admin_id3'],
Expand Down Expand Up @@ -178,30 +178,8 @@ it('should return status 500 and error message when an error occurs', async () =
expect(response.body).toEqual({ error: 'Internal server error' });
});

it('should successfully remove user from the group', async () => {
const group = await Group.create({
uuid: 'successfully_remove_member_group_uuid',
groupName: 'Succesfully remove member from Test Group',
members: ['user_id', 'admin_id4'],
admin: 'admin_id4',
isPublic: true,
maxNumUsers: 5
});

const requestBody = {
expelledUUID: 'user_id',
groupName: 'Succesfully remove member from Test Group',
adminUUID: 'admin_id4'
};

const response = await request(app).post('/leaveGroup').send(requestBody);
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('members');
expect(response.body.members).not.toContain(requestBody.expelledUUID);
});

it('should successfully remove user from the group and remove the group when nobody is left', async () => {
const group = await Group.create({
await Group.create({
uuid: 'successfully_remove_member_group_and_remove_group_uuid',
groupName: 'Succesfully remove member, and group Test Group',
members: ['admin_id'],
Expand Down Expand Up @@ -368,13 +346,8 @@ it('should return status 500 and error message when an error occurs', async () =
const mockError = new Error('Internal server error');
jest.spyOn(Group, 'findOne').mockRejectedValue(mockError);

// Send request to get a group
const response = await request(app).get('/getGroup/group_uuid');

// Expect response status to be 500
expect(response.status).toBe(500);

// Expect response body to contain the error message
expect(response.body).toEqual({ error: 'Internal server error' });
});

Expand Down
5 changes: 1 addition & 4 deletions game/qgservice/QGController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,13 @@ let QGController = {
getQuestionsByIds: async (req, res) => {
try {
const { ids } = req.body;
console.log(ids)
const questions = [];
for (const id of ids) {
const question = await Question4Answers.find({uuid: id})
console.log(question)
const question = await Question4Answers.find({uuid: id.toString()})
questions.push(question);
}
res.json(questions);
} catch (error) {
console.log(error)
res.status(500).json({ error: 'Internal Server Error' });
}
}
Expand Down
6 changes: 3 additions & 3 deletions game/qgservice/generatorLogic/MathQuestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function generateRandomMathQuestion() {
};
}

async function createMathQuestions(numberOfQuestions, lang) {
async function createMathQuestions(numberOfQuestions) {
const questions = [];

for (let i = 0; i < numberOfQuestions; i++) {
const mathQuestion = generateRandomMathQuestion(lang);
const mathQuestion = generateRandomMathQuestion();
questions.push(mathQuestion);
}

Expand All @@ -54,4 +54,4 @@ function generateRandomMathQuestion() {
}
}

module.exports = { createMathQuestions };
module.exports = { createMathQuestions, generateRandomMathQuestion };
6 changes: 5 additions & 1 deletion game/qgservice/qg-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mongoose.connect(mongoUri);

app.get('/', (req, res) => {
res.json({
"hi": "question generator"
"message": "Welcome to question generator service module"
});
});

Expand All @@ -26,4 +26,8 @@ const server = app.listen(port, () => {
console.log(`Question generator Service listening at http://localhost:${port}`);
});

server.on('close', () => {
mongoose.connection.close();
});

module.exports = server;
Loading

0 comments on commit 6d25c00

Please sign in to comment.