saleor-dashboard/cypress/apiRequests/Attribute.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

export function createAttribute(name, attributeValues = ["value"]) {
const values = attributeValues.map(element => `{name:"${element}"}`);
const mutation = `mutation{
2021-02-04 11:15:27 +00:00
attributeCreate(input:{
name:"${name}"
valueRequired:false
type:PRODUCT_TYPE
values: [${values}]
2021-02-04 11:15:27 +00:00
}){
attribute{
id
2021-02-25 09:51:52 +00:00
name
values{name}
2021-02-04 11:15:27 +00:00
}
attributeErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
2021-02-04 11:15:27 +00:00
export function getAttributes(first, search) {
const mutation = `query{
attributes(first:${first}, filter:{
search:"${search}"
}){
edges{
node{
id
name
2021-02-04 11:15:27 +00:00
}
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.then(resp => resp.body.data.attributes.edges);
}
2021-02-04 11:15:27 +00:00
export function deleteAttribute(attributeId) {
const mutation = `mutation{
attributeDelete(id:"${attributeId}"){
attributeErrors{
field
message
2021-02-04 11:15:27 +00:00
}
}
}`;
return cy.sendRequestWithQuery(mutation);
2021-02-04 11:15:27 +00:00
}