Kaynağa Gözat

Merge pull request #8555 from alyf-de/test_api

feat(tests): test api/resources via cypress
version-14
mergify[bot] 5 yıl önce
committed by GitHub
ebeveyn
işleme
11dfa09ffd
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: 4AEE18F83AFDEB23
2 değiştirilmiş dosya ile 104 ekleme ve 0 silme
  1. +38
    -0
      cypress/integration/api.js
  2. +66
    -0
      cypress/support/commands.js

+ 38
- 0
cypress/integration/api.js Dosyayı Görüntüle

@@ -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);
}));
});
});

+ 66
- 0
cypress/support/commands.js Dosyayı Görüntüle

@@ -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);


Yükleniyor…
İptal
Kaydet