From 20bb411b1c553cc28ff11363cf5606d758304424 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Thu, 20 Apr 2023 15:08:26 +0100 Subject: [PATCH 1/3] Add Cypress command for conditional test skipping --- CypressTests/cypress/support/commands.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CypressTests/cypress/support/commands.js b/CypressTests/cypress/support/commands.js index 66ea16ef0..0a700511f 100644 --- a/CypressTests/cypress/support/commands.js +++ b/CypressTests/cypress/support/commands.js @@ -22,4 +22,16 @@ // // // -- This will overwrite an existing command -- -// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) + +/** + * Adds a skip capability based on an expression for tests. + * NOTE: You will need to use es5 syntax to be able to access context e.g. + * + * it('does a thing', function () { //do something }) + */ +Cypress.Commands.add('skipWhen', (expr, context) => { + if(expr) { + context.skip.bind(context)(); + } +}) \ No newline at end of file From fdc35a60d2eb3266e3068fae541c6d5f023ceed1 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Thu, 20 Apr 2023 15:37:35 +0100 Subject: [PATCH 2/3] Change tests to skip on dev to use new command --- .../cypress/e2e/FAM-AddTrustKeyPerson.cy.js | 352 +++++++------ .../cypress/e2e/Get-UpdateApplication.cy.js | 490 +++++++++--------- 2 files changed, 421 insertions(+), 421 deletions(-) diff --git a/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js b/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js index 3dec9aef7..c80a37036 100644 --- a/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js +++ b/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js @@ -1,239 +1,237 @@ /// import { AuthorisedUserCanCreateNewFAMTrustKeyPersonBodyPayload } from '../support/payloads/FAM-TrustKeyPerson/AuthorisedUserCanCreateNewFAMTrustKeyPerson.spec' - import { AuthorisedUserCanUpdateNewFAMTrustKeyPersonBodyPayload } from '../support/payloads/FAM-TrustKeyPerson/AuthorisedUserCanUpdateNewFAMTrustKeyPerson.spec' import { AuthorisedUserCannotCreateNewFAMTrustKeyPersonWITHINVALIDDOBBodyPayload } from '../support/payloads/FAM-TrustKeyPerson/AuthorisedUserCannotCreateNewFAMTrustKeyPersonWITHINVALIDDOB.spec' import { UnauthorisedUserCannotUpdateNewFAMTrustKeyPersonBodyPayload } from '../support/payloads/FAM-TrustKeyPerson/UnauthorisedUserCannotUpdateNewFAMTrustKeyPerson.spec' + describe('Academisation API Testing - FAM - Add Trust Key Person', () => { + let apiKey = Cypress.env('apiKey'); + let url = Cypress.env('url'); + let applicationNumber = 10038; + let trustKeyPersonNumber = 0; + it('POST - Verify An UnAuthorised User Is Unable To Create New FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', function () { + cy.skipWhen(url.includes('dev'), this) - let apiKey = Cypress.env('apiKey'); - let url = Cypress.env('url'); - let applicationNumber = 10038; - let trustKeyPersonNumber = 0; + cy.request({ + method: 'POST', + url: url + '/application/' + applicationNumber + '/form-trust/key-person', + failOnStatusCode: false, + headers: + { + 'x-api-key': 'INVALIDAPIKEY' + }, + body: + AuthorisedUserCanCreateNewFAMTrustKeyPersonBodyPayload + }).then((response) => { - /********************* COMMENTING THIS OUT FOR THE PIPELINES IN DEV!!!!!!! ****************** - it('POST - Verify An UnAuthorised User Is Unable To Create New FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', () => { - cy.request({ - method: 'POST', - url: url + '/application/' + applicationNumber + '/form-trust/key-person', - failOnStatusCode: false, - headers: - { - 'x-api-key' : 'INVALIDAPIKEY' - }, - body: - AuthorisedUserCanCreateNewFAMTrustKeyPersonBodyPayload - }).then((response) => { + expect(response).to.have.property('status', 401) + + }) + }) - expect(response).to.have.property('status', 401) + it('POST - Verify An Authorised User Is Able To Create New FAM-Trust Key Person - Form-Trust Key-Person - 200 CREATED Expected', () => { + cy.request({ + method: 'POST', + url: url + '/application/' + applicationNumber + '/form-trust/key-person', + headers: + { + 'x-api-key': apiKey + }, + body: + AuthorisedUserCanCreateNewFAMTrustKeyPersonBodyPayload + }).then((response) => { - }) + expect(response).to.have.property('status', 200) + + }) }) - */ - - it('POST - Verify An Authorised User Is Able To Create New FAM-Trust Key Person - Form-Trust Key-Person - 200 CREATED Expected', () => { - cy.request({ - method: 'POST', - url: url + '/application/' + applicationNumber + '/form-trust/key-person', - headers: - { - 'x-api-key' : apiKey - }, - body: - AuthorisedUserCanCreateNewFAMTrustKeyPersonBodyPayload - }).then((response) => { - - expect(response).to.have.property('status', 200) - - }) - }) - it('POST - Verify An Authorised User Is Unable To Create New FAM-Trust Key Person - Form-Trust Key-Person WITH AN INVALID DOB - 400 BAD REQUEST Expected', () => { - cy.request({ - method: 'POST', - url: url + '/application/' + applicationNumber + '/form-trust/key-person', - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - AuthorisedUserCannotCreateNewFAMTrustKeyPersonWITHINVALIDDOBBodyPayload - }).then((response) => { - - expect(response).to.have.property('status', 400) - - }) + it('POST - Verify An Authorised User Is Unable To Create New FAM-Trust Key Person - Form-Trust Key-Person WITH AN INVALID DOB - 400 BAD REQUEST Expected', () => { + cy.request({ + method: 'POST', + url: url + '/application/' + applicationNumber + '/form-trust/key-person', + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + AuthorisedUserCannotCreateNewFAMTrustKeyPersonWITHINVALIDDOBBodyPayload + }).then((response) => { + + expect(response).to.have.property('status', 400) + }) + }) - /********************* COMMENTING THIS OUT FOR THE PIPELINES IN DEV!!!!!!! ****************** - it('GET - Verify An UNAuthorised User Is UNAble To GET FAM-Trust Key PERSONS - Form-Trust Key-PersonS - 401 UNAUTHORISED Expected', () => { - cy.request({ - method: 'GET', - url: url + '/application/' + applicationNumber + '/form-trust/key-person', - failOnStatusCode: false, - headers: - { - 'x-api-key' : 'INVALIDAPIKEY' - }, - }).then((response) => { - - expect(response).to.have.property('status', 401) + it('GET - Verify An UNAuthorised User Is UNAble To GET FAM-Trust Key PERSONS - Form-Trust Key-PersonS - 401 UNAUTHORISED Expected', function () { + cy.skipWhen(url.includes('dev'), this) + + cy.request({ + method: 'GET', + url: url + '/application/' + applicationNumber + '/form-trust/key-person', + failOnStatusCode: false, + headers: + { + 'x-api-key': 'INVALIDAPIKEY' + }, + }).then((response) => { + + expect(response).to.have.property('status', 401) }) }) -*/ - it('GET - Verify An Authorised User Is Able To GET FAM-Trust Key PERSONS - Form-Trust Key-PersonS - 200 OK Expected', () => { - cy.request({ - method: 'GET', - url: url + '/application/' + applicationNumber + '/form-trust/key-person', - headers: - { - 'x-api-key' : apiKey - }, - }).then((response) => { - - expect(response).to.have.property('status', 200) - expect(response.body[0]).to.have.property('id') - trustKeyPersonNumber = response.body[0].id; + + it('GET - Verify An Authorised User Is Able To GET FAM-Trust Key PERSONS - Form-Trust Key-PersonS - 200 OK Expected', () => { + cy.request({ + method: 'GET', + url: url + '/application/' + applicationNumber + '/form-trust/key-person', + headers: + { + 'x-api-key': apiKey + }, + }).then((response) => { + + expect(response).to.have.property('status', 200) + expect(response.body[0]).to.have.property('id') + trustKeyPersonNumber = response.body[0].id; }) }) - /********************* COMMENTING THIS OUT FOR THE PIPELINES IN DEV!!!!!!! ****************** - it('GET - Verify An UNAuthorised User Is UNAble To GET FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', () => { + it('GET - Verify An UNAuthorised User Is UNAble To GET FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', function () { + cy.skipWhen(url.includes('dev'), this) + cy.request({ - method: 'GET', - url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + 105, - failOnStatusCode: false, - headers: - { - 'x-api-key' : 'INVALIDAPIKEY' - }, - }).then((response) => { + method: 'GET', + url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + 105, + failOnStatusCode: false, + headers: + { + 'x-api-key': 'INVALIDAPIKEY' + }, + }).then((response) => { - expect(response).to.have.property('status', 401) + expect(response).to.have.property('status', 401) -}) + }) -}) -*/ + }) it('GET - Verify An Authorised User Is Able To GET FAM-Trust Key Person - Form-Trust Key-Person - 200 OK Expected', () => { cy.request({ - method: 'GET', - url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + trustKeyPersonNumber, - headers: - { - 'x-api-key' : apiKey - }, - }).then((response) => { + method: 'GET', + url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + trustKeyPersonNumber, + headers: + { + 'x-api-key': apiKey + }, + }).then((response) => { - expect(response).to.have.property('status', 200) - expect(response.body).to.have.property('id') + expect(response).to.have.property('status', 200) + expect(response.body).to.have.property('id') -}) + }) -}) + }) -/********************* COMMENTING THIS OUT FOR THE PIPELINES IN DEV!!!!!!! ****************** -it('PUT - Verify An UNAuthorised User Is UNAble To UPDATE a FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', () => { + it('PUT - Verify An UNAuthorised User Is UNAble To UPDATE a FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', function () { + cy.skipWhen(url.includes('dev'), this) -cy.log(JSON.stringify("Id = " + Cypress.env('responseIDForRequest'))) -cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + 19, - failOnStatusCode: false, - headers: - { - 'x-api-key' : 'INVALIDAPIKEY' - }, - body: + cy.log(JSON.stringify("Id = " + Cypress.env('responseIDForRequest'))) + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + 19, + failOnStatusCode: false, + headers: + { + 'x-api-key': 'INVALIDAPIKEY' + }, + body: UnauthorisedUserCannotUpdateNewFAMTrustKeyPersonBodyPayload }).then((response) => { - expect(response).to.have.property('status', 401) - }) + expect(response).to.have.property('status', 401) + }) -}) -*/ + }) it('PUT - Verify An Authorised User Is Able To UPDATE a FAM-Trust Key Person - Form-Trust Key-Person - 200 OK Expected', () => { cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + trustKeyPersonNumber, - headers: - { - 'x-api-key' : apiKey - }, - body: - AuthorisedUserCanUpdateNewFAMTrustKeyPersonBodyPayload - }).then((response) => { - - expect(response).to.have.property('status', 200) - }) -}) - -// NEED TO COMMENT OUT THE UNAUTH DELETE AS THIS IS NOW DELETING WHEN IT SHOULDN'T BE -/* -it('DELETE - Verify An UNAuthorised User Is UNable To DELETE FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', () => { - cy.request({ - method: 'DELETE', - url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + Cypress.env('responseIDForRequest'), - failOnStatusCode: false, - headers: - { - 'x-api-key' : 'INVALID APIKEY' - }, - }).then((response) => { - - expect(response).to.have.property('status', 401) + method: 'PUT', + url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + trustKeyPersonNumber, + headers: + { + 'x-api-key': apiKey + }, + body: + AuthorisedUserCanUpdateNewFAMTrustKeyPersonBodyPayload + }).then((response) => { - }) + expect(response).to.have.property('status', 200) }) - */ - - // BEST TO TAKE THIS ONE OUT THE PIPELINE SO WE DON'T RUN OUT OF PEOPLE TO DELETE -/* - it('DELETE - Verify An Authorised User Is Able To DELETE FAM-Trust Key Person - Form-Trust Key-Person - 200 OK Expected', () => { - cy.request({ - method: 'DELETE', - url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + Cypress.env('responseIDForRequest'), - headers: - { - 'x-api-key' : apiKey - }, - }).then((response) => { - - expect(response).to.have.property('status', 200) - - }) }) - */ - // WE DON'T CARE ABOUT THIS RIGHT NOW -/* - it('DELETE - Verify An Authorised User Is UNable To DELETE FAM-Trust Key Person THAT DOES NOT EXIST - Form-Trust Key-Person THAT DOES NOT EXIST - 500 SERVER ERROR Expected - (May change to 400 later)', () => { + // NEED TO COMMENT OUT THE UNAUTH DELETE AS THIS IS NOW DELETING WHEN IT SHOULDN'T BE + /* + it('DELETE - Verify An UNAuthorised User Is UNable To DELETE FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', () => { cy.request({ method: 'DELETE', url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + Cypress.env('responseIDForRequest'), failOnStatusCode: false, headers: { - 'x-api-key' : apiKey + 'x-api-key' : 'INVALID APIKEY' }, }).then((response) => { - - expect(response).to.have.property('status', 400) + + expect(response).to.have.property('status', 401) }) - }) - */ + }) + */ + // BEST TO TAKE THIS ONE OUT THE PIPELINE SO WE DON'T RUN OUT OF PEOPLE TO DELETE + /* + it('DELETE - Verify An Authorised User Is Able To DELETE FAM-Trust Key Person - Form-Trust Key-Person - 200 OK Expected', () => { + cy.request({ + method: 'DELETE', + url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + Cypress.env('responseIDForRequest'), + headers: + { + 'x-api-key' : apiKey + }, + }).then((response) => { + + expect(response).to.have.property('status', 200) + }) + }) + */ + + // WE DON'T CARE ABOUT THIS RIGHT NOW + /* + it('DELETE - Verify An Authorised User Is UNable To DELETE FAM-Trust Key Person THAT DOES NOT EXIST - Form-Trust Key-Person THAT DOES NOT EXIST - 500 SERVER ERROR Expected - (May change to 400 later)', () => { + cy.request({ + method: 'DELETE', + url: url + '/application/' + applicationNumber + '/form-trust/key-person' + '/' + Cypress.env('responseIDForRequest'), + failOnStatusCode: false, + headers: + { + 'x-api-key' : apiKey + }, + }).then((response) => { + + expect(response).to.have.property('status', 400) + + }) + }) + */ + + }) \ No newline at end of file diff --git a/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js b/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js index dc5928d43..f92f7e371 100644 --- a/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js +++ b/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js @@ -1,269 +1,271 @@ /// -import {UnauthorisedUserCannotUpdatePayload} from '../support/payloads/UnauthorisedUserCannotUpdateBody.spec' -import {AuthorisedUserCanUpdatePayload} from '../support/payloads/AuthorisedUserCanUpdate.spec' -import {AuthorisedUserCannotUpdateTheirContributorsEmailToAnotherEmailBodyPayload} from '../support/payloads/AuthorisedUserCannotChangeTheirContributorsEmailToAnotherEmail.spec' -import {AuthorisedUserCannotUpdateTheirContributorsEmailToInvalidEmailBodyPayload} from '../support/payloads/AuthorisedUserCannotChangeTheirContributorsEmailToInvalidEmail.spec' -import {AuthorisedUserCannotUpdateWorksPlannedDateToInvalidDateBodyPayload} from '../support/payloads/AuthorisedUserCannotChangeWorksPlannedDateToInvalidDate.spec' -import {AuthorisedUserCannotUpdateSacreExemptionEndDateToInvalidDateBodyPayload} from '../support/payloads/AuthorisedUserCannotChangeSacreExemptionEndDateToInvalidDate.spec' -import {AuthorisedUserCannotUpdateSchoolConversionTargetDateToInvalidDateBodyPayload} from '../support/payloads/AuthorisedUserCannotUpdateSchoolConversionTargetDateToInvalidDateBody.spec' -import {AuthorisedUserCannotUpdatePreviousFinancialYearEndDateToInvalidDateBodyPayload} from '../support/payloads/AuthorisedUserCannotChangePreviousFinancialYearEndDateToInvalidDate.spec' -import {AuthorisedUserCannotUpdateCurrentFinancialYearEndDateToInvalidDateBodyPayload} from '../support/payloads/AuthorisedUserCannotChangeCurrentFinancialYearEndDateToInvalidDate.spec' -import {AuthorisedUserCannotUpdateNextFinancialYearEndDateToInvalidDateBodyPayload} from '../support/payloads/AuthorisedUserCannotChangeNextFinancialYearEndDateToInvalidDate.spec' +import { UnauthorisedUserCannotUpdatePayload } from '../support/payloads/UnauthorisedUserCannotUpdateBody.spec' +import { AuthorisedUserCanUpdatePayload } from '../support/payloads/AuthorisedUserCanUpdate.spec' +import { AuthorisedUserCannotUpdateTheirContributorsEmailToAnotherEmailBodyPayload } from '../support/payloads/AuthorisedUserCannotChangeTheirContributorsEmailToAnotherEmail.spec' +import { AuthorisedUserCannotUpdateTheirContributorsEmailToInvalidEmailBodyPayload } from '../support/payloads/AuthorisedUserCannotChangeTheirContributorsEmailToInvalidEmail.spec' +import { AuthorisedUserCannotUpdateWorksPlannedDateToInvalidDateBodyPayload } from '../support/payloads/AuthorisedUserCannotChangeWorksPlannedDateToInvalidDate.spec' +import { AuthorisedUserCannotUpdateSacreExemptionEndDateToInvalidDateBodyPayload } from '../support/payloads/AuthorisedUserCannotChangeSacreExemptionEndDateToInvalidDate.spec' +import { AuthorisedUserCannotUpdateSchoolConversionTargetDateToInvalidDateBodyPayload } from '../support/payloads/AuthorisedUserCannotUpdateSchoolConversionTargetDateToInvalidDateBody.spec' +import { AuthorisedUserCannotUpdatePreviousFinancialYearEndDateToInvalidDateBodyPayload } from '../support/payloads/AuthorisedUserCannotChangePreviousFinancialYearEndDateToInvalidDate.spec' +import { AuthorisedUserCannotUpdateCurrentFinancialYearEndDateToInvalidDateBodyPayload } from '../support/payloads/AuthorisedUserCannotChangeCurrentFinancialYearEndDateToInvalidDate.spec' +import { AuthorisedUserCannotUpdateNextFinancialYearEndDateToInvalidDateBodyPayload } from '../support/payloads/AuthorisedUserCannotChangeNextFinancialYearEndDateToInvalidDate.spec' describe('Academisation API Testing', () => { - let apiKey = Cypress.env('apiKey'); - let url = Cypress.env('url'); - let applicationNumber = 10002 - let emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ - let getDateTimestampFormatRegex = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})Z?$/ - - - it('GET - Verify An Authorised User Can Retrieve A Respective Application - 200 OK EXPECTED', () => { - cy.request({ - method: 'GET', - url: url + '/application/' + applicationNumber, - headers: - { - 'x-api-key' : apiKey - } - }).then((response) => { - cy.log(JSON.stringify(response)) - expect(response).to.have.property('status', 200) - expect(response.body).to.have.property('contributors') - expect(response.body.contributors[0]).to.have.property('firstName') - expect(response.body.contributors[0]).to.have.property('lastName') - expect(response.body.contributors[0]).to.have.property('emailAddress').to.match(emailRegex) - expect(response.body.contributors[0]).to.have.property('role') - - - expect(response.body).to.have.property('schools') - - // PREVIOUS FINANCIAL YEAR PROPERTIES - expect(response.body.schools[0].previousFinancialYear).to.have.property('financialYearEndDate').to.match(getDateTimestampFormatRegex) - expect(response.body.schools[0].previousFinancialYear).to.have.property('revenue') - expect(response.body.schools[0].previousFinancialYear).to.have.property('revenueStatus') - - expect(response.body.schools[0].previousFinancialYear).to.have.property('capitalCarryForward') - expect(response.body.schools[0].previousFinancialYear).to.have.property('capitalCarryForwardStatus') - - - // CURRENT FINANCIAL YEAR PROPERTIES - expect(response.body.schools[0].currentFinancialYear).to.have.property('financialYearEndDate').to.match(getDateTimestampFormatRegex) - expect(response.body.schools[0].currentFinancialYear).to.have.property('revenue') - expect(response.body.schools[0].currentFinancialYear).to.have.property('revenueStatus') - expect(response.body.schools[0].currentFinancialYear).to.have.property('revenueStatusExplained') - - expect(response.body.schools[0].currentFinancialYear).to.have.property('capitalCarryForward') - expect(response.body.schools[0].currentFinancialYear).to.have.property('capitalCarryForwardStatus') - expect(response.body.schools[0].currentFinancialYear).to.have.property('capitalCarryForwardExplained') - - - // NEXT FINANCIAL YEAR PROPERTIES - expect(response.body.schools[0].nextFinancialYear).to.have.property('financialYearEndDate').to.match(getDateTimestampFormatRegex) - expect(response.body.schools[0].nextFinancialYear).to.have.property('revenue') - expect(response.body.schools[0].nextFinancialYear).to.have.property('revenueStatus') - expect(response.body.schools[0].nextFinancialYear).to.have.property('revenueStatusExplained') - - expect(response.body.schools[0].nextFinancialYear).to.have.property('capitalCarryForward') - expect(response.body.schools[0].nextFinancialYear).to.have.property('capitalCarryForwardStatus') - expect(response.body.schools[0].nextFinancialYear).to.have.property('capitalCarryForwardExplained') - - }) - }) -/********************* COMMENTING THIS OUT FOR THE PIPELINES IN DEV!!!!!!! ****************** - it('GET - Verify An UNAUTHORISED USER CANNOT Retreive An Application - 401 UNAUTHORISED EXPECTED', () => { - cy.request({ - method: 'GET', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false - }).then((response) => { - expect(response).to.have.property('status', 401) - }) - }) - */ - - it('PUT - Verify An Authorised User Can Update An Application Correctly - 200 OK EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - headers: - { - 'x-api-key' : apiKey - }, - body: - AuthorisedUserCanUpdatePayload - }).then((response) => { - cy.log(JSON.stringify(response)) - expect(response).to.have.property('status', 200) + let apiKey = Cypress.env('apiKey'); + let url = Cypress.env('url'); + let applicationNumber = 10002 + let emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/ + let getDateTimestampFormatRegex = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})Z?$/ + + + it('GET - Verify An Authorised User Can Retrieve A Respective Application - 200 OK EXPECTED', () => { + cy.request({ + method: 'GET', + url: url + '/application/' + applicationNumber, + headers: + { + 'x-api-key': apiKey + } + }).then((response) => { + cy.log(JSON.stringify(response)) + expect(response).to.have.property('status', 200) + expect(response.body).to.have.property('contributors') + expect(response.body.contributors[0]).to.have.property('firstName') + expect(response.body.contributors[0]).to.have.property('lastName') + expect(response.body.contributors[0]).to.have.property('emailAddress').to.match(emailRegex) + expect(response.body.contributors[0]).to.have.property('role') + + + expect(response.body).to.have.property('schools') + + // PREVIOUS FINANCIAL YEAR PROPERTIES + expect(response.body.schools[0].previousFinancialYear).to.have.property('financialYearEndDate').to.match(getDateTimestampFormatRegex) + expect(response.body.schools[0].previousFinancialYear).to.have.property('revenue') + expect(response.body.schools[0].previousFinancialYear).to.have.property('revenueStatus') + + expect(response.body.schools[0].previousFinancialYear).to.have.property('capitalCarryForward') + expect(response.body.schools[0].previousFinancialYear).to.have.property('capitalCarryForwardStatus') + + + // CURRENT FINANCIAL YEAR PROPERTIES + expect(response.body.schools[0].currentFinancialYear).to.have.property('financialYearEndDate').to.match(getDateTimestampFormatRegex) + expect(response.body.schools[0].currentFinancialYear).to.have.property('revenue') + expect(response.body.schools[0].currentFinancialYear).to.have.property('revenueStatus') + expect(response.body.schools[0].currentFinancialYear).to.have.property('revenueStatusExplained') + + expect(response.body.schools[0].currentFinancialYear).to.have.property('capitalCarryForward') + expect(response.body.schools[0].currentFinancialYear).to.have.property('capitalCarryForwardStatus') + expect(response.body.schools[0].currentFinancialYear).to.have.property('capitalCarryForwardExplained') + + + // NEXT FINANCIAL YEAR PROPERTIES + expect(response.body.schools[0].nextFinancialYear).to.have.property('financialYearEndDate').to.match(getDateTimestampFormatRegex) + expect(response.body.schools[0].nextFinancialYear).to.have.property('revenue') + expect(response.body.schools[0].nextFinancialYear).to.have.property('revenueStatus') + expect(response.body.schools[0].nextFinancialYear).to.have.property('revenueStatusExplained') + + expect(response.body.schools[0].nextFinancialYear).to.have.property('capitalCarryForward') + expect(response.body.schools[0].nextFinancialYear).to.have.property('capitalCarryForwardStatus') + expect(response.body.schools[0].nextFinancialYear).to.have.property('capitalCarryForwardExplained') + + }) + }) + + it('GET - Verify An UNAUTHORISED USER CANNOT Retreive An Application - 401 UNAUTHORISED EXPECTED', function () { + cy.skipWhen(url.includes('dev'), this) + + cy.request({ + method: 'GET', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false + }).then((response) => { + expect(response).to.have.property('status', 401) + }) + }) + + it('PUT - Verify An Authorised User Can Update An Application Correctly - 200 OK EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + headers: + { + 'x-api-key': apiKey + }, + body: + AuthorisedUserCanUpdatePayload + }).then((response) => { + cy.log(JSON.stringify(response)) + expect(response).to.have.property('status', 200) }) }) it('PUT - Verify An Authorised User Is Unable To Change Their Contributor\'s Email to ANOTHER EMAIL ADDRESS - 400 BAD REQUEST EXPECTED', () => { cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - AuthorisedUserCannotUpdateTheirContributorsEmailToAnotherEmailBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + AuthorisedUserCannotUpdateTheirContributorsEmailToAnotherEmailBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) + }) it('PUT - Verify An Authorised User Is Unable To Change Their Contributor\'s Email to AN INVALID EMAIL ADDRESS - 400 BAD REQUEST EXPECTED', () => { cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - AuthorisedUserCannotUpdateTheirContributorsEmailToInvalidEmailBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + AuthorisedUserCannotUpdateTheirContributorsEmailToInvalidEmailBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - -it('PUT - Verify An Authorised User Is Unable To Change The worksPlannedDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - - AuthorisedUserCannotUpdateWorksPlannedDateToInvalidDateBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + }) + + it('PUT - Verify An Authorised User Is Unable To Change The worksPlannedDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + + AuthorisedUserCannotUpdateWorksPlannedDateToInvalidDateBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - -it('PUT - Verify An Authorised User Is Unable To Change The sacreExemptionDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - AuthorisedUserCannotUpdateSacreExemptionEndDateToInvalidDateBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + }) + + it('PUT - Verify An Authorised User Is Unable To Change The sacreExemptionDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + AuthorisedUserCannotUpdateSacreExemptionEndDateToInvalidDateBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - -it('PUT - Verify An Authorised User Is Unable To Change The previousFinancialYearEndDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - AuthorisedUserCannotUpdatePreviousFinancialYearEndDateToInvalidDateBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + }) + + it('PUT - Verify An Authorised User Is Unable To Change The previousFinancialYearEndDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + AuthorisedUserCannotUpdatePreviousFinancialYearEndDateToInvalidDateBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - -it('PUT - Verify An Authorised User Is Unable To Change The currentFinancialYearEndDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - AuthorisedUserCannotUpdateCurrentFinancialYearEndDateToInvalidDateBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + }) + + it('PUT - Verify An Authorised User Is Unable To Change The currentFinancialYearEndDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + AuthorisedUserCannotUpdateCurrentFinancialYearEndDateToInvalidDateBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - -it('PUT - Verify An Authorised User Is Unable To Change The nextFinancialYearEndDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - - AuthorisedUserCannotUpdateNextFinancialYearEndDateToInvalidDateBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + }) + + it('PUT - Verify An Authorised User Is Unable To Change The nextFinancialYearEndDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + + AuthorisedUserCannotUpdateNextFinancialYearEndDateToInvalidDateBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - -it('PUT - Verify An Authorised User Is Unable To Change The schoolConversionTargetDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - headers: - { - 'x-api-key' : apiKey - }, - body: - AuthorisedUserCannotUpdateSchoolConversionTargetDateToInvalidDateBodyPayload - - - }).then((response) => { - expect(response).to.have.property('status', 400) + }) + + it('PUT - Verify An Authorised User Is Unable To Change The schoolConversionTargetDate To An Invalid Date - 400 BAD REQUEST EXPECTED', () => { + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + headers: + { + 'x-api-key': apiKey + }, + body: + AuthorisedUserCannotUpdateSchoolConversionTargetDateToInvalidDateBodyPayload + + + }).then((response) => { + expect(response).to.have.property('status', 400) }) -}) - /********************* COMMENTING THIS OUT FOR THE PIPELINES IN DEV!!!!!!! ****************** - it('PUT - Verify An UNAUTHORISED USER CANNOT Update An Application - 401 UNAUTHORISED EXPECTED', () => { - cy.request({ - method: 'PUT', - url: url + '/application/' + applicationNumber, - failOnStatusCode: false, - body: - UnauthorisedUserCannotUpdatePayload - - }).then((response) => { - expect(response).to.have.property('status', 401) + }) + + it('PUT - Verify An UNAUTHORISED USER CANNOT Update An Application - 401 UNAUTHORISED EXPECTED', function () { + cy.skipWhen(url.includes('dev'), this) + + cy.request({ + method: 'PUT', + url: url + '/application/' + applicationNumber, + failOnStatusCode: false, + body: + UnauthorisedUserCannotUpdatePayload + + }).then((response) => { + expect(response).to.have.property('status', 401) }) }) -*/ }) \ No newline at end of file From 54bd5c71ad9ab6d9585dea09068ae4433d8f6be7 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Thu, 20 Apr 2023 16:04:19 +0100 Subject: [PATCH 3/3] Change expression for skip tests in Cypress --- CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js | 8 ++++---- CypressTests/cypress/e2e/Get-UpdateApplication.cy.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js b/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js index c80a37036..9ea20811a 100644 --- a/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js +++ b/CypressTests/cypress/e2e/FAM-AddTrustKeyPerson.cy.js @@ -11,7 +11,7 @@ describe('Academisation API Testing - FAM - Add Trust Key Person', () => { let trustKeyPersonNumber = 0; it('POST - Verify An UnAuthorised User Is Unable To Create New FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', function () { - cy.skipWhen(url.includes('dev'), this) + cy.skipWhen(url.includes('d01'), this) cy.request({ method: 'POST', @@ -66,7 +66,7 @@ describe('Academisation API Testing - FAM - Add Trust Key Person', () => { }) it('GET - Verify An UNAuthorised User Is UNAble To GET FAM-Trust Key PERSONS - Form-Trust Key-PersonS - 401 UNAUTHORISED Expected', function () { - cy.skipWhen(url.includes('dev'), this) + cy.skipWhen(url.includes('d01'), this) cy.request({ method: 'GET', @@ -102,7 +102,7 @@ describe('Academisation API Testing - FAM - Add Trust Key Person', () => { }) it('GET - Verify An UNAuthorised User Is UNAble To GET FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', function () { - cy.skipWhen(url.includes('dev'), this) + cy.skipWhen(url.includes('d01'), this) cy.request({ method: 'GET', @@ -140,7 +140,7 @@ describe('Academisation API Testing - FAM - Add Trust Key Person', () => { it('PUT - Verify An UNAuthorised User Is UNAble To UPDATE a FAM-Trust Key Person - Form-Trust Key-Person - 401 UNAUTHORISED Expected', function () { - cy.skipWhen(url.includes('dev'), this) + cy.skipWhen(url.includes('d01'), this) cy.log(JSON.stringify("Id = " + Cypress.env('responseIDForRequest'))) cy.request({ diff --git a/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js b/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js index f92f7e371..086bc5f6d 100644 --- a/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js +++ b/CypressTests/cypress/e2e/Get-UpdateApplication.cy.js @@ -74,7 +74,7 @@ describe('Academisation API Testing', () => { }) it('GET - Verify An UNAUTHORISED USER CANNOT Retreive An Application - 401 UNAUTHORISED EXPECTED', function () { - cy.skipWhen(url.includes('dev'), this) + cy.skipWhen(url.includes('d01'), this) cy.request({ method: 'GET', @@ -254,7 +254,7 @@ describe('Academisation API Testing', () => { }) it('PUT - Verify An UNAUTHORISED USER CANNOT Update An Application - 401 UNAUTHORISED EXPECTED', function () { - cy.skipWhen(url.includes('dev'), this) + cy.skipWhen(url.includes('d01'), this) cy.request({ method: 'PUT',