Skip to content

Commit

Permalink
e2e test fix (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelalvaigle committed Dec 17, 2024
1 parent 2dd08ab commit 5b38680
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions middleware/validation-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ export const validateRegisterInput = withValidationErrors([
body('lastName')
.notEmpty()
.withMessage('last name is required')
.isLength({ max: 20 })
.isLength({ max: 40 })
.withMessage('last name must be no more than 20 characters long'),
body('username')
.notEmpty()
.withMessage('username is required')
.isLength({ max: 20 })
.withMessage('username must be no more than 20 characters long'),
.withMessage('username must be no more than 20 characters long')
.custom(async (username) => {
const user = await User.findOne({ username });
if (user) throw new BadRequestError('username already exists');
}),
body('email')
.notEmpty()
.withMessage('email is required')
Expand Down
16 changes: 14 additions & 2 deletions webapp/e2e/steps/register-form.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ let browser;
defineFeature(feature, (test) => {
beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch({ headless: 'new' })
? await puppeteer.launch({
headless: 'new',
args: ['--no-sandbox'],
})
: await puppeteer.launch({ headless: false, slowMo: 100 });
page = await browser.newPage();
//Way of setting up the timeout
Expand All @@ -23,23 +26,32 @@ defineFeature(feature, (test) => {
});

test('The user is not registered in the site', ({ given, when, then }) => {
let name;
let lastName;
let email;
let username;
let password;

given('An unregistered user', async () => {
name = 'pablo';
lastName = 'gonzalez';
email = '[email protected]';
username = 'pablo';
password = 'pabloasw';
await expect(page).toClick('a', { text: 'Register' });
});

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

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

0 comments on commit 5b38680

Please sign in to comment.