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