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

Commit

Permalink
Merge pull request #65 from Arquisoft/add-e2e-tests
Browse files Browse the repository at this point in the history
Add e2e tests
  • Loading branch information
Manueluz authored Feb 12, 2024
2 parents fb63c43 + 55ddb61 commit 44a6d1c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- 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
Expand Down
4 changes: 4 additions & 0 deletions auth_service/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ app.use(cors()) // This api is listening on a different port from the frontend
app.post("/api/auth/register", auth.register);
app.post("/api/auth/login", auth.login);
app.post("/api/auth/verify", auth.verify);
app.get('/health', (req, res) => {
res.json({ status: 'OK' });
});


// Start the server
const server = app.listen(port, () => {
Expand Down
12 changes: 11 additions & 1 deletion webapp/e2e/features/register-form.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ Feature: Registering a new user
Scenario: The user is not registered in the site
Given An unregistered user
When I fill the data in the form and press submit
Then A confirmation message should be shown in the screen
Then A confirmation message should be shown in the screen

Scenario: The user puts two different passwords
Given An unregistered user
When I fill the data with different passwords in the form and press submit
Then A error message appears

Scenario: The user uses an already taken username
Given An unregistered user
When I fill the data with a taken username
Then A error message appears
58 changes: 53 additions & 5 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,88 @@ 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: 1 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })

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

test('The user is not registered in the site', ({given,when,then}) => {

let username;
let password;

given('An unregistered user', async () => {
username = "pablo"
password = "pabloasw"
await expect(page).toClick("button", { text: "Don't have an account? Register here." });
await expect(page).toClick("a", { text: "¿No tienes una cuenta? Regístrate" });
});

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

then('A confirmation message should be shown in the screen', async () => {
/*TODO: Add the message
await expect(page).toMatchElement("div", { text: "User added successfully" });
*/
});
})

test('The user puts two different passwords', ({given,when,then}) => {
let username;
let password;

given('An unregistered user', async () => {
username = "pablo"
password = "pabloasw"
});

when('I fill the data with different passwords in the form and press submit', async () => {
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toFill('input[name="confirmPassword"]', password + 'imdifferent');
await expect(page).toClick('button', { text: 'Registrarme' })
});

then('A error message appears', async () => {
await expect(page).toMatchElement("div", { text: "Las contraseñas no coinciden" });
});
});

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

test('The user uses an already taken username', ({given,when,then}) => {
let username;
let password;

given('An unregistered user', async () => {
username = "pablo"
password = "pabloasw"
});

when('I fill the data with a taken username', async () => {
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 expect(page).toClick('button', { text: 'Registrarme' })
});

then('A error message appears', async () => {
await expect(page).toMatchElement("div", { text: "Nombre de usuario no disponible" });
});
});

afterAll(async ()=>{
browser.close()
})
Expand Down
20 changes: 7 additions & 13 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
const { MongoMemoryServer } = require('mongodb-memory-server');


let mongoserver;
let userservice;
let authservice;
let gatewayservice;

let auth_service;

async function startServer() {
console.log('Starting MongoDB memory server...');
mongoserver = await MongoMemoryServer.create();
const mongoUri = mongoserver.getUri();
process.env.MONGODB_URI = mongoUri;
userservice = await require("../../users/userservice/user-service");
authservice = await require("../../users/authservice/auth-service");
gatewayservice = await require("../../gatewayservice/gateway-service");
}
console.log('Starting auth memory server...');

auth_service = await require("../../auth_service/auth");
}

startServer();
startServer();
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build": "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:8000/health prod 3000 \"cd e2e && jest\"",
"test:e2e": "start-server-and-test 'node e2e/test-environment-setup.js' http://localhost:8001/health prod 3000 \"cd e2e && jest\"",
"eject": "react-scripts eject"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/routers/AppRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Error404 from "../components/error/Error404";
const router = createBrowserRouter([
{
path: "/",
element: <Navigate to="/home" replace />
element: <Navigate to="/login" replace />
},
{
path: "/home",
Expand Down

0 comments on commit 44a6d1c

Please sign in to comment.