Skip to content

Commit

Permalink
Sidm 4015 welsh functional tests (#352)
Browse files Browse the repository at this point in the history
* Add functional tests: duplicate registration in different languages

* Welsh tests.

* Welsh tests.

* Welsh tests.

* Welsh tests.
  • Loading branch information
Radoslaw Orlowski authored Apr 21, 2020
1 parent 147db73 commit 15bb408
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 3 deletions.
26 changes: 26 additions & 0 deletions src/test/js/mfa_e2e_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const randomData = require('./shared/random_data');
const TestData = require('./config/test_data');
const Welsh = require('./shared/welsh_constants');
const assert = require('assert');

Feature('I am able to login with MFA');

Expand Down Expand Up @@ -84,6 +86,30 @@ Scenario('@functional @mfaLogin I am able to login with MFA', async (I) => {
I.resetRequestInterception();
}).retry(TestData.SCENARIO_RETRY_LIMIT);

Scenario('@functional @mfaLogin @welshLanguage I am able to login with MFA in Welsh', async (I) => {
const loginUrl = `${TestData.WEB_PUBLIC_URL}/login?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}${Welsh.urlForceCy}`;

I.amOnPage(loginUrl);
I.waitForText(Welsh.signInOrCreateAccount, 20, 'h1');
I.fillField('#username', mfaUserEmail);
I.fillField('#password', TestData.PASSWORD);
I.click(Welsh.signIn);
I.seeInCurrentUrl("/verification");
I.waitForText(Welsh.verificationRequired, 10, 'h1');
I.wait(5);
const otpEmailBody = await I.getEmail(mfaUserEmail);
assert.equal(otpEmailBody.body.startsWith('Ysgrifennwyd'), true);
const otpCode = await I.extractOtpFromEmailBody(otpEmailBody);

I.fillField('code', otpCode);
I.interceptRequestsAfterSignin();
I.click(Welsh.submitBtn);
I.waitForText(TestData.SERVICE_REDIRECT_URI);
I.see('code=');
I.dontSee('error=');
I.resetRequestInterception();
}).retry(TestData.SCENARIO_RETRY_LIMIT);


Scenario('@functional @mfaLogin I am not able to login with MFA for the block policy ', async (I) => {
const loginUrl = `${TestData.WEB_PUBLIC_URL}/login?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}`;
Expand Down
69 changes: 67 additions & 2 deletions src/test/js/self_registration_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const TestData = require('./config/test_data');
const randomData = require('./shared/random_data');
const assert = require('assert');
const Welsh = require('./shared/welsh_constants');

Feature('Self Registration');

Expand Down Expand Up @@ -65,8 +66,9 @@ Scenario('@functional @selfregister User Validation errors', (I) => {
I.see('Sign in');
}).retry(TestData.SCENARIO_RETRY_LIMIT);

Scenario('@functional @selfregister Account already created', async (I) => {
Scenario('@functional @selfregister @welshLanguage Account already created (no language)', async (I) => {

I.clearCookie(Welsh.localeCookie);
I.amOnPage(selfRegUrl);
I.waitInUrl('users/selfRegister', 180);
I.waitForText('Create an account or sign in', 20, 'h1');
Expand All @@ -85,11 +87,36 @@ Scenario('@functional @selfregister Account already created', async (I) => {

});

Scenario('@functional @selfregister I can self register', async (I) => {
Scenario('@functional @selfregister @welshLanguage Account already created (force Welsh)', async (I) => {

I.clearCookie(Welsh.localeCookie);
I.amOnPage(selfRegUrl + Welsh.urlForceCy);
I.waitInUrl('users/selfRegister', 180);
I.waitForText(Welsh.createAnAccountOrSignIn, 20, 'h1');

let cookie = await I.grabCookie(Welsh.localeCookie);
assert(cookie.value, 'cy');

I.see(Welsh.createAnAccount);
I.fillField('firstName', randomUserFirstName);
I.fillField('lastName', randomUserLastName);
I.fillField('email', citizenEmail);
I.click(Welsh.continueBtn);

I.waitForText(Welsh.checkYourEmail, 20, 'h1');

I.wait(5);
const emailResponse = await I.getEmail(citizenEmail);
assert.equal(Welsh.youAlreadyHaveAccountSubject, emailResponse.subject);

});

Scenario('@functional @selfregister @welshLanguage I can self register (no language)', async (I) => {

const email = 'test_citizen.' + randomData.getRandomEmailAddress();
const loginPage = `${TestData.WEB_PUBLIC_URL}/login?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}&state=selfreg`;

I.clearCookie(Welsh.localeCookie);
I.amOnPage(selfRegUrl);
I.waitInUrl('users/selfRegister', 180);
I.waitForText('Create an account or sign in', 20, 'h1');
Expand Down Expand Up @@ -123,6 +150,44 @@ Scenario('@functional @selfregister I can self register', async (I) => {
I.resetRequestInterception();
});

Scenario('@functional @selfregister @welshLanguage I can self register (Welsh)', async (I) => {

const email = 'test_citizen.' + randomData.getRandomEmailAddress();
const loginPage = `${TestData.WEB_PUBLIC_URL}/login?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}&state=selfreg`;

I.amOnPage(selfRegUrl + Welsh.urlForceCy);
I.waitInUrl('users/selfRegister', 180);
I.waitForText(Welsh.createAnAccountOrSignIn, 20, 'h1');

I.see(Welsh.createAnAccount);
I.fillField('firstName', randomUserFirstName);
I.fillField('lastName', randomUserLastName);
I.fillField('email', email);
I.click(Welsh.continueBtn);
I.waitForText(Welsh.checkYourEmail, 20, 'h1');
I.wait(5);
const userActivationUrl = await I.extractUrl(email);
I.amOnPage(userActivationUrl);
I.waitForText(Welsh.createAPassword, 20, 'h1');
I.seeTitleEquals(Welsh.userActivationTitle);
I.fillField('#password1', TestData.PASSWORD);
I.fillField('#password2', TestData.PASSWORD);
I.click(Welsh.continueBtn);
I.waitForText(Welsh.accountCreated, 20, 'h1');
I.see(Welsh.youCanNowSignIn);
I.amOnPage(loginPage);
I.seeInCurrentUrl("state=selfreg");
I.waitForText(Welsh.signInOrCreateAccount, 20, 'h1');
I.fillField('#username', email);
I.fillField('#password', TestData.PASSWORD);
I.interceptRequestsAfterSignin();
I.click(Welsh.signIn);
I.waitForText(TestData.SERVICE_REDIRECT_URI);
I.see('code=');
I.dontSee('error=');
I.resetRequestInterception();
});

Scenario('@functional @selfregister I can self register and cannot use activation link again', async (I) => {

const email = 'test_citizen.' + randomData.getRandomEmailAddress();
Expand Down
5 changes: 4 additions & 1 deletion src/test/js/shared/idam_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ class IdamHelper extends Helper {
}

async extractOtpFromEmail(searchEmail) {
const emailResponse = await this.getEmail(searchEmail);
return this.extractOtpFromEmailBody(await this.getEmail(searchEmail))
}

async extractOtpFromEmailBody(emailResponse) {
if(emailResponse) {
const regex = "[0-9]{8}";
const url = emailResponse.body.match(regex);
Expand Down
37 changes: 37 additions & 0 deletions src/test/js/shared/welsh_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const TestData = require('./../config/test_data');

const localeParam = 'ui_locales';
const localeCookie = 'idam_ui_locales';

module.exports = {
localeParam: localeParam,
localeCookie: localeCookie,

pageUrl: TestData.WEB_PUBLIC_URL,

accessDeniedWelsh: 'Mynediad wedi\'i wrthod',
pageUrlWithParamWelsh: `${TestData.WEB_PUBLIC_URL}?${localeParam}=cy`,
pageUrlWithParamEnglish: `${TestData.WEB_PUBLIC_URL}?${localeParam}=en`,

urlForceEn: `&${localeParam}=en`,
urlForceCy: `&${localeParam}=cy`,
urlInvalidLang: `&${localeParam}=invalid`,

createAnAccountOrSignIn: 'Creu cyfrif neu fewngofnodi',
createAnAccount: 'Creu cyfrif',
continueBtn: 'Parhau',
checkYourEmail: 'Gwiriwch eich negeseuon e-bost',
youAlreadyHaveAccountSubject: 'Mae gennych gyfrif yn barod / You already have an account',
createAPassword: 'Creu cyfrinair',
userActivationTitle: 'Actifadu Cyfrif Defnyddiwr - Mynediad GLlTEM',
accountCreated: 'Mae eich cyfrif wedi cael ei greu',
youCanNowSignIn: 'Gallwch nawr fewngofnodi i’ch cyfrif.',
signIn: 'Mewngofnodi',
signInOrCreateAccount: 'Mewngofnodwch neu crëwch gyfrif',
forgottenPassword: 'Wedi anghofio eich cyfrinair?',
resetYourPassword: 'ailosod eich cyfrinair',
submitBtn: 'Cyflwyno',
createANewPassword: 'Creu cyfrinair newydd',
passwordChanged: 'Mae eich cyfrinair wedi cael ei newid',
verificationRequired: 'Mae angen dilysu eich cyfrif'
};
105 changes: 105 additions & 0 deletions src/test/js/welsh_language_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const TestData = require('./config/test_data');
const randomData = require('./shared/random_data');
const assert = require('assert');
const Welsh = require('./shared/welsh_constants');

Feature('Welsh Language');

const serviceName = randomData.getRandomServiceName();
const citizenEmail = 'citizen.' + randomData.getRandomEmailAddress();

let userFirstNames = [];
let serviceNames = [];
let randomUserFirstName;
let randomUserLastName;
let specialCharacterPassword;


BeforeSuite(async (I) => {
randomUserFirstName = randomData.getRandomUserName();
randomUserLastName = randomData.getRandomUserName();
await I.createServiceData(serviceName);
serviceNames.push(serviceName);
await I.createUserWithRoles(citizenEmail, randomUserFirstName, ["citizen"]);
userFirstNames.push(randomUserFirstName);
specialCharacterPassword = 'New%%%&&&234';
});

AfterSuite(async (I) => {
return await I.deleteAllTestData(randomData.TEST_BASE_PREFIX);
});

Scenario('@functional @welshLanguage There is a language switch that is working', async (I) => {

const welshLinkValue = 'Cymraeg';
const englishLinkValue = 'English';

I.amOnPage(Welsh.pageUrlWithParamEnglish);

I.waitForText('Access Denied', 20, 'h1');
I.waitForText(welshLinkValue);

I.click(welshLinkValue);
I.waitForText(Welsh.accessDeniedWelsh, 20, 'h1');
I.waitForText(englishLinkValue);

I.click(englishLinkValue);
I.waitForText(welshLinkValue, 20);
});

Scenario('@functional @welshLanguage I can set the language with a cookie', async (I) => {

I.amOnPage(Welsh.pageUrl);
I.setCookie({name: Welsh.localeCookie, value: 'cy'});
I.amOnPage(Welsh.pageUrl);
I.waitForText(Welsh.accessDeniedWelsh, 20, 'h1');
});

Scenario('@functional @welshLanguage I can set the language with a header', async (I) => {

I.amOnPage(Welsh.pageUrl);
I.clearCookie(Welsh.localeCookie);
I.haveRequestHeaders({'Accept-Language': 'cy'});
I.amOnPage(Welsh.pageUrl);
I.waitForText(Welsh.accessDeniedWelsh, 20, 'h1');
});

Scenario('@functional @welshLanguage I can set the language with a parameter', async (I) => {

I.amOnPage(Welsh.pageUrl);
I.clearCookie(Welsh.localeCookie);
I.amOnPage(Welsh.pageUrlWithParamWelsh);
I.waitForText(Welsh.accessDeniedWelsh, 20, 'h1');
});

Scenario('@functional @welshLanguage I can set the language to English with an invalid parameter', async (I) => {

I.amOnPage(Welsh.pageUrl);
I.clearCookie(Welsh.localeCookie);
I.amOnPage(Welsh.pageUrl + '?' + Welsh.urlInvalidLang);
I.waitForText('Access Denied', 20, 'h1');
});

Scenario('@functional @welshLanguage I can reset my password in Welsh', async (I) => {

const loginPage = `${TestData.WEB_PUBLIC_URL}/login?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}${Welsh.urlForceCy}`;

I.amOnPage(loginPage);
I.waitForText(Welsh.signInOrCreateAccount, 20, 'h1');
I.see(Welsh.forgottenPassword);
I.click(Welsh.forgottenPassword);
I.waitInUrl('reset/forgotpassword');
I.waitForText(Welsh.resetYourPassword, 20, 'h1');
I.fillField('#email', citizenEmail);
I.click(Welsh.submitBtn);
I.waitForText(Welsh.checkYourEmail, 20, 'h1');
I.wait(5);
const userPwdResetUrl = await I.extractUrl(citizenEmail);
I.amOnPage(userPwdResetUrl);
I.waitForText(Welsh.createANewPassword, 20, 'h1');
I.fillField('#password1', specialCharacterPassword);
I.fillField('#password2', specialCharacterPassword);
I.click(Welsh.continueBtn);
I.waitInUrl('doResetPassword');
I.waitForText(Welsh.passwordChanged, 20, 'h1');
});

0 comments on commit 15bb408

Please sign in to comment.