saleor-dashboard/cypress/support/api/requests/Attribute.js

106 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-07-15 11:22:04 +00:00
export function createAttribute({
name,
attributeValues = ["value"],
type = "PRODUCT_TYPE",
inputType = "DROPDOWN",
filterableInDashboard = false
2021-07-15 11:22:04 +00:00
}) {
const values = attributeValues.map(element => `{name:"${element}"}`);
const mutation = `mutation{
attributeCreate(input:{
name:"${name}"
valueRequired:false
2021-07-15 11:22:04 +00:00
type:${type}
values: [${values}]
inputType: ${inputType}
filterableInDashboard: ${filterableInDashboard}
}){
attribute{
id
name
2021-08-18 11:58:07 +00:00
slug
choices(first: 100){
edges{
node{
name
}
}
}
}
attributeErrors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.attributeCreate.attribute");
}
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
}
}
}
}`;
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
}
}
}`;
return cy.sendRequestWithQuery(mutation);
2021-02-04 11:15:27 +00:00
}
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");
}
2021-08-18 11:58:07 +00:00
export function updateAttribute({ attributeId, filterableInDashboard }) {
2021-08-18 11:58:07 +00:00
const mutation = `mutation{
attributeUpdate(id:"${attributeId}" input:{
filterableInDashboard: ${filterableInDashboard}
2021-08-18 11:58:07 +00:00
}){
attribute{
id
filterableInDashboard
}
2021-08-18 11:58:07 +00:00
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}