-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add legacy Cypress tests for v1, v2 and v3 endpoints (#432)
* Add legacy Cypress tests for outstanding v1, v2 and v3 endpoints
- Loading branch information
Showing
9 changed files
with
200 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
describe('Key Stage Performance endpoint tests', () => { | ||
|
||
const apiKey = Cypress.env('apiKey') | ||
const url = Cypress.env('url') | ||
const urn = '100000' | ||
const schoolName = 'The Aldgate School' | ||
|
||
it('Returns education performance data when URN supplied', () => { | ||
|
||
cy.api({ | ||
method: 'GET', | ||
url: `${url}/educationPerformance/${urn}`, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.schoolName).to.eq(schoolName) | ||
expect(response.body).to.include.keys('schoolName', 'keyStage1', 'keyStage2', 'keyStage4', 'keyStage5') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
describe("Baseline Tracker endpoint", () => { | ||
|
||
const apiKey = Cypress.env('apiKey') | ||
const baseUrlV2 = `${Cypress.env('url')}/v2` | ||
|
||
it("Should return a list of baseline trackers when default parameters set", () => { | ||
|
||
// TODO change url endpoint when spelling mistake resolved | ||
cy.api({ | ||
method: 'GET', | ||
url: `${baseUrlV2}/basline-tracker`, | ||
qs: { | ||
page: 1, | ||
count: 50 | ||
}, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.data).to.have.lengthOf.at.least(1).and.lengthOf.at.most(50) | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
describe('Trusts endpoints tests', () => { | ||
|
||
const apiKey = Cypress.env('apiKey') | ||
const baseUrlV3 = `${Cypress.env('url')}/v3` | ||
const companiesHouseNumber = '11082297' | ||
const ukprn = '10067112' | ||
const groupName = 'SOUTH YORK MULTI ACADEMY TRUST' | ||
|
||
context('Search Trusts', () => { | ||
|
||
it('should return a list of trusts when default search parameters set', () => { | ||
|
||
cy.api({ | ||
method: 'GET', | ||
url: `${baseUrlV3}/trusts`, | ||
qs: { | ||
page: 1, | ||
count: 50 | ||
}, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.data).to.have.lengthOf.at.least(1).and.lengthOf.at.most(50) | ||
expect(response.body.paging.page).to.eq(1) | ||
}) | ||
}) | ||
|
||
it('should return a single trust when group name set', () => { | ||
|
||
cy.api({ | ||
method: 'GET', | ||
url: `${baseUrlV3}/trusts`, | ||
qs: { | ||
groupName: groupName, | ||
page: 1, | ||
count: 50 | ||
}, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.data[0].groupName).to.eq(groupName) | ||
}) | ||
}) | ||
|
||
it('should return a single trust when UKPRN set', () => { | ||
|
||
cy.api({ | ||
method: 'GET', | ||
url: `${baseUrlV3}/trusts`, | ||
qs: { | ||
ukPrn: ukprn, | ||
page: 1, | ||
count: 50 | ||
}, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.data[0].groupName).to.eq(groupName) | ||
}) | ||
}) | ||
|
||
it('should return a single trust when Companies House Number set', () => { | ||
|
||
cy.api({ | ||
method: 'GET', | ||
url: `${baseUrlV3}/trusts`, | ||
qs: { | ||
companiesHouseNumber: companiesHouseNumber, | ||
page: 1, | ||
count: 50 | ||
}, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.data[0].groupName).to.eq(groupName) | ||
expect(response.body.data[0].companiesHouseNumber).to.eq(companiesHouseNumber) | ||
}) | ||
}) | ||
}) | ||
|
||
context('Get Trust by UKPRN', () => { | ||
|
||
it('should return a single trust when UKPRN set', () => { | ||
|
||
cy.api({ | ||
method: 'GET', | ||
url: `${baseUrlV3}/trust/${ukprn}`, | ||
headers: { | ||
ApiKey: apiKey, | ||
"Content-type": "application/json" | ||
} | ||
}) | ||
.then((response) => { | ||
expect(response.status).to.eq(200) | ||
expect(response.body.data).to.include.keys('trustData', 'giasData', 'establishments') | ||
expect(response.body.data.giasData.groupName).to.eq(groupName) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import Ajv from "ajv"; | ||
import Ajv from "ajv" | ||
import addFormats from "ajv-formats" | ||
|
||
// error message | ||
const getSchemaError = (getAjvError) => { | ||
return cy.wrap( | ||
`Field: ${getAjvError[0]["dataPath"]} is invalid. Cause: ${getAjvError[0]["message"]}` | ||
); | ||
}; | ||
) | ||
} | ||
|
||
// commands function | ||
export const validateSchema = (schema, response) => { | ||
|
||
const ajv = new Ajv() | ||
addFormats(ajv) | ||
const validate = ajv.compile(schema); | ||
const validate = ajv.compile(schema) | ||
|
||
const valid = validate(response); | ||
const valid = validate(response) | ||
console.log(validate.errors) | ||
|
||
if (!valid) { | ||
getSchemaError(validate.errors).then((schemaError) => { | ||
throw new Error(schemaError); | ||
}); | ||
throw new Error(schemaError) | ||
}) | ||
} else { | ||
cy.log("Schema validated!"); | ||
cy.log("Schema validated!") | ||
} | ||
}; | ||
} |