From aaa2d134f7bd7dd5038ceed3170beac14d8c6f89 Mon Sep 17 00:00:00 2001 From: Joossensei Date: Tue, 23 Nov 2021 13:20:07 +0100 Subject: [PATCH 1/2] Add new tests and fix old ones This should work :D --- .../integration/api_getcontent.spec.js | 150 ++++++++++++++++++ .../integration/edit_record_1_field.spec.js | 4 +- tests/cypress/support/index.js | 2 + 3 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 tests/cypress/integration/api_getcontent.spec.js diff --git a/tests/cypress/integration/api_getcontent.spec.js b/tests/cypress/integration/api_getcontent.spec.js new file mode 100644 index 0000000000..5dd0b4ae6d --- /dev/null +++ b/tests/cypress/integration/api_getcontent.spec.js @@ -0,0 +1,150 @@ +/// + +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) + }); + }) + }) +}) diff --git a/tests/cypress/integration/edit_record_1_field.spec.js b/tests/cypress/integration/edit_record_1_field.spec.js index c4019d8980..fa5e4ece42 100644 --- a/tests/cypress/integration/edit_record_1_field.spec.js +++ b/tests/cypress/integration/edit_record_1_field.spec.js @@ -46,8 +46,8 @@ describe('As an Admin, I want to reset an image field', () => { cy.get('a[id="media-tab"]').click(); cy.get("label[for=field-image]").should('contain', 'Image'); - cy.get('input[name="fields[image][filename]"]').should('have.value', 'foal.jpg'); - cy.get('input[name="fields[image][alt]"]').should('have.value', 'Ex veniam repellat ipsam autem delectus.'); + cy.get('input[name="fields[image][filename]"]').should('have.value', 'stock/image_40862.jpg'); + cy.get('input[name="fields[image][alt]"]').should('have.value', 'Voluptate nemo quam natus harum numquam.'); cy.get('button[class="btn btn-sm btn-hidden-danger"]').should('contain', 'Remove').eq(0).click(); cy.get('input[name="fields[image][filename]"]').should('have.value', ''); diff --git a/tests/cypress/support/index.js b/tests/cypress/support/index.js index cfcd5aebc8..02fe3beb7a 100644 --- a/tests/cypress/support/index.js +++ b/tests/cypress/support/index.js @@ -31,6 +31,8 @@ Cypress.Commands.add('login', (username = 'admin', password = 'admin%1') => { cy.url().should('include', '/bolt/login'); + cy.get('input[name="login[username]"]').type('{selectall}{backspace}'); + cy.get('input[name="login[username]"]').type(username); cy.get('input[name="login[password]"]').type(password + '{enter}'); From 16a935753893fd554892b816684203e8000d5ee9 Mon Sep 17 00:00:00 2001 From: Joossensei Date: Tue, 23 Nov 2021 13:55:46 +0100 Subject: [PATCH 2/2] Revert changes to standard tests Ill make a different pull request for these --- tests/cypress/integration/edit_record_1_field.spec.js | 4 ++-- tests/cypress/support/index.js | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/cypress/integration/edit_record_1_field.spec.js b/tests/cypress/integration/edit_record_1_field.spec.js index fa5e4ece42..c4019d8980 100644 --- a/tests/cypress/integration/edit_record_1_field.spec.js +++ b/tests/cypress/integration/edit_record_1_field.spec.js @@ -46,8 +46,8 @@ describe('As an Admin, I want to reset an image field', () => { cy.get('a[id="media-tab"]').click(); cy.get("label[for=field-image]").should('contain', 'Image'); - cy.get('input[name="fields[image][filename]"]').should('have.value', 'stock/image_40862.jpg'); - cy.get('input[name="fields[image][alt]"]').should('have.value', 'Voluptate nemo quam natus harum numquam.'); + cy.get('input[name="fields[image][filename]"]').should('have.value', 'foal.jpg'); + cy.get('input[name="fields[image][alt]"]').should('have.value', 'Ex veniam repellat ipsam autem delectus.'); cy.get('button[class="btn btn-sm btn-hidden-danger"]').should('contain', 'Remove').eq(0).click(); cy.get('input[name="fields[image][filename]"]').should('have.value', ''); diff --git a/tests/cypress/support/index.js b/tests/cypress/support/index.js index 02fe3beb7a..cfcd5aebc8 100644 --- a/tests/cypress/support/index.js +++ b/tests/cypress/support/index.js @@ -31,8 +31,6 @@ Cypress.Commands.add('login', (username = 'admin', password = 'admin%1') => { cy.url().should('include', '/bolt/login'); - cy.get('input[name="login[username]"]').type('{selectall}{backspace}'); - cy.get('input[name="login[username]"]').type(username); cy.get('input[name="login[password]"]').type(password + '{enter}');