Skip to content

Commit

Permalink
Merge pull request #2966 from bolt/tests/add-api-tests
Browse files Browse the repository at this point in the history
Add tests for the API functionality
  • Loading branch information
I-Valchev authored Nov 23, 2021
2 parents 14b7456 + 16a9357 commit 3e1fe2d
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 additions & 0 deletions tests/cypress/integration/api_getcontent.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/// <reference types="cypress" />

describe('As a user I want to fetch all contents of an API' , () => {
it('Checks that GET response equals 200', () => {
cy.login();
cy.visit('/bolt/api');
cy.get('#operations-Content-getContentCollection').eq(0).click();
cy.get('.response-col_status').should('contain', '200');
})

it('Checks if the contents.json is filled with all content', () => {
cy.login();
cy.request({
url: '/api/contents.json',
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body[0]).property('id').to.not.be.oneOf([null, ""])
const respBody = response.body[0];
const fieldId = respBody;
resolve(fieldId)
});
})
})

it('Check if it returns JSON of a single record', () => {
cy.login();
cy.request({
url: '/api/contents/1.json',
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body).property('id').to.not.be.oneOf([null, ""])
const respBody = response.body[0];
const fieldId = respBody;
resolve(fieldId)
});
})
})

it('Check if the JSON LD format is working', () => {
cy.login();
cy.request({
url: '/api/contents.jsonld',
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body).property('hydra:totalItems').to.not.be.oneOf([null, "", 0])
const respBody = response.body;
const fieldId = respBody;
resolve(fieldId)
});
})
})
//TODO fix this test once we can navigate inside object
it('Check if the JSON LD format is working for single contenttypes like homepage', () => {
cy.login();
cy.request({
url: '/api/contents.jsonld?contentType=homepage',
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body).property('hydra:totalItems').to.not.be.oneOf([null, "", 0])
const respBody = response.body;
const fieldId = respBody;
resolve(fieldId)
});
})
})

it('Check if the JSON LD format is working for single records', () => {
cy.login();
cy.request({
url: '/api/contents/1.jsonld',
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body).property('id').to.not.be.oneOf([null, ""])
const respBody = response.body;
const fieldId = respBody;
resolve(fieldId)
});
})
})
})

describe('Test reading JSON Fields', () => {
it('should read the values of the returned data in JSON', () => {
cy.request({
url:`/api/contents/1/fields.json`,
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body[0]).property('name').to.not.be.oneOf([null, ""])
const respBody = response.body[0];
const fieldId = respBody;
resolve(fieldId)
});
})
})

it('should read the values of the returned data in JSON ld', () => {
cy.request({
url:`/api/contents/1/fields.jsonld`,
failOnStatusCode: false,
auth: {
username: 'admin',
password: 'admin%1',
},
}).then((response) => {
return new Promise(resolve => {
expect(response).property('status').to.eq(200)
expect(response.body).property('hydra:totalItems').to.not.be.oneOf([null, "", 0])
const respBody = response.body;
const fieldId = respBody;
resolve(fieldId)
});
})
})
})

0 comments on commit 3e1fe2d

Please sign in to comment.