Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cypress/e2e/homework16/api_separate_tests/createNewPost.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

11 changes: 11 additions & 0 deletions cypress/e2e/homework16/api_separate_tests/deletePostById.test.js
Original file line number Diff line number Diff line change
@@ -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', {});
});
});
12 changes: 12 additions & 0 deletions cypress/e2e/homework16/api_separate_tests/getPostById.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

12 changes: 12 additions & 0 deletions cypress/e2e/homework16/api_separate_tests/getPostsList.test.js
Original file line number Diff line number Diff line change
@@ -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)
});
});


26 changes: 26 additions & 0 deletions cypress/e2e/homework16/api_separate_tests/updatePostById.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

73 changes: 73 additions & 0 deletions cypress/e2e/homework16/task1.test.js
Original file line number Diff line number Diff line change
@@ -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', {});
})

})