Skip to content

Commit

Permalink
feat: init DataTable for running tests in a loop with different configs
Browse files Browse the repository at this point in the history
  • Loading branch information
darkoatanasovski committed Jan 12, 2023
1 parent 1663736 commit 5c4f5a8
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 122 deletions.
6 changes: 4 additions & 2 deletions src/services/inplayer.account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,10 @@ function processAccount(account: AccountData): Customer {
function processUpdateAccount(customer: UpdateCustomerArgs) {
const firstName = customer.firstName?.trim() || '';
const lastName = customer.lastName?.trim() || '';
const fullName = `${firstName} ${lastName}`;

let fullName = `${firstName} ${lastName}`;
if (!firstName && !lastName) {
fullName = '[EMPTY FULL NAME]';
}
const data: UpdateAccountData = {
fullName,
metadata: {
Expand Down
26 changes: 23 additions & 3 deletions src/stores/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
Capture,
Customer,
CustomerConsent,
EmailConfirmPasswordInput,
FirstLastNameInput,
GetCaptureStatusResponse,
GetCustomerConsentsResponse,
GetPublisherConsentsResponse,
Expand Down Expand Up @@ -115,9 +117,7 @@ export const initializeAccount = async () => {
});
};

export async function updateUser(
values: { firstName: string; lastName: string } | { email: string; confirmationPassword: string },
): Promise<ServiceResponse<Customer>> {
export async function updateUser(values: FirstLastNameInput | EmailConfirmPasswordInput): Promise<ServiceResponse<Customer>> {
return await useService(async ({ accountService, sandbox = true }) => {
if (!accountService) throw new Error('account service is not configured');

Expand All @@ -133,6 +133,14 @@ export async function updateUser(
throw new Error('no auth');
}

const errors = validateInputLength(values as FirstLastNameInput);
if (errors.length) {
return {
errors,
responseData: {} as Customer,
};
}

const response = await accountService.updateCustomer({ ...values, id: user.id.toString() }, sandbox, auth.jwt);

if (!response) {
Expand Down Expand Up @@ -496,3 +504,15 @@ async function afterLogin(
getPublisherConsents(),
]);
}

const validateInputLength = (values: { firstName: string; lastName: string }) => {
const errors: string[] = [];
if (Number(values?.firstName?.length) > 50) {
errors.push('firstName can have max 50 characters.');
}
if (Number(values?.lastName?.length) > 50) {
errors.push('lastName can have max 50 characters.');
}

return errors;
};
104 changes: 63 additions & 41 deletions test-e2e/tests/account_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,27 @@ const firstNameField = 'firstName';
const lastNameField = 'lastName';
const consentCheckbox = 'Yes, I want to receive Blender updates by email';

let loginContext: LoginContext;
const loginContexts: { [key: string]: LoginContext } = {};
const firstName = 'John Q.';
const lastName = 'Tester';

Feature('account').retry(Number(process.env.TEST_RETRY_COUNT) || 0);
const configs = new DataTable(['config', 'resetPasswordType', 'canEditEmail']);
configs.add([testConfigs.svod, 'resetlink', true]);
configs.xadd([testConfigs.inplayerSvod, 'direct', false]);

Before(async ({ I }) => {
I.useConfig(testConfigs.svod);

loginContext = await I.registerOrLogin(loginContext, () => {
I.fillField('firstName', firstName);
I.fillField('lastName', lastName);

I.click('Continue');
I.waitForLoaderDone();

I.clickCloseButton();
});
});

Scenario('I can see my account data', async ({ I }) => {
Data(configs).Scenario('I can see my account data', async ({ I, current }) => {
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
I.seeInCurrentUrl(constants.baseUrl);
await I.openMainMenu();

I.click('Account');

I.see('Email');
I.see(loginContext.email);
I.see(editAccount);
I.see(loginContexts[current.config.label].email);
if (current.canEditEmail) {
I.see(editAccount);
}

I.see('Security');
I.see('Password');
Expand All @@ -53,41 +45,53 @@ Scenario('I can see my account data', async ({ I }) => {
I.see('Edit information');

I.see('Terms & tracking');
I.see('I accept the Terms and Conditions of Cleeng.');
I.see(`I accept the Terms and Conditions of ${current.config.label}.`);
I.see(consentCheckbox);

I.seeInCurrentUrl(constants.accountsUrl);
});

Scenario('I can cancel Edit account', async ({ I }) => {
Data(configs).Scenario('I can cancel Edit account', async ({ I, current }) => {
if (!current.canEditEmail) {
return;
}
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
editAndCancel(I, editAccount, [
{ name: emailField, startingValue: loginContext.email, newValue: 'user@email.nl' },
{ name: emailField, startingValue: loginContexts[current.config.label].email, newValue: 'user@email.nl' },
{ name: passwordField, startingValue: '', newValue: 'pass123!?' },
]);
});

Scenario('I get a duplicate email warning', async ({ I }) => {
Data(configs).Scenario('I get a duplicate email warning', async ({ I, current }) => {
if (!current.canEditEmail) {
return;
}
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
editAndCancel(I, editAccount, [
{
name: emailField,
startingValue: loginContext.email,
startingValue: loginContexts[current.config.label].email,
newValue: constants.username,
expectedError: 'Email already exists!',
},
{
name: passwordField,
startingValue: '',
newValue: loginContext.password,
newValue: loginContexts[current.config.label].password,
},
]);
});

Scenario('I get a wrong password warning', async ({ I }) => {
Data(configs).Scenario('I get a wrong password warning', async ({ I, current }) => {
if (!current.canEditEmail) {
return;
}
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
editAndCancel(I, editAccount, [
{
name: emailField,
startingValue: loginContext.email,
newValue: loginContext.email,
startingValue: loginContexts[current.config.label].email,
newValue: loginContexts[current.config.label].email,
},
{
name: passwordField,
Expand All @@ -98,13 +102,21 @@ Scenario('I get a wrong password warning', async ({ I }) => {
]);
});

Scenario('I can toggle to view/hide my password', async ({ I }) => {
Data(configs).Scenario('I can toggle to view/hide my password', async ({ I, current }) => {
if (!current.canEditEmail) {
return;
}
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
I.amOnPage(constants.accountsUrl);
I.click(editAccount);
await passwordUtils.testPasswordToggling(I, 'confirmationPassword');
});

Scenario('I can reset my password', async ({ I }) => {
Data(configs).Scenario('I can reset my password (ResetLink)', async ({ I, current }) => {
if (current.resetPasswordType !== 'resetlink') {
return;
}
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
I.amOnPage(constants.accountsUrl);

I.click('Edit password');
Expand All @@ -122,17 +134,18 @@ Scenario('I can reset my password', async ({ I }) => {

I.click('Yes, reset');
I.see('Password link sent');
I.see(`Please check your inbox at ${loginContext.email}`);
I.see(`Please check your inbox at ${loginContexts[current.config.label].email}`);
I.see('Back to login');

I.click('Back to login');
I.see('Sign in');

I.clickCloseButton();
await I.login({ email: loginContext.email, password: loginContext.password });
await I.login({ email: loginContexts[current.config.label].email, password: loginContexts[current.config.label].password });
});

Scenario('I can update firstName', async ({ I }) => {
Data(configs).Scenario('I can update firstName', async ({ I, current }) => {
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
editAndSave(I, editDetials, [
{
name: firstNameField,
Expand All @@ -155,7 +168,8 @@ Scenario('I can update firstName', async ({ I }) => {
]);
});

Scenario('I can update lastName', async ({ I }) => {
Data(configs).Scenario('I can update lastName', async ({ I, current }) => {
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
editAndSave(I, editDetials, [
{
name: lastNameField,
Expand All @@ -178,7 +192,9 @@ Scenario('I can update lastName', async ({ I }) => {
]);
});

Scenario('I can update details', async ({ I }) => {
Data(configs).Scenario('I can update details', async ({ I, current }) => {
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);

editAndSave(I, editDetials, [
{
name: firstNameField,
Expand Down Expand Up @@ -213,7 +229,8 @@ Scenario('I can update details', async ({ I }) => {
]);
});

Scenario('I see name limit errors', async ({ I }) => {
Data(configs).Scenario('I see name limit errors', async ({ I, current }) => {
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
editAndCancel(I, editDetials, [
{
name: firstNameField,
Expand All @@ -230,7 +247,8 @@ Scenario('I see name limit errors', async ({ I }) => {
]);
});

Scenario('I can update my consents', async ({ I }) => {
Data(configs).Scenario('I can update my consents', async ({ I, current }) => {
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
I.amOnPage(constants.accountsUrl);

I.dontSeeCheckboxIsChecked(consentCheckbox);
Expand Down Expand Up @@ -260,21 +278,25 @@ Scenario('I can update my consents', async ({ I }) => {
I.seeCheckboxIsChecked(consentCheckbox);
});

Scenario('I can change email', async ({ I }) => {
Data(configs).Scenario('I can change email', async ({ I, current }) => {
if (!current.canEditEmail) {
return;
}
loginContexts[current.config.label] = await I.beforeAccount(current.config, loginContexts[current.config.label], firstName, lastName);
const newEmail = passwordUtils.createRandomEmail();

editAndSave(I, editAccount, [
{ name: emailField, newValue: newEmail },
{ name: passwordField, newValue: loginContext.password },
{ name: passwordField, newValue: loginContexts[current.config.label].password },
]);

await I.logout();

await I.login({ email: newEmail, password: loginContext.password });
await I.login({ email: newEmail, password: loginContexts[current.config.label].password });

editAndSave(I, editAccount, [
{ name: emailField, newValue: loginContext.email },
{ name: passwordField, newValue: loginContext.password },
{ name: emailField, newValue: loginContexts[current.config.label].email },
{ name: passwordField, newValue: loginContexts[current.config.label].password },
]);
});

Expand Down
39 changes: 20 additions & 19 deletions test-e2e/tests/login/account_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,43 @@ const incorrectLogin = 'Incorrect email/password combination';
const formFeedback = 'div[class*=formFeedback]';

Feature('login - account').retry(Number(process.env.TEST_RETRY_COUNT) || 0);
const configs = new DataTable(['config']);
configs.add([testConfigs.cleengAuthvod]);
configs.xadd([testConfigs.inplayerAuth]);

Before(async ({ I }) => {
I.useConfig(testConfigs.cleengAuthvod);

if (await I.isMobile()) {
I.openMenuDrawer();
}

I.click('Sign in');

I.waitForElement(constants.loginFormSelector, normalTimeout);
});

Scenario('I can close the modal', async ({ I }) => {
Data(configs).Scenario('I can close the modal', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');
I.clickCloseButton();
I.dontSee('Email');
I.dontSee('Password');
I.dontSeeElement(constants.loginFormSelector);
});

Scenario('I can close the modal by clicking outside', async ({ I }) => {
Data(configs).Scenario('I can close the modal by clicking outside', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');
I.forceClick('div[data-testid="backdrop"]');

I.dontSee('Email');
I.dontSee('Password');
I.dontSeeElement(constants.loginFormSelector);
});

Scenario('I can toggle to view password', async ({ I }) => {
Data(configs).Scenario('I can toggle to view password', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');
await passwordUtils.testPasswordToggling(I);
});

Scenario('I get a warning when the form is incompletely filled in', async ({ I }) => {
Data(configs).Scenario('I get a warning when the form is incompletely filled in', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');
tryToSubmitForm(I);

checkField(I, 'email', fieldRequired);
checkField(I, 'password', fieldRequired);
});

Scenario('I see email warnings', async ({ I }) => {
Data(configs).Scenario('I see email warnings', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');

I.fillField('email', 'danny@email.com');
I.fillField('password', 'Password');

Expand Down Expand Up @@ -79,7 +76,9 @@ Scenario('I see email warnings', async ({ I }) => {
checkField(I, 'email', invalidEmail);
});

Scenario('I see empty password warnings', async ({ I }) => {
Data(configs).Scenario('I see empty password warnings', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');

I.fillField('email', 'danny@email.com');
I.fillField('password', 'Password');

Expand All @@ -103,7 +102,9 @@ Scenario('I see empty password warnings', async ({ I }) => {
checkField(I, 'password', fieldRequired);
});

Scenario('I see a login error message', async ({ I }) => {
Data(configs).Scenario('I see a login error message', async ({ I, current }) => {
await I.beforeRegisterOrLogin(current.config, 'signin');

I.fillField('email', 'danny@email.com');
I.fillField('password', 'Password');

Expand Down
Loading

0 comments on commit 5c4f5a8

Please sign in to comment.