feat(tests): add api/resources
This commit is contained in:
parent
596f80a7f9
commit
d823417d2f
2 changed files with 104 additions and 0 deletions
38
cypress/integration/api.js
Normal file
38
cypress/integration/api.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
context('API Resources', () => {
|
||||
before(() => {
|
||||
cy.visit('/login');
|
||||
cy.login();
|
||||
cy.visit('/desk');
|
||||
});
|
||||
|
||||
it('Creates two Comments', () => {
|
||||
cy.create_doc('Comment', {comment_type: 'Comment', content: "hello"});
|
||||
cy.create_doc('Comment', {comment_type: 'Comment', content: "world"});
|
||||
});
|
||||
|
||||
it('Lists the Comments', () => {
|
||||
cy.get_list('Comment')
|
||||
.its('data')
|
||||
.then(data => expect(data.length).to.be.at.least(2));
|
||||
|
||||
cy.get_list('Comment', ['name', 'content'], [['content', '=', 'hello']])
|
||||
.then(body => {
|
||||
expect(body).to.have.property('data');
|
||||
expect(body.data).to.have.lengthOf(1);
|
||||
expect(body.data[0]).to.have.property('content');
|
||||
expect(body.data[0]).to.have.property('name');
|
||||
});
|
||||
});
|
||||
|
||||
it('Gets each Comment', () => {
|
||||
cy.get_list('Comment').then(body => body.data.forEach(comment => {
|
||||
cy.get_doc('Comment', comment.name);
|
||||
}));
|
||||
});
|
||||
|
||||
it('Removes the Comments', () => {
|
||||
cy.get_list('Comment').then(body => body.data.forEach(comment => {
|
||||
cy.remove_doc('Comment', comment.name);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
@ -59,6 +59,72 @@ Cypress.Commands.add('call', (method, args) => {
|
|||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('get_list', (doctype, fields=[], filters=[]) => {
|
||||
return cy.window().its('frappe.csrf_token').then(csrf_token => {
|
||||
return cy.request({
|
||||
method: 'GET',
|
||||
url: `/api/resource/${doctype}?fields=${JSON.stringify(fields)}&filters=${JSON.stringify(filters)}`,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-Frappe-CSRF-Token': csrf_token
|
||||
}
|
||||
}).then(res => {
|
||||
expect(res.status).eq(200);
|
||||
return res.body;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('get_doc', (doctype, name) => {
|
||||
return cy.window().its('frappe.csrf_token').then(csrf_token => {
|
||||
return cy.request({
|
||||
method: 'GET',
|
||||
url: `/api/resource/${doctype}/${name}`,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-Frappe-CSRF-Token': csrf_token
|
||||
}
|
||||
}).then(res => {
|
||||
expect(res.status).eq(200);
|
||||
return res.body;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('create_doc', (doctype, args) => {
|
||||
return cy.window().its('frappe.csrf_token').then(csrf_token => {
|
||||
return cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/resource/${doctype}`,
|
||||
body: args,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Frappe-CSRF-Token': csrf_token
|
||||
}
|
||||
}).then(res => {
|
||||
expect(res.status).eq(200);
|
||||
return res.body;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('remove_doc', (doctype, name) => {
|
||||
return cy.window().its('frappe.csrf_token').then(csrf_token => {
|
||||
return cy.request({
|
||||
method: 'DELETE',
|
||||
url: `/api/resource/${doctype}/${name}`,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-Frappe-CSRF-Token': csrf_token
|
||||
}
|
||||
}).then(res => {
|
||||
expect(res.status).eq(202);
|
||||
return res.body;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('create_records', (doc) => {
|
||||
return cy.call('frappe.tests.ui_test_helpers.create_if_not_exists', { doc })
|
||||
.then(r => r.message);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue