saleor-dashboard/cypress/apiRequests/Attribute.js
Karolina Rakoczy 4faafd2489
Saleor 3626 tests for attributes (#1198)
* tests for attributes

* add tests for content attribute
2021-07-09 11:43:45 +02:00

78 lines
1.5 KiB
JavaScript

export function createAttribute(name, attributeValues = ["value"]) {
const values = attributeValues.map(element => `{name:"${element}"}`);
const mutation = `mutation{
attributeCreate(input:{
name:"${name}"
valueRequired:false
type:PRODUCT_TYPE
values: [${values}]
}){
attribute{
id
name
choices(first: 100){
edges{
node{
name
}
}
}
}
attributeErrors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.attributeCreate.attribute");
}
export function getAttributes(first, search) {
const mutation = `query{
attributes(first:${first}, filter:{
search:"${search}"
}){
edges{
node{
id
name
}
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.then(resp => resp.body.data.attributes.edges);
}
export function deleteAttribute(attributeId) {
const mutation = `mutation{
attributeDelete(id:"${attributeId}"){
attributeErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function getAttribute(attributeId) {
const query = `query{
attribute(id:"${attributeId}"){
id
inputType
name
slug
type
entityType
valueRequired
visibleInStorefront
availableInGrid
unit
}
}`;
return cy.sendRequestWithQuery(query).its("body.data.attribute");
}