From 93aa89fb4fe16bec975f7b0229faa89dba5b8111 Mon Sep 17 00:00:00 2001 From: litserkovna <39171450+litserkovna@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:29:43 +0100 Subject: [PATCH 1/2] Homework 16 --- .../api_separate_tests/createNewPost.test.js | 21 ++++++ .../api_separate_tests/deletePostById.test.js | 11 +++ .../api_separate_tests/getPostById.test.js | 13 ++++ .../api_separate_tests/getPostsList.test.js | 14 ++++ .../api_separate_tests/updatePostById.test.js | 23 +++++++ cypress/e2e/homework16/task1.test.js | 68 +++++++++++++++++++ 6 files changed, 150 insertions(+) create mode 100644 cypress/e2e/homework16/api_separate_tests/createNewPost.test.js create mode 100644 cypress/e2e/homework16/api_separate_tests/deletePostById.test.js create mode 100644 cypress/e2e/homework16/api_separate_tests/getPostById.test.js create mode 100644 cypress/e2e/homework16/api_separate_tests/getPostsList.test.js create mode 100644 cypress/e2e/homework16/api_separate_tests/updatePostById.test.js create mode 100644 cypress/e2e/homework16/task1.test.js diff --git a/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js b/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js new file mode 100644 index 0000000..2a15663 --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js @@ -0,0 +1,21 @@ +describe('Create New Item API Test', () => { + it('should be creating a new item', () => { + cy.api({ + url: `${Cypress.env('API_URL')}/posts`, + method: 'POST', + body: JSON.stringify({ + title: 'My new title', + body: 'New Body', + userId: 3 + }), + headers: { + 'Content-type': 'application/json; charset=UTF-8' + } + }).as('addPost'); + + cy.get('@addPost').its('body.title').should('equals', 'My new title'); + cy.get('@addPost').its('body.body').should('equals', 'New Body'); + cy.get('@addPost').its('body.userId').should('be.a','number').should('eq', 3); + }); + }); + \ No newline at end of file diff --git a/cypress/e2e/homework16/api_separate_tests/deletePostById.test.js b/cypress/e2e/homework16/api_separate_tests/deletePostById.test.js new file mode 100644 index 0000000..739e778 --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/deletePostById.test.js @@ -0,0 +1,11 @@ +describe('Remove Item API Test', () => { + it('should be removing an item', () => { + cy.api({ + url: `${Cypress.env('API_URL')}/posts/1`, + method: 'DELETE' + }).as('removePost'); + + cy.get('@removePost').its('status').should('eq', 200); + cy.get('@removePost').its('body').should('deep.equal', {}); + }); + }); \ No newline at end of file diff --git a/cypress/e2e/homework16/api_separate_tests/getPostById.test.js b/cypress/e2e/homework16/api_separate_tests/getPostById.test.js new file mode 100644 index 0000000..26d5b7f --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/getPostById.test.js @@ -0,0 +1,13 @@ +describe('Fetch Single Item API Test', () => { + it('should be fetching a single item', async () => { + const response = await cy.api({ + url: `${Cypress.env('API_URL')}/posts/1` + }); + + expect(response.status).to.equal(200); + expect(response.body.userId).to.equal(1); + expect(typeof response.body.id).to.equal('number'); + expect(typeof response.body.body).to.equal('string'); + }); + }); + \ No newline at end of file diff --git a/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js b/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js new file mode 100644 index 0000000..97cf214 --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js @@ -0,0 +1,14 @@ +describe('Fetch All Items API Test', () => { + it('should be fetching all items', () => { + cy.api({ + url: `${Cypress.env('API_URL')}/posts` + }).as('getFullList'); + + cy.get('@getFullList').its('status').should('eq', 200) + cy.get('@getFullList').its('body').should('have.length.above', 10) + cy.get('@getFullList').its('body').should('have.length', 100); + + }); + }); + + \ No newline at end of file diff --git a/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js b/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js new file mode 100644 index 0000000..c784a41 --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js @@ -0,0 +1,23 @@ +describe('Update Item API Test', () => { + it('should be updating an item', () => { + cy.api({ + url: `${Cypress.env('API_URL')}/posts/1`, + method: 'PUT', + body: JSON.stringify({ + id : 1, + title: 'Updated Title', + body: 'Updated Body', + userId: 4 + }), + headers: { + 'Content-type': 'application/json; charset=UTF-8' + } + }).as('updatePost'); + + cy.get('@updatePost').its('status').should('eq', 200); + cy.get('@updatePost').its('body.body').should('equals', 'Updated Body'); + cy.get('@updatePost').its('body.title').should('equals', 'Updated Title') + cy.get('@updatePost').its('body.userId').should('be.a','number').should('eq', 4); + }); + }); + \ No newline at end of file diff --git a/cypress/e2e/homework16/task1.test.js b/cypress/e2e/homework16/task1.test.js new file mode 100644 index 0000000..f455cc2 --- /dev/null +++ b/cypress/e2e/homework16/task1.test.js @@ -0,0 +1,68 @@ +describe('Custom API Tests', () => { + + it('should be fetching a single item', async () => { + const response = await cy.api({ + url: `${Cypress.env('API_URL')}/posts/1`}); + + expect(response.status).to.equal(200); + expect(response.body.userId).to.equal(1); + expect(typeof response.body.id).to.equal('number'); + expect(typeof response.body.body).to.equal('string'); + }); + + + it('should be fetching all items', () =>{ + cy.api({ + url: `${Cypress.env('API_URL')}/posts`}).as('getFullList') + + cy.get('@getFullList').its('status').should('eq', 200) + cy.get('@getFullList').its('body').should('have.length.above', 10) + cy.get('@getFullList').its('body').should('have.length', 100); + }) + + it('should be creating a new item', ()=>{ + cy.api({ + url: `${Cypress.env('API_URL')}/posts`, + method: 'POST', + body: JSON.stringify({ + title: 'My new title', + body: 'New Body', + userId: 3 + }), + headers: { + 'Content-type': 'application/json; charset=UTF-8' + }}).as('addPost') + cy.get('@addPost').its('body.title').should('equals', 'My new title') + cy.get('@addPost').its('body.body').should('equals', 'New Body') + cy.get("@addPost").its('body.userId').should('be.a','number').should('eq', 3) + }) + + it('should be updating an item', ()=>{ + cy.api({ + url: `${Cypress.env('API_URL')}/posts/1`, + method: 'PUT', + body: JSON.stringify({ + id : 1, + title: 'Updated Title', + body: 'Updated Body', + userId: 4 + }), + headers: { + 'Content-type': 'application/json; charset=UTF-8' + }}).as('updatePost') + cy.get('@updatePost').its('status').should('eq', 200) + cy.get('@updatePost').its('body.body').should('equals', 'Updated Body') + cy.get('@updatePost').its('body.title').should('equals', 'Updated Title') + cy.get('@updatePost').its('body.userId').should('be.a','number').should('eq', 4) + }) + + it('should be removing an item', ()=>{ + cy.api({ + url: `${Cypress.env('API_URL')}/posts/1`, + method: 'DELETE' + }).as('removePost') + cy.get('@removePost').its('status').should('eq', 200) + cy.get('@removePost').its('body').should('deep.equal', {}); + }) + +}) From fcba83576fd148b44a0a46669485de29d9632e67 Mon Sep 17 00:00:00 2001 From: litserkovna <39171450+litserkovna@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:28:27 +0100 Subject: [PATCH 2/2] Resolving comments --- .../api_separate_tests/createNewPost.test.js | 19 ++++--- .../api_separate_tests/getPostById.test.js | 1 - .../api_separate_tests/getPostsList.test.js | 4 +- .../api_separate_tests/updatePostById.test.js | 21 ++++--- cypress/e2e/homework16/task1.test.js | 55 ++++++++++--------- 5 files changed, 54 insertions(+), 46 deletions(-) diff --git a/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js b/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js index 2a15663..aa88f93 100644 --- a/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js +++ b/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js @@ -1,21 +1,24 @@ describe('Create New Item API Test', () => { it('should be creating a new item', () => { + + const requestBody = { + title: 'My new title', + body: 'New Body', + userId: 3 + }; + cy.api({ url: `${Cypress.env('API_URL')}/posts`, method: 'POST', - body: JSON.stringify({ - title: 'My new title', - body: 'New Body', - userId: 3 - }), + body: JSON.stringify(requestBody), headers: { 'Content-type': 'application/json; charset=UTF-8' } }).as('addPost'); - cy.get('@addPost').its('body.title').should('equals', 'My new title'); - cy.get('@addPost').its('body.body').should('equals', 'New Body'); - cy.get('@addPost').its('body.userId').should('be.a','number').should('eq', 3); + cy.get('@addPost').its('body.title').should('equals', requestBody.title); + cy.get('@addPost').its('body.body').should('equals', requestBody.body); + cy.get('@addPost').its('body.userId').should('equals', requestBody.userId); }); }); \ No newline at end of file diff --git a/cypress/e2e/homework16/api_separate_tests/getPostById.test.js b/cypress/e2e/homework16/api_separate_tests/getPostById.test.js index 26d5b7f..eb5c54d 100644 --- a/cypress/e2e/homework16/api_separate_tests/getPostById.test.js +++ b/cypress/e2e/homework16/api_separate_tests/getPostById.test.js @@ -6,7 +6,6 @@ describe('Fetch Single Item API Test', () => { expect(response.status).to.equal(200); expect(response.body.userId).to.equal(1); - expect(typeof response.body.id).to.equal('number'); expect(typeof response.body.body).to.equal('string'); }); }); diff --git a/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js b/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js index 97cf214..b54f52c 100644 --- a/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js +++ b/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js @@ -5,9 +5,7 @@ describe('Fetch All Items API Test', () => { }).as('getFullList'); cy.get('@getFullList').its('status').should('eq', 200) - cy.get('@getFullList').its('body').should('have.length.above', 10) - cy.get('@getFullList').its('body').should('have.length', 100); - + cy.get('@getFullList').its('body').should('have.length.above', 10) }); }); diff --git a/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js b/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js index c784a41..0af8412 100644 --- a/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js +++ b/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js @@ -1,23 +1,26 @@ describe('Update Item API Test', () => { it('should be updating an item', () => { + + const requestBody = { + id: 1, + title: 'Updated Title', + body: 'Updated Body', + userId: 4 + }; + cy.api({ url: `${Cypress.env('API_URL')}/posts/1`, method: 'PUT', - body: JSON.stringify({ - id : 1, - title: 'Updated Title', - body: 'Updated Body', - userId: 4 - }), + body: JSON.stringify(requestBody), headers: { 'Content-type': 'application/json; charset=UTF-8' } }).as('updatePost'); cy.get('@updatePost').its('status').should('eq', 200); - cy.get('@updatePost').its('body.body').should('equals', 'Updated Body'); - cy.get('@updatePost').its('body.title').should('equals', 'Updated Title') - cy.get('@updatePost').its('body.userId').should('be.a','number').should('eq', 4); + cy.get('@updatePost').its('body.body').should('equals', requestBody.body); + cy.get('@updatePost').its('body.title').should('equals', requestBody.title) + cy.get('@updatePost').its('body.userId').should('eq', requestBody.userId); }); }); \ No newline at end of file diff --git a/cypress/e2e/homework16/task1.test.js b/cypress/e2e/homework16/task1.test.js index f455cc2..40b25db 100644 --- a/cypress/e2e/homework16/task1.test.js +++ b/cypress/e2e/homework16/task1.test.js @@ -6,7 +6,6 @@ describe('Custom API Tests', () => { expect(response.status).to.equal(200); expect(response.body.userId).to.equal(1); - expect(typeof response.body.id).to.equal('number'); expect(typeof response.body.body).to.equal('string'); }); @@ -17,43 +16,49 @@ describe('Custom API Tests', () => { cy.get('@getFullList').its('status').should('eq', 200) cy.get('@getFullList').its('body').should('have.length.above', 10) - cy.get('@getFullList').its('body').should('have.length', 100); }) it('should be creating a new item', ()=>{ + const requestBody = { + title: 'My new title', + body: 'New Body', + userId: 3 + }; + cy.api({ - url: `${Cypress.env('API_URL')}/posts`, - method: 'POST', - body: JSON.stringify({ - title: 'My new title', - body: 'New Body', - userId: 3 - }), - headers: { - 'Content-type': 'application/json; charset=UTF-8' - }}).as('addPost') - cy.get('@addPost').its('body.title').should('equals', 'My new title') - cy.get('@addPost').its('body.body').should('equals', 'New Body') - cy.get("@addPost").its('body.userId').should('be.a','number').should('eq', 3) - }) + url: `${Cypress.env('API_URL')}/posts`, + method: 'POST', + body: JSON.stringify(requestBody), + headers: { + 'Content-type': 'application/json; charset=UTF-8' + } + }).as('addPost'); + + cy.get('@addPost').its('body.title').should('equals', requestBody.title); + cy.get('@addPost').its('body.body').should('equals', requestBody.body); + cy.get('@addPost').its('body.userId').should('equals', requestBody.userId); + }); it('should be updating an item', ()=>{ + + const requestBody = { + id: 1, + title: 'Updated Title', + body: 'Updated Body', + userId: 4 + }; + cy.api({ url: `${Cypress.env('API_URL')}/posts/1`, method: 'PUT', - body: JSON.stringify({ - id : 1, - title: 'Updated Title', - body: 'Updated Body', - userId: 4 - }), + body: JSON.stringify(requestBody), headers: { 'Content-type': 'application/json; charset=UTF-8' }}).as('updatePost') cy.get('@updatePost').its('status').should('eq', 200) - cy.get('@updatePost').its('body.body').should('equals', 'Updated Body') - cy.get('@updatePost').its('body.title').should('equals', 'Updated Title') - cy.get('@updatePost').its('body.userId').should('be.a','number').should('eq', 4) + cy.get('@updatePost').its('body.body').should('equals', requestBody.body) + cy.get('@updatePost').its('body.title').should('equals', requestBody.title) + cy.get('@updatePost').its('body.userId').should('eq', requestBody.userId) }) it('should be removing an item', ()=>{