saleor-dashboard/cypress/support/api/requests/Product.js
Karolina Rakoczy f85786f203
Run critical tests after test env deployment (#1902)
* run critical tests after test env deployment

* add cache

* add all branches

* change workflow name

* add run on pull request for testing

* change type

* add run on deployment

* run on copleted

* test critical

* add quote

* change baseUrl

* fix base url

* fix base url

* upload reports

* run in parallel

* save build folder

* remove build from gitignore

* remove build

* update nide version

* last try with parallel

* save build

* save build

* Run critical

* change cypress API url

* run critical in parallel

* check which workflow has lower duration time

* save all reports with container in name

* add reports on failure

* remove reporters

* fix jobs

* merge

* add group name

* run critical

* Refactor critical tests (#1906)

* refactored tag added to purchaseWithProductsTypes, navigation, stocksInCheckout

* homePageAnalitics - refactor

* refactor home page

* refactor creating variants

* refactor adding product without sku to order

* add script to run critical locally

* change tests cases names

* fix names, remove comments, add script to run refactored tests

* remove workflow for parallel

* remove key
2022-03-21 13:17:37 +01:00

359 lines
7.4 KiB
JavaScript

import { stringify } from "../.././formatData/formatJson";
import { returnValueDependsOnShopVersion } from "../../formatData/dataDependingOnVersion";
import {
getDataForDescriptionInVariables,
getValueWithDefault,
getVariantsListIds
} from "./utils/Utils";
export function getFirstProducts(first, search) {
const filter = search
? `, filter:{
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);
}
export function updateProduct(productId, input) {
const mutation = `mutation {
productUpdate(id:"${productId}", input:${stringify(input)} ){
productErrors{
field
message
}
product{
id
}
}
}
`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.productUpdate.product");
}
export function updateChannelInProduct({
productId,
channelId,
variantsIdsToAdd = "[]",
variantsIdsToRemove = "[]",
isPublished = true,
isAvailableForPurchase = true,
visibleInListings = true
}) {
const mutation = `mutation{
productChannelListingUpdate(id:"${productId}",
input:{
updateChannels:{
channelId:"${channelId}"
isPublished:${isPublished}
isAvailableForPurchase:${isAvailableForPurchase}
visibleInListings:${visibleInListings}
addVariants:${variantsIdsToAdd}
removeVariants:${variantsIdsToRemove}
}
}){
product{
id
name
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function updateChannelPriceInVariant(variantId, channelId) {
const mutation = `mutation{
productVariantChannelListingUpdate(id: "${variantId}", input: {
channelId: "${channelId}"
price: 10
costPrice: 10
}){
productChannelListingErrors{
message
}
}
} `;
return cy.sendRequestWithQuery(mutation);
}
export function createProduct({
attributeId,
attributeValue,
name,
productTypeId,
categoryId,
collectionId,
description
}) {
const collection = getValueWithDefault(
collectionId,
`collections:["${collectionId}"]`
);
const category = getValueWithDefault(categoryId, `category:"${categoryId}"`);
const descriptionData = getDataForDescriptionInVariables(description);
const attributeValuesLine = getValueWithDefault(
attributeValue,
`values:["${attributeValue}"]`
);
const attributes = getValueWithDefault(
attributeId,
`attributes:[{
id:"${attributeId}"
${attributeValuesLine}
}]`
);
const mutation = `mutation createProduct${descriptionData.mutationVariables}{
productCreate(input:{
${attributes}
name:"${name}"
slug:"${name}"
seo:{title:"${name}" description:""}
productType:"${productTypeId}"
${category}
${collection}
${descriptionData.descriptionLine}
}){
product{
id
name
}
productErrors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation, "auth", descriptionData.variables, true)
.its("body.data.productCreate.product");
}
export function createVariant({
productId,
sku,
warehouseId,
quantityInWarehouse = 1,
channelId,
attributeId,
price = 1,
costPrice = 1,
trackInventory = true,
weight = 1,
attributeName = "value",
preorder
}) {
const preorderLines = getValueWithDefault(
preorder,
`preorder:${stringify(preorder)}`
);
const skuLines = getValueWithDefault(sku, `sku: "${sku}"`);
const attributeLines = getValueWithDefault(
attributeId,
`attributes: [{
id:"${attributeId}"
values: ["${attributeName}"]
}]`,
"attributes:[]"
);
const channelListings = getValueWithDefault(
channelId,
`channelListings:{
channelId:"${channelId}"
price:"${price}"
costPrice:"${costPrice}"
}`
);
const stocks = getValueWithDefault(
warehouseId,
`stocks:{
warehouse:"${warehouseId}"
quantity:${quantityInWarehouse}
}`
);
const mutation = `mutation{
productVariantBulkCreate(product: "${productId}", variants: {
${preorderLines}
${attributeLines}
weight: ${weight}
${skuLines}
${channelListings}
trackInventory:${trackInventory}
${stocks}
}) {
productVariants{
id
name
}
errors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.productVariantBulkCreate.productVariants");
}
export function deleteProduct(productId) {
const mutation = `mutation{
productDelete(id: "${productId}"){
productErrors{
field
message
}
}
} `;
return cy.sendRequestWithQuery(mutation);
}
export function getVariants(variantsList) {
const variantsIds = getVariantsListIds(variantsList);
const query = `query{
productVariants(first:100 ids:[${variantsIds}]){
edges{
node{
stocks{
warehouse{
id
}
quantity
quantityAllocated
}
}
}
}
}`;
return cy.sendRequestWithQuery(query).its("body.data.productVariants");
}
export function getVariant(id, channelSlug, auth = "auth") {
const preorder = returnValueDependsOnShopVersion(
"3.1",
`preorder{
globalThreshold
globalSoldUnits
endDate
}`
);
const query = `query{
productVariant(id:"${id}" channel:"${channelSlug}"){
id
name
stocks{
warehouse{
id
}
quantityAllocated
}
${preorder}
sku
attributes{
attribute{
inputType
}
values{
name
}
}
pricing{
onSale
discount{
gross{
amount
}
}
price{
gross{
amount
}
}
priceUndiscounted{
gross{
amount
}
}
}
}
}`;
return cy.sendRequestWithQuery(query, auth).its("body.data.productVariant");
}
export function deactivatePreorderOnVariant(variantId) {
const mutation = `mutation{
productVariantPreorderDeactivate(id:"${variantId}"){
errors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.productVariantPreorderDeactivate");
}
export function activatePreorderOnVariant({
variantId,
threshold = 50,
endDate
}) {
const thresholdLine = getValueWithDefault(
threshold,
`globalThreshold:${threshold}`
);
const endDateLine = getValueWithDefault(endDate, `endDate:${endDate}`);
const mutation = `mutation{
productVariantUpdate(id:"${variantId}", input:{
preorder:{
${thresholdLine}
${endDateLine}
}
}){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function updateVariantPrice({ variantId, channelId, price }) {
const mutation = `mutation {
productVariantChannelListingUpdate(id:"${variantId}", input:{
channelId:"${channelId}"
price:${price}
costPrice:${price}
}){
errors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.productVariantChannelListingUpdate");
}