Skip to content

Commit

Permalink
Merge pull request #195 from Arquisoft/monitor
Browse files Browse the repository at this point in the history
Endpoint_usage, e2e tests and i18n files updated
  • Loading branch information
UO287747 authored Apr 26, 2024
2 parents abe05a8 + b4927b7 commit 94e8f5b
Show file tree
Hide file tree
Showing 21 changed files with 1,082 additions and 42 deletions.
11 changes: 11 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ const memoryUsageGauge = new promClient.Gauge({
name: 'system_memory_usage',
help: 'Memory usage',
});
// Endpoint usage counter
const endpointUsageCounter = new promClient.Counter({
name: 'endpoint_usage',
help: 'Number of calls to each endpoint',
labelNames: ['endpoint']
});

app.use((req, res, next) => {
endpointUsageCounter.inc({ endpoint: req.path });
next();
});

if (process.env.NODE_ENV !== 'test') {
setInterval(() => {
Expand Down
2 changes: 1 addition & 1 deletion question_generator/locales/es.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Which city is higher above sea level?": "¿Qué ciudad está a mayor altitud?",
"Which city has more population?": "¿Qué ciudad tiene más población?",
"Which city is in?": "¿Qué ciudad se encuentra %s?",
"Which city is in?": "¿Qué ciudad se encuentra en %s?",
"Which city has an area of?": "¿Qué ciudad tiene un área de %s km2?",
"Which city is governed by?": "¿Qué ciudad es gobernada por %s?",
"Which city is in the time zone?": "¿Qué ciudad está en la zona horaria %s?",
Expand Down
3 changes: 1 addition & 2 deletions question_generator/locales/fr.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Which city is higher above sea level?": "Quelle ville est située à une altitude plus élevée ?",
"Which city has more population?": "Quelle ville a une population plus nombreuse ?",
"Which city is in %s?": "Dans quelle ville se trouve %s ?",
"Which city is in %s?": "Quelle ville se trouve en %s ?",
"Which city has an area of %s km2?": "Quelle ville a une superficie de %s km2 ?",
"Which city is governed by %s?": "Quelle ville est gouvernée par %s ?",
"Which city is in the time zone %s?": "Dans quelle ville se trouve le fuseau horaire %s ?",
Expand Down Expand Up @@ -67,5 +67,4 @@
"Which basketball team is trained by?": "Quelle équipe de basketball est entraînée par %s ?",
"Which basketball team belongs to?": "À quelle équipe de basketball appartient %s ?",
"Which is the division of?": "Quelle est la division de %s ?"

}
3 changes: 1 addition & 2 deletions question_generator/locales/it.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Which city is higher above sea level?": "Quale città si trova ad un'altitudine maggiore?",
"Which city has more population?": "Quale città ha una popolazione maggiore?",
"Which city is in %s?": "In quale città si trova %s?",
"Which city is in %s?": "Quale città si trova in %s?",
"Which city has an area of %s km2?": "Quale città ha un'area di %s km2?",
"Which city is governed by %s?": "Quale città è governata da %s?",
"Which city is in the time zone %s?": "In quale città si trova il fuso orario %s?",
Expand Down Expand Up @@ -67,5 +67,4 @@
"Which basketball team is trained by %s?": "Quale squadra di basket è allenata da %s?",
"Which basketball team belongs to %s?": "A quale squadra di basket appartiene %s?",
"Which is the division of %s?": "Qual è la divisione di %s?"

}
2 changes: 1 addition & 1 deletion question_generator/questionGenerationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const app = express();
const port = 8003;

i18n.configure({
locales: ['en', 'es'],
locales: ['en', 'es', 'fr', 'it'],
directory: './locales',
defaultLocale: 'en',
cookie: 'lang',
Expand Down
10 changes: 10 additions & 0 deletions webapp/e2e/features/friends.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Add friend

Scenario: The user is going to add a friend
Given An unregistered user
When I fill the data in the form, press submit, press Friends and adds a friend
Then The friend will be added
Scenario: The user is going to remove a friend
Given A registered user with one friend
When I am in Friends page and select the friend to remove
Then The friend will be removed from the user's friend list
6 changes: 6 additions & 0 deletions webapp/e2e/features/login.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Login

Scenario: Login
Given A registered user
When I fill the data in the form, press submit
Then The user must be logged
6 changes: 6 additions & 0 deletions webapp/e2e/features/play-classic.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Play Classic Mode

Scenario: The user is going to play classic mode
Given An unregistered user
When I fill the data in the form, press submit, press Classic Mode button and play game
Then A Game Over message should be shown in the screen
2 changes: 1 addition & 1 deletion webapp/e2e/steps/close-session-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defineFeature(feature, test => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
: await puppeteer.launch({ headless: false, slowMo: 50 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })
Expand Down
87 changes: 87 additions & 0 deletions webapp/e2e/steps/friends.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/friends.feature');

let page;
let browser;

defineFeature(feature, test => {

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 50 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })
await page.setViewport({ width: 1080, height: 980 });

await page
.goto("http://localhost:3000", {
waitUntil: "networkidle0",
})
.catch(() => {});

});

test('The user is going to add a friend', ({given,when,then}) => {

let username;
let password;

given('An unregistered user', async () => {
username = "add-friend-user"
password = "defaultpassword"
await expect(page).toClick("button", { text: "Don't have an account? Register here." });
});

when('I fill the data in the form, press submit, press Friends and adds a friend', async () => {
await page.waitForSelector('input[name="username"]');
await expect(page).toFill('input[name="username"]', username);

await page.waitForSelector('input[name="password"]');
await expect(page).toFill('input[name="password"]', password);

await page.waitForSelector('input[name="confirmPassword"]');
await expect(page).toFill('input[name="confirmPassword"]', password);

await page.waitForSelector('button.btn');
await expect(page).toClick('button.btn', { text: '' });

await page.waitForSelector('div a');
await expect(page).toClick('div a', { text: 'Friends' });

await page.waitForSelector('.searchForm input');
await expect(page).toFill('.searchForm input', 'defaultuser');

await page.waitForSelector('button.btn');
await expect(page).toClick('button.btn', { text: '' });

});

then('The friend will be added', async () => {
await expect(page).toMatchElement('.tableFriends', { text: 'defaultuser' });
});
})
test('The user is going to remove a friend', ({given,when,then}) => {

given('A registered user with one friend', async () => {
});

when('I am in Friends page and select the friend to remove', async () => {
await page.waitForSelector('.tableFriends button.btn');
await expect(page).toClick('.tableFriends button.btn', { text: 'Delete friend' });

});

then("The friend will be removed from the user's friend list", async () => {
await expect(page).not.toMatchElement('.tableFriends', { text: 'defaultuser' });
});
})

afterAll(async ()=>{
browser.close()
})

});
14 changes: 9 additions & 5 deletions webapp/e2e/steps/i18n-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defineFeature(feature, test => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 10 });
: await puppeteer.launch({ headless: false, slowMo: 50 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })
Expand All @@ -23,7 +23,7 @@ defineFeature(feature, test => {
.catch(() => {});
});

test('The user is going to try different languages', ({given,when,then}) => {
test('The user is going to try different languages', async ({given,when,then}) => {

let username;
let password;
Expand All @@ -38,23 +38,27 @@ defineFeature(feature, test => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password);

await page.waitForSelector('button.btn', { text: '' });
await expect(page).toClick('button.btn', { text: '' });

await page.waitForSelector('span', { text: "Classic Game" });
await expect(page).toMatchElement("span", { text: "Classic Game" });

await page.waitForSelector('button.menuLeft', { text: '' });
await expect(page).toClick('button.menuLeft', { text: '' });

await page.waitForSelector('div.languageButton', { text: '' });
await expect(page).toClick('div.languageButton', { text: '' });

await page.waitForSelector('li', { text: 'Spanish' });
await expect(page).toClick('li', { text: 'Spanish' });
});

then('A Classic Game message should be shown in different languages', async () => {

await expect(page).toMatchElement("span", { text: "Juego Clásico" });

await page.waitForSelector('div.languageButton', { text: '' });
await expect(page).toClick('div.languageButton', { text: '' });
await page.waitForSelector('li', { text: 'Italiano' });
await expect(page).toClick('li', { text: 'Italiano' });
await expect(page).toMatchElement("span", { text: "Gioco Classico" });
});
Expand Down
6 changes: 4 additions & 2 deletions webapp/e2e/steps/infinite-mode-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defineFeature(feature, test => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 10 });
: await puppeteer.launch({ headless: false, slowMo: 50 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })
Expand Down Expand Up @@ -41,13 +41,15 @@ defineFeature(feature, test => {

await expect(page).toClick('button.btn', { text: '' });

await page.waitForSelector('button.btn', { text: 'Infinite Mode' });
await expect(page).toClick('button.btn', { text: 'Infinite Mode' });

await page.waitForSelector('div.endGameButton', { text: '' });
await expect(page).toClick('div.endGameButton', { text: '' });
});

then('A Game Over message should be shown in the screen', async () => {
await expect(page).toMatchElement("p", { text: "Game Over" });
await page.waitForSelector('p', { text: 'Game Over' });
});
})

Expand Down
58 changes: 58 additions & 0 deletions webapp/e2e/steps/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/login.feature');

let page;
let browser;

defineFeature(feature, test => {

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 50 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })

await page
.goto("http://localhost:3000", {
waitUntil: "networkidle0",
})
.catch(() => {});


});

test('Login', ({given,when,then}) => {

let username;
let password;

given('A registered user', async () => {
username = "defaultuser"
password = "defaultpassword"
});

when('I fill the data in the form, press submit', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
expect(page).toClick('button.btn', { text: '' })



});
then('The user must be logged', async () => {
await page.waitForFunction(() => localStorage.getItem('sessionData') !== null);
const sessionData = await page.evaluate(() => localStorage.getItem('sessionData'));
expect(sessionData).toContain('token');

})
});

afterAll(async ()=>{
browser.close()
})

});
Loading

0 comments on commit 94e8f5b

Please sign in to comment.