diff --git a/src/test/js/shared/idam_helper.js b/src/test/js/shared/idam_helper.js index afabe7c66..ffa1c1f9b 100644 --- a/src/test/js/shared/idam_helper.js +++ b/src/test/js/shared/idam_helper.js @@ -504,8 +504,10 @@ class IdamHelper extends Helper { interceptRequestsAfterSignin() { const helper = this.helpers['Puppeteer']; helper.page.setRequestInterception(true); + const pages = ["/login", "/register", "/activate", "/verification"]; + helper.page.on('request', request => { - if (request.url().indexOf('/login') > 0 || request.url().indexOf('/register') > 0 || request.url().indexOf('/activate') > 0 || request.url().indexOf('/verification') > 0) { + if (pages.some(v => request.url().includes(v))) { request.continue(); } else { request.respond({ @@ -604,6 +606,22 @@ class IdamHelper extends Helper { }) } + getOidcUserInfo(accessToken) { + return fetch(`${TestData.IDAM_API}/o/userinfo`, { + agent: agent, + method: 'GET', + headers: { + 'Authorization': 'Bearer ' + accessToken + } + }).then(response => { + if (response.status != 200) { + console.log('Error getting user details', response.status); + throw new Error() + } + return response.json(); + }) + } + grantRoleToUser(roleName, accessToken) { return fetch(`${TestData.IDAM_API}/account/role`, { agent: agent, diff --git a/src/test/js/uplift_user_test.js b/src/test/js/uplift_user_test.js index e6321fed8..0d9e07bd3 100644 --- a/src/test/js/uplift_user_test.js +++ b/src/test/js/uplift_user_test.js @@ -1,5 +1,7 @@ const TestData = require('./config/test_data'); const randomData = require('./shared/random_data'); +const chai = require('chai'); +const {expect} = chai; Feature('I am able to uplift a user'); @@ -48,6 +50,29 @@ AfterSuite(async (I) => { return await I.deleteAllTestData(randomData.TEST_BASE_PREFIX); }); +After((I) => { + I.resetRequestInterception(); +}); + +Scenario('@functional @loginWithPin As a Defendant, I should be able to login with the pin received from the Claimant', async (I) => { + let pinUser = await I.getPinUser(randomUserFirstName, randomUserLastName); + I.amOnPage(`${TestData.WEB_PUBLIC_URL}/login/pin?redirect_uri=${TestData.SERVICE_REDIRECT_URI}&client_id=${serviceName}`); + I.waitForText('Enter security code', 30, 'h1'); + I.fillField('#pin', pinUser.pin); + + I.interceptRequestsAfterSignin(); + I.click('Continue'); + I.waitForText(TestData.SERVICE_REDIRECT_URI); + I.see('code='); + + let pageSource = await I.grabSource(); + let code = pageSource.match(/\?code=([^&]*)(.*)/)[1]; + let accessToken = await I.getAccessToken(code, serviceName, TestData.SERVICE_REDIRECT_URI, TestData.SERVICE_CLIENT_SECRET); + + let userInfo = await I.retry({retries: 3, minTimeout: 10000}).getOidcUserInfo(accessToken); + expect(userInfo.roles).to.eql(['letter-holder']); +}); + Scenario('@functional @uplift @upliftvalid User Validation errors', (I) => { I.amOnPage(`${TestData.WEB_PUBLIC_URL}/login/uplift?client_id=${serviceName}&redirect_uri=${TestData.SERVICE_REDIRECT_URI}&jwt=${accessToken}`); I.waitForText('Create an account or sign in', 30, 'h1'); @@ -121,5 +146,4 @@ Scenario('@functional @uplift @upliftLogin uplift a user via login journey', asy I.waitForText(TestData.SERVICE_REDIRECT_URI); I.see('code='); I.dontSee('error='); - I.resetRequestInterception(); }); \ No newline at end of file