saleor-dashboard/cypress/apiRequests/Product.js

203 lines
3.9 KiB
JavaScript
Raw Normal View History

2021-02-26 15:39:42 +00:00
import { getValueWithDefault } from "./utils/Utils";
2021-02-23 12:09:58 +00:00
export function getFirstProducts(first, search) {
const filter = search
? `, filter:{
2021-02-16 14:19:46 +00:00
search:"${search}"
}`
: "";
const query = `query{
products(first:${first}${filter}){
edges{
node{
id
name
variants{
id
}
}
}
}`;
return cy
.sendRequestWithQuery(query)
.then(resp => resp.body.data.products.edges);
}
2021-02-04 11:15:27 +00:00
export function updateChannelInProduct({
productId,
channelId,
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true
}) {
const mutation = `mutation{
productChannelListingUpdate(id:"${productId}",
input:{
addChannels:{
channelId:"${channelId}"
isPublished:${isPublished}
isAvailableForPurchase:${isAvailableForPurchase}
visibleInListings:${visibleInListings}
}
}){
product{
id
name
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
2021-02-04 11:15:27 +00:00
export function updateChannelPriceInVariant(variantId, channelId) {
const mutation = `mutation{
productVariantChannelListingUpdate(id: "${variantId}", input: {
channelId: "${channelId}"
price: 10
costPrice: 10
}){
productChannelListingErrors{
message
}
2021-02-18 15:28:29 +00:00
}
} `;
return cy.sendRequestWithQuery(mutation);
}
export function createProduct(attributeId, name, productType, category) {
const mutation = `mutation{
productCreate(input:{
attributes:[{
id:"${attributeId}"
}]
name:"${name}"
productType:"${productType}"
category:"${category}"
}){
product{
id
name
}
productErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
2021-02-04 11:15:27 +00:00
export function createVariant({
productId,
sku,
warehouseId,
quantity,
channelId,
price = 1,
costPrice = 1
}) {
const channelListings = getValueWithDefault(
2021-02-04 11:15:27 +00:00
channelId,
`channelListings:{
2021-02-18 19:32:35 +00:00
channelId:"${channelId}"
price:"${price}"
costPrice:"${costPrice}"
}`
);
2021-02-23 12:09:58 +00:00
const stocks = getValueWithDefault(
warehouseId,
`stocks:{
2021-02-18 19:32:35 +00:00
warehouse:"${warehouseId}"
quantity:${quantity}
}`
);
2021-02-18 19:32:35 +00:00
const mutation = `mutation{
productVariantBulkCreate(product: "${productId}", variants: {
attributes: []
sku: "${sku}"
${channelListings}
${stocks}
}) {
productVariants{
id
name
}
bulkProductErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
2021-02-04 11:15:27 +00:00
export function createTypeProduct(
name,
attributeId,
hasVariants = true,
slug = name
) {
const mutation = `mutation{
productTypeCreate(input: {
name: "${name}"
slug: "${slug}"
isShippingRequired: true
productAttributes: "${attributeId}"
variantAttributes: "${attributeId}"
hasVariants: ${hasVariants}
}){
productErrors{
field
message
}
productType{
id
}
2021-02-18 15:28:29 +00:00
}
} `;
return cy.sendRequestWithQuery(mutation);
}
2021-02-04 11:15:27 +00:00
export function deleteProduct(productId) {
const mutation = `mutation{
productDelete(id: "${productId}"){
productErrors{
field
message
}
2021-02-18 15:28:29 +00:00
}
} `;
return cy.sendRequestWithQuery(mutation);
}
2021-02-04 11:15:27 +00:00
export function getProductTypes(first, search) {
const query = `query{
productTypes(first:${first}, filter:{
search:"${search}"
}){
edges{
node{
id
name
2021-02-04 11:15:27 +00:00
}
}
}
}`;
return cy
.sendRequestWithQuery(query)
.then(resp => resp.body.data.productTypes.edges);
}
2021-02-04 11:15:27 +00:00
export function deleteProductType(productTypeId) {
const mutation = `mutation{
productTypeDelete(id:"${productTypeId}"){
productErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
2021-02-04 11:15:27 +00:00
}