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..aa88f93 --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/createNewPost.test.js @@ -0,0 +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(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); + }); + }); + \ 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..eb5c54d --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/getPostById.test.js @@ -0,0 +1,12 @@ +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.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..b54f52c --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/getPostsList.test.js @@ -0,0 +1,12 @@ +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) + }); + }); + + \ 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..0af8412 --- /dev/null +++ b/cypress/e2e/homework16/api_separate_tests/updatePostById.test.js @@ -0,0 +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(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', 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 new file mode 100644 index 0000000..40b25db --- /dev/null +++ b/cypress/e2e/homework16/task1.test.js @@ -0,0 +1,73 @@ +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.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) + }) + + 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(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(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', 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', ()=>{ + 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', {}); + }) + +})