Skip to content

Instantly share code, notes, and snippets.

@samlucax
Created July 17, 2020 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samlucax/8acb2cb08b16303705c5a250b9e181a3 to your computer and use it in GitHub Desktop.
Save samlucax/8acb2cb08b16303705c5a250b9e181a3 to your computer and use it in GitHub Desktop.
// Sugestão de solução enviada por Vinicius Flores no grupo do Cypress Brasil
describe('Should been possible to validate Update Catalog data in Agena plans table', () => {
before(() => {
cy.fixture('IIYOGI-1517.csv').then(plans => {
lines = plans.split('\n')
})
})
beforeEach(() => {
cy.getAuthZAuthorizationPie().then(responseToken => {
token = responseToken
})
})
it('Should been possible to compare csv with the response API', () => {
console.log(lines.length)
lines.map(line => {
column = line.split(';')
console.log('passou no map')
runCompareGetApiXGetCsvData(token, column)
})
})
})
function getAgenaApiPlansData(token) {
console.log('start promisse')
return new Cypress.Promise(resolve => {
console.log('passou no agena api')
cy.request({
method: 'GET',
url: `${agenaHost}/plans/${column[2]}`,
headers: {
Authorization: `bearer ${token}`,
Accept: 'application/vnd.agena+json;version=3',
'Content-Type': 'application/json',
},
})
.its('body')
.as('response')
resolve(cy.get('@response'))
})
}
function runCompareGetApiXGetCsvData(token, column) {
console.log('esse é o promisse all')
return Cypress.Promise.all([getAgenaApiPlansData(token)]).spread(res => {
console.log('passou no then do request')
expect(res.name).eq(column[0])
expect(res.region).eq(column[1])
expect(JSON.stringify(res.catalogData)).eq(column[3])
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment