diff --git a/playwright-staging/package.json b/playwright-staging/package.json index f084a177..3dbe85a9 100644 --- a/playwright-staging/package.json +++ b/playwright-staging/package.json @@ -16,6 +16,7 @@ "uuid": "8.3.2" }, "scripts": { - "test:sanity": "FORCE_COLOR=1 playwright test --grep '@sanity'" + "test:sanity": "FORCE_COLOR=1 playwright test --grep '@sanity'", + "test:regression": "FORCE_COLOR=1 playwright test --grep '@regression'" } } diff --git a/playwright-staging/tests/submit/erp.spec.js b/playwright-staging/tests/submit/erp.spec.js new file mode 100644 index 00000000..f83e91ee --- /dev/null +++ b/playwright-staging/tests/submit/erp.spec.js @@ -0,0 +1,100 @@ +// @ts-check +const { expect } = require('@playwright/test'); +const { test } = require('../../browserstack'); +const { Commands } = require('../utils/commands'); +const { ErpNextTester } = require('@comicrelief/test-utils/ErpNextTester'); +const Chance = require('chance'); +const chance = new Chance(); + +const erpTester = new ErpNextTester( + process.env.ERP_HOST, + process.env.ERP_API_KEY, + process.env.ERP_API_SECRET, +); + +test('Verify giftaid submit ERP data @regression', async ({ page }) => { + const commands = new Commands(page); + const rndmString = await commands.randomString(); + + const contactInfo = { + mobile: chance.phone({ country: 'uk', mobile: true }).replace(/\s/g, ''), // Remove spaces from the phone number + firstName: `test${rndmString}`, + lastName: chance.last(), + email: `giftaid-staging-${chance.email()}`, + postcode: chance.postcode(), + address1: chance.address(), + address2: chance.street(), + address3: 'test address 3', + town: chance.city() + }; + + // Navigate to the giftaid page + await page.goto(process.env.BASE_URL, { timeout: 30000 }); + await page.waitForLoadState('domcontentloaded'); + + // Click the Giftaid checkbox + await page.click('#field-label--giftaid'); + + // Populate all the form fields with valid inputs + await commands.populateFormFields(page, contactInfo); + + // Select marketing preferences as required + await commands.selectMarketingPrefs(page); + + // Submit the form and wait for the navigation to ensure the submission goes through + await Promise.all([ + page.waitForNavigation(), // This ensures that the navigation happens before the check + page.click('button[type=submit]') + ]); + + // Check for the thank you message to confirm successful submission + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText(`Thank you, ${contactInfo.firstName}!`); + + // ERP Steps + const giftaidSubmit = await erpTester.findOne('Gift Aid Declaration', { + filters: [ + { + field: 'first_name', + value: contactInfo.firstName + } + ] + }, 60, 10000); + + console.log('Fetching Giftaid submit data from ERP'); + expect(giftaidSubmit.first_name).toEqual(contactInfo.firstName); + expect(giftaidSubmit.last_name).toEqual(contactInfo.lastName); + expect(giftaidSubmit.can_claim_giftaid).toEqual(1); + expect(giftaidSubmit.source).toEqual('Giftaid Submit'); + + // Supporter ID + const supporterUUID = giftaidSubmit.supporter_uuid; + + console.log('Fetching supporter from ERP'); + const supporter = await erpTester.get('Supporter', supporterUUID, 30, 10000); + + console.log('Fetching supporter data from ERP'); + expect(supporter.first_name).toEqual(contactInfo.firstName); + expect(supporter.last_name).toEqual(contactInfo.lastName); + + // Fetch supporter's phone number + expect(supporter.phone[0].type).toEqual('Mobile'); + expect(supporter.phone[0].number).toEqual(contactInfo.mobile.replace(/^[07]{1}/, '+44')); + + // Get supporter's postal ID + const getPostalID = supporter.giftaid_declarations[0]; + const postalID = getPostalID.postal_id; + console.log('postalID', postalID); + + // Fetch supporter's postal data + console.log('Fetching postal data from ERP'); + const postal = await erpTester.get('Postal', postalID, 30, 10000); + expect(postal.name).toEqual(postalID); + expect(postal.line_1).toEqual(contactInfo.address1); + expect(postal.line_2).toEqual(contactInfo.address2); + expect(postal.line_3).toEqual(contactInfo.address3); + expect(postal.post_code).toEqual(contactInfo.postcode); + expect(postal.town).toEqual(contactInfo.town); + expect(postal.country).toEqual('GB'); + + await page.close(); +}); diff --git a/playwright-staging/tests/submit/formValidation.spec.js b/playwright-staging/tests/submit/formValidation.spec.js index 6516fc6b..636e110f 100644 --- a/playwright-staging/tests/submit/formValidation.spec.js +++ b/playwright-staging/tests/submit/formValidation.spec.js @@ -77,6 +77,6 @@ test.describe('Form validation @sanity @nightly-sanity', () => { await page.locator('#field-input--lastname').fill(''); await commands.populateFormFields(page); await page.locator('button[type=submit]').click(); - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); }); }); diff --git a/playwright-staging/tests/submit/internationalAddressesValidation.spec.js b/playwright-staging/tests/submit/internationalAddressesValidation.spec.js index cddbd77a..f2823116 100644 --- a/playwright-staging/tests/submit/internationalAddressesValidation.spec.js +++ b/playwright-staging/tests/submit/internationalAddressesValidation.spec.js @@ -38,7 +38,7 @@ test.describe('International addresses validation @sanity @nightly-sanity', () = // Submit the form and ensure no errors are shown for international address await commands.selectMarketingPrefs(page); // Assuming this handles checkbox interactions await page.click('button[type=submit]'); - await expect(page.locator('div > h1')).toContainText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toContainText('Thank you, test!'); await page.close(); }); diff --git a/playwright-staging/tests/submit/marketingPreferencesData.spec.js b/playwright-staging/tests/submit/marketingPreferencesData.spec.js index 92170f11..140313c1 100644 --- a/playwright-staging/tests/submit/marketingPreferencesData.spec.js +++ b/playwright-staging/tests/submit/marketingPreferencesData.spec.js @@ -38,7 +38,7 @@ test('Verify giftaid marketing preferences data in contact-store @sanity @nightl await page.locator('button[type=submit]').click(); // Verify success message - await expect(page.locator('div > h1')).toHaveText(`Thank you, ${firstName}!`); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText(`Thank you, ${firstName}!`); // Retrieve and verify marketing preferences data const mpData = await MarketingPrefsVerify.get(email); diff --git a/playwright-staging/tests/submit/marketingPreferencesValidation.spec.js b/playwright-staging/tests/submit/marketingPreferencesValidation.spec.js index 602a3553..f7fe5c6e 100644 --- a/playwright-staging/tests/submit/marketingPreferencesValidation.spec.js +++ b/playwright-staging/tests/submit/marketingPreferencesValidation.spec.js @@ -6,7 +6,7 @@ const { Commands } = require('../utils/commands'); const Chance = require('chance'); const chance = new Chance(); -const email = `giftaid-staging-${Date.now().toString()}@email.sls.comicrelief.com`; +const email = `giftaid-update-staging-${chance.email()}`; const phone = chance.phone({ country: 'uk', mobile: false }).replace(/\s/g, ''); test.describe('Marketing preferences validation @sanity @nightly-sanity', () => { @@ -35,7 +35,7 @@ test.describe('Marketing preferences validation @sanity @nightly-sanity', () => // Submit the form await page.click('button[type=submit]'); - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); }); test('Validate email marketing preference field', async ({ page }) => { @@ -53,7 +53,7 @@ test.describe('Marketing preferences validation @sanity @nightly-sanity', () => // Re-enter valid email and submit await page.fill('input#field-input--email', email); await page.click('button[type=submit]'); - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); }); test('Validate phone marketing preference field', async ({ page }) => { @@ -71,6 +71,6 @@ test.describe('Marketing preferences validation @sanity @nightly-sanity', () => // Re-enter valid phone number and submit await page.fill('input#field-input--phone', phone); await page.click('button[type=submit]'); - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); }); }); diff --git a/playwright-staging/tests/submit/postcodeLookup.spec.js b/playwright-staging/tests/submit/postcodeLookup.spec.js index 3670b38e..79d71b8e 100644 --- a/playwright-staging/tests/submit/postcodeLookup.spec.js +++ b/playwright-staging/tests/submit/postcodeLookup.spec.js @@ -45,7 +45,7 @@ test.describe('Postcode validation @sanity @nightly-sanity', () => { } await page.click('button[type=submit]'); - await expect(page.locator('div > h1')).toContainText('Thank you,\n' + 'test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toContainText('Thank you,\n' + 'test!'); await page.close(); }); diff --git a/playwright-staging/tests/submit/validFormSubmission.spec.js b/playwright-staging/tests/submit/validFormSubmission.spec.js index fbd88947..d9264b86 100644 --- a/playwright-staging/tests/submit/validFormSubmission.spec.js +++ b/playwright-staging/tests/submit/validFormSubmission.spec.js @@ -26,7 +26,7 @@ test('Valid giftaid submission @sanity @nightly-sanity', async ({ page }) => { ]); // Check for the thank you message to confirm successful submission - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); await page.close(); }); diff --git a/playwright-staging/tests/update/erp.spec.js b/playwright-staging/tests/update/erp.spec.js new file mode 100644 index 00000000..e71566af --- /dev/null +++ b/playwright-staging/tests/update/erp.spec.js @@ -0,0 +1,91 @@ +// @ts-check +const { expect } = require('@playwright/test'); +const { test } = require('../../browserstack'); +const { Commands } = require('../utils/commands'); +const { ErpNextTester } = require('@comicrelief/test-utils/ErpNextTester'); +const Chance = require('chance'); +const chance = new Chance(); + +const erpTester = new ErpNextTester( + process.env.ERP_HOST, + process.env.ERP_API_KEY, + process.env.ERP_API_SECRET, +); + +test('Verify giftaid update ERP data @regression', async ({ page }) => { + const commands = new Commands(page); + const rndmString = await commands.randomString(); + + const contactInfo = { + firstName: `testUpdate${chance.first()}`, + lastName: chance.last(), + email: `giftaid-update-staging-${chance.email()}`, + mobile: chance.phone({ country: 'uk', mobile: true }).replace(/\s/g, ''), + postcode: chance.postcode(), + address1: chance.address(), + address2: chance.street(), + address3: 'test address 3', + town: chance.city(), + }; + + // Navigate to the Giftaid update page + await page.goto(`${process.env.BASE_URL}update`, { timeout: 30000 }); + await page.waitForLoadState('domcontentloaded'); + + // Populate all input fields with valid data + await commands.populateUpdateFormFields(page, contactInfo); + + // Select 'Yes' for GiftAid declaration + await page.locator('#giftAidClaimChoice>div:nth-child(2)>label').click(); + + // Submit the form and validate the thank you message + await page.locator('button[type=submit]').click(); + await expect(page.locator('div.success-wrapper--inner h1')).toContainText(`Thank you, ${contactInfo.firstName}!`); + + // ERP Steps + const giftaidUpdate = await erpTester.findOne('Gift Aid Declaration', { + filters: [ + { + field: 'first_name', + value: contactInfo.firstName + } + ] + }, 60, 10000); + + console.log('Fetching Giftaid submit data from ERP'); + expect(giftaidUpdate.first_name).toEqual(contactInfo.firstName); + expect(giftaidUpdate.last_name).toEqual(contactInfo.lastName); + expect(giftaidUpdate.can_claim_giftaid).toEqual(1); + expect(giftaidUpdate.source).toEqual('Giftaid Update'); + + // Supporter ID + const supporterUUID = giftaidUpdate.supporter_uuid; + + console.log('Fetching supporter from ERP'); + const supporter = await erpTester.get('Supporter', supporterUUID, 30, 10000); + + console.log('Fetching supporter data from ERP'); + expect(supporter.first_name).toEqual(contactInfo.firstName); + expect(supporter.last_name).toEqual(contactInfo.lastName); + expect(supporter.giftaid_status).toEqual(1); + expect(supporter.email[0].email).toEqual(contactInfo.email); + expect(supporter.phone[0].number).toEqual(contactInfo.mobile.replace(/^[07]{1}/, '+44')); + + // Get supporter's postal ID + const getPostalID = supporter.giftaid_declarations[0]; + const postalID = getPostalID.postal_id; + console.log('postalID', postalID); + + // Fetch supporter's postal data + console.log('Fetching postal data from ERP'); + const postal = await erpTester.get('Postal', postalID, 30, 10000); + expect(postal.name).toEqual(postalID); + expect(postal.line_1).toEqual(contactInfo.address1); + expect(postal.line_2).toEqual(contactInfo.address2); + expect(postal.line_3).toEqual(contactInfo.address3); + expect(postal.post_code).toEqual(contactInfo.postcode); + expect(postal.town).toEqual(contactInfo.town); + expect(postal.country).toEqual('GB'); + + await page.close(); +}); diff --git a/playwright-staging/tests/update/formValidation.spec.js b/playwright-staging/tests/update/formValidation.spec.js index 4400bb10..529c1c8e 100644 --- a/playwright-staging/tests/update/formValidation.spec.js +++ b/playwright-staging/tests/update/formValidation.spec.js @@ -54,7 +54,7 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { await page.click('#giftAidClaimChoice>div:nth-child(2)>label'); // Select yes for declaration await page.click('button[type=submit]'); // Submit the form - await expect(page.locator('div > h1')).toHaveText('Thank you, John!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, John!'); await page.close(); }); @@ -83,13 +83,13 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { } // Test for a valid email - const validEmail = 'test@comicrelief.com'; + const validEmail = `giftaid-update-staging-${chance.email()}`; await page.fill('input#field-input--email', ''); // clear email field await commands.populateUpdateFormFields(page, { email: validEmail }); await page.click('#giftAidClaimChoice>div:nth-child(3)>label'); // Select no for declaration await page.click('button[type=submit]'); // Submit the form - await expect(page.locator('div > h1')).toHaveText('Thanks for letting us know'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thanks for letting us know'); await page.close(); }); @@ -119,11 +119,11 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { // Validate correct mobile number await page.locator('#field-input--mobile').fill(''); // Ensure the field is cleared and filled with valid data - await commands.populateUpdateFormFields(page, { mobile: mobile }); + await commands.populateUpdateFormFields(page, { lastName: 'test', mobile: mobile }); await page.click('#giftAidClaimChoice>div:nth-child(2)>label'); // Select yes for declaration await page.click('button[type=submit]'); // Submit the form - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); }); test('Postcode validation and form submission', async ({ page }) => { @@ -170,7 +170,7 @@ test.describe('Giftaid Update form validation @sanity @nightly-sanity', () => { await page.click('#giftAidClaimChoice>div:nth-child(2)>label'); // Select yes for declaration await page.click('button[type=submit]'); // Submit the form - await expect(page.locator('div > h1')).toHaveText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thank you, test!'); await page.close(); }); }); diff --git a/playwright-staging/tests/update/giftaidDeclarationOptions.spec.js b/playwright-staging/tests/update/giftaidDeclarationOptions.spec.js index f576d77a..397ba1f1 100644 --- a/playwright-staging/tests/update/giftaidDeclarationOptions.spec.js +++ b/playwright-staging/tests/update/giftaidDeclarationOptions.spec.js @@ -23,7 +23,7 @@ test('Validate Giftaid declaration claim selections @sanity @nightly-sanity', as expect(await page.locator('#giftAidClaimChoice>div:nth-child(2)>input').isChecked()).toBeFalsy(); await page.locator('button[type=submit]').click(); - await expect(page.locator('div > h1')).toHaveText('Thanks for letting us know'); + await expect(page.locator('div.success-wrapper--inner h1')).toHaveText('Thanks for letting us know'); await page.close(); }); diff --git a/playwright-staging/tests/update/internationalAddressesValidation.spec.js b/playwright-staging/tests/update/internationalAddressesValidation.spec.js index 696ae997..9f64900d 100644 --- a/playwright-staging/tests/update/internationalAddressesValidation.spec.js +++ b/playwright-staging/tests/update/internationalAddressesValidation.spec.js @@ -46,7 +46,7 @@ test.describe('International addresses validation on update form @sanity @nightl await page.locator('button[type=submit]').click(); // Thank you message on success page - await expect(page.locator('div > h1')).toContainText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toContainText('Thank you, test!'); await page.close(); }); diff --git a/playwright-staging/tests/update/validFormSubmission.spec.js b/playwright-staging/tests/update/validFormSubmission.spec.js index ab7b5a00..dcfc71f7 100644 --- a/playwright-staging/tests/update/validFormSubmission.spec.js +++ b/playwright-staging/tests/update/validFormSubmission.spec.js @@ -18,7 +18,7 @@ test('Valid giftaid update submission @sanity @nightly-sanity', async ({ page }) // Submit the form and validate the thank you message await page.locator('button[type=submit]').click(); - await expect(page.locator('div > h1')).toContainText('Thank you, test!'); + await expect(page.locator('div.success-wrapper--inner h1')).toContainText('Thank you, test!'); await page.close(); }); diff --git a/playwright-staging/tests/utils/commands.js b/playwright-staging/tests/utils/commands.js index 49fd8043..92a7cf78 100644 --- a/playwright-staging/tests/utils/commands.js +++ b/playwright-staging/tests/utils/commands.js @@ -5,6 +5,14 @@ class Commands { constructor(page) { this.page = page; } + + /** + * Generate a random string of 5 lowercase letters. + * @return {Promise} A promise that resolves to a random string. + */ + async randomString() { + return chance.string({ length: 5, pool: 'abcdefghijklmnopqrstuvwxyz' }); + } /** * Populate giftaid from fields