Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Arquisoft/wiq_es1a
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 26, 2024
2 parents 4fbc890 + 5d9e6fa commit f78de1c
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 256 deletions.
61 changes: 39 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,42 @@ jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix statsservice test -- --coverage
- run: npm --prefix webapp test -- --coverage
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix users/authservice ci
- run: npm --prefix users/userservice ci
- run: npm --prefix gatewayservice ci
- run: npm --prefix questionservice ci
- run: npm --prefix statsservice ci
- run: npm --prefix webapp ci
- run: npm --prefix users/authservice test -- --coverage
- run: npm --prefix users/userservice test -- --coverage
- run: npm --prefix gatewayservice test -- --coverage
- run: npm --prefix statsservice test -- --coverage
- run: npm --prefix webapp 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 questionservice install
- run: npm --prefix statsservice install
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ services:
- "3000:3000"
environment:
REACT_APP_API_ENDPOINT: http://gatewayservice:8000
restart: always

prometheus:
image: prom/prometheus
Expand All @@ -115,6 +116,7 @@ services:
- "9090:9090"
depends_on:
- gatewayservice
restart: always

grafana:
image: grafana/grafana
Expand All @@ -134,6 +136,7 @@ services:
- "9091:9091"
depends_on:
- prometheus
restart: always


volumes:
Expand Down
87 changes: 0 additions & 87 deletions webapp/e2e/steps/add-friend.steps.js

This file was deleted.

105 changes: 84 additions & 21 deletions webapp/e2e/steps/create-group.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,92 @@ const feature = loadFeature("./features/create-group.feature");
let page;
let browser;

function generateUUID() {
const hexDigits = '0123456789abcdef';
let uuid = '';
for (let i = 0; i < 36; i++) {
if (i === 8 || i === 13 || i === 18 || i === 23) {
uuid += '-';
} else if (i === 14) {
uuid += '4';
} else if (i === 19) {
uuid += hexDigits.charAt(Math.floor(Math.random() * 4) + 8);
} else {
uuid += hexDigits.charAt(Math.floor(Math.random() * 16));
}
}
return uuid;
}

defineFeature(feature, (test) => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch({ headless: 'new', slowMo: 100 })
: await puppeteer.launch({ headless: 'new', slowMo: 100 });
? await puppeteer.launch({ headless: "new", slowMo: 100 })
: await puppeteer.launch({ headless: "new", slowMo: 100 });
page = await browser.newPage();
setDefaultOptions({ timeout: 10000 });

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

await page.setRequestInterception(true);
page.on("request", (req) => {
if (req.method() === "OPTIONS") {
req.respond({
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "*",
},
});
} else if (req.url().includes("/questions")) {
req.respond({
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
},
contentType: "application/json",
body: JSON.stringify([
{
pregunta: "Test question",
respuestas: [
"Test answer 1",
"Test answer 2",
"Test answer 3",
"Test correct answer",
],
correcta: "Test correct answer",
},
{
pregunta: "Test question 2",
respuestas: [
"Test answer 1",
"Test answer 2",
"Test answer 3",
"Test correct answer",
],
correcta: "Test correct answer",
},
]),
});
} else {
req.continue();
}
});
});
let username;
let password;
let groupname;
test("The user can create a group", ({ given, when, then }) => {
given("A logged-in user", async () => {
username = "testuser";
password = "Testpassword1";
await page.waitForSelector("#login-username");
await page.type("#login-username", username);
await page.waitForSelector("#login-password");
await page.type("#login-password", password);
await page.click("button", { text: "Login" });
//await page.waitForNavigation({ waitUntil: "networkidle0" });
await page.evaluate(() => {
localStorage.setItem("username", "testuser");
localStorage.setItem("token", "abcdefg");
});

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

when("I click on the Groups link and create a group", async () => {
Expand All @@ -41,24 +103,25 @@ defineFeature(feature, (test) => {
await page.click('[data-testid="home-grupos-link"]');
//await page.waitForNavigation({ waitUntil: "networkidle0" });


groupname = generateUUID();
await page.waitForSelector('[name="name"]');
await page.type('[name="name"]', "Testgroup");
await page.type('[name="name"]', groupname);
await page.waitForTimeout(2000);
await page.click('button[data-testid="addgroup-button"]');
});
});

then("The confirmation message should be shown on screen", async () => {
await page.waitForTimeout(1000);
await page.waitForSelector('div[role="alert"]');
// Obtén el texto del elemento que contiene el mensaje

// Obtén el texto del elemento que contiene el mensaje
const alertText = await page.evaluate(() => {
const alertElement = document.querySelector('div[role="alert"]');
return alertElement.innerText.trim();
const alertElement = document.querySelector('div[role="alert"]');
return alertElement.innerText.trim();
});
const rightMessage=alertText === "Group created successfully";
expect(rightMessage).toBe(true);

const rightMessage = "Error: Failed to fetch";
expect(rightMessage).toBe(alertText);
});
});

Expand Down
Loading

0 comments on commit f78de1c

Please sign in to comment.