Fix tests for purchase digital product for 3.1 (#1684)

* purchase digital product for 3.1

* purchase digital product for 3.1
This commit is contained in:
Karolina Rakoczy 2021-12-15 13:17:35 +01:00 committed by GitHub
parent ee9e55db0f
commit 6f8feebf7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 117 additions and 18 deletions

View file

@ -100,7 +100,7 @@ filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
address,
auth: "token",
channelSlug: defaultChannel.slug,
shippingMethodId: shippingMethod.id,
shippingMethodName: shippingMethod.name,
variantsList: variants
};
});

View file

@ -13,7 +13,10 @@ import {
createCheckout
} from "../../support/api/requests/Checkout";
import { getOrder } from "../../support/api/requests/Order";
import { createTypeProduct } from "../../support/api/requests/ProductType";
import {
createDigitalContent,
createTypeProduct
} from "../../support/api/requests/ProductType";
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
import {
addPayment,
@ -21,6 +24,7 @@ import {
createWaitingForCaptureOrder
} from "../../support/api/utils/ordersUtils";
import {
addDigitalContentAndUpdateProductType,
createProductInChannel,
deleteProductsStartsWith
} from "../../support/api/utils/products/productsUtils";
@ -94,6 +98,8 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
it("should purchase digital product", () => {
const digitalName = `${startsWith}${faker.datatype.number()}`;
let variants;
createTypeProduct({
name: digitalName,
attributeId: attribute.id,
@ -105,11 +111,19 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
createProductInChannel(createProductData);
})
.then(({ variantsList }) => {
variants = variantsList;
addDigitalContentAndUpdateProductType(
variants[0].id,
createProductData.productTypeId,
defaultChannel.id
);
})
.then(() => {
createAndCompleteCheckoutWithoutShipping({
channelSlug: defaultChannel.slug,
email,
billingAddress: address,
variantsList,
variantsList: variants,
auth: "token"
});
})
@ -142,7 +156,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
channelSlug: defaultChannel.slug,
email,
variantsList,
shippingMethodId: shippingMethod.id,
shippingMethodName: shippingMethod.name,
address
});
})
@ -175,6 +189,9 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
})
.then(({ variantsList }) => {
digitalProductVariantsList = variantsList;
createDigitalContent(variantsList[0].id);
})
.then(() => {
createCheckout({
channelSlug: defaultChannel.slug,
email,

View file

@ -83,7 +83,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
channel: defaultChannel,
name: productName,
warehouseId: warehouse.id,
shippingMethodId: shippingMethod.id,
shippingMethod,
address
}).then(({ order }) => {
expect(order, "order should be created").to.be.ok;
@ -137,7 +137,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
warehouseId: warehouse.id,
quantityInWarehouse: 0,
trackInventory: false,
shippingMethodId: shippingMethod.id,
shippingMethod,
address
}).then(({ order }) => {
expect(order, "order should be created").to.be.ok;
@ -156,7 +156,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
warehouseId: warehouse.id,
quantityInWarehouse: 10,
trackInventory: true,
shippingMethodId: shippingMethod.id,
shippingMethod,
address
})
.then(({ variantsList }) => {

View file

@ -213,7 +213,7 @@ filterTests({ definedTags: ["all"] }, () => {
channelSlug: defaultChannel.slug,
variantsList: variants,
address,
shippingMethodId: shippingMethod.id,
shippingMethodName: shippingMethod.name,
voucherCode,
auth: "token"
});

View file

@ -153,7 +153,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
channelSlug: defaultChannel.slug,
email: randomEmail,
variantsList: createdVariants,
shippingMethodId: shippingMethod.id,
shippingMethodName: shippingMethod.name,
address: addresses.plAddress
});

View file

@ -51,6 +51,7 @@ export function createCheckout({
token
availableShippingMethods{
name
id
}
lines{
variant{
@ -249,3 +250,7 @@ export function addProductsToCheckout(
}`;
return cy.sendRequestWithQuery(mutation).its("body.data.checkoutLinesUpdate");
}
export function getCheckout(checkoutId) {
const mutation = ``;
}

View file

@ -313,7 +313,21 @@ export function activatePreorderOnVariant(variantId, threshold, endDate) {
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

View file

@ -22,6 +22,7 @@ export function createTypeProduct({
productTypeCreate(input: {
name: "${name}"
slug: "${slug}"
isDigital: ${!shippable}
${productAttributesLine}
hasVariants: ${hasVariants}
${variantAttributesLine}
@ -109,3 +110,36 @@ export function getProductType(productTypeId) {
}`;
return cy.sendRequestWithQuery(query).its("body.data.productType");
}
export function createDigitalContent(variantId) {
const mutation = `mutation{
digitalContentCreate(input:{
useDefaultSettings:true,
automaticFulfillment: true,
contentFile:""
}, variantId:"${variantId}"){
content{
id
}
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function setProductTypeAsDigital(productTypeId, isDigital = true) {
const mutation = `mutation updateProductType{
productTypeUpdate(id:"${productTypeId}", input:{
isDigital:${isDigital}
}){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}

View file

@ -26,6 +26,7 @@ export function createShippingRate({
}){
shippingMethod{
id
name
}
errors{
field

View file

@ -1,6 +1,6 @@
import { getValueWithDefault } from "../utils/Utils";
export function getProductDetails(productId, channelId, auth = "token") {
export function getProductDetails(productId, channelSlug, auth = "token") {
const privateMetadataLine = getValueWithDefault(
auth === "auth",
`privateMetadata{key value}`
@ -36,6 +36,7 @@ export function getProductDetails(productId, channelId, auth = "token") {
productType{
id
name
isDigital
}
}
@ -62,7 +63,7 @@ export function getProductDetails(productId, channelId, auth = "token") {
}
query ProductDetails{
product(id: "${productId}", channel: "${channelId}") {
product(id: "${productId}", channel: "${channelSlug}") {
...BasicProductFields
variants {
...ProductVariantFields

View file

@ -10,7 +10,7 @@ export function createWaitingForCaptureOrder({
channelSlug,
email,
variantsList,
shippingMethodId,
shippingMethodName,
address
}) {
let checkout;
@ -27,6 +27,10 @@ export function createWaitingForCaptureOrder({
})
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
const shippingMethodId = getShippingMethodIdFromCheckout(
checkout,
shippingMethodName
);
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
})
.then(() => addPayment(checkout.id))
@ -34,12 +38,18 @@ export function createWaitingForCaptureOrder({
.then(({ order }) => ({ checkout, order }));
}
export function getShippingMethodIdFromCheckout(checkout, shippingMethodName) {
return checkout.availableShippingMethods.find(
element => element.name === shippingMethodName
).id;
}
export function createCheckoutWithVoucher({
channelSlug,
email = "email@example.com",
variantsList,
address,
shippingMethodId,
shippingMethodName,
voucherCode,
auth
}) {
@ -55,6 +65,10 @@ export function createCheckoutWithVoucher({
})
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
const shippingMethodId = getShippingMethodIdFromCheckout(
checkout,
shippingMethodName
);
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
})
.then(() => {
@ -71,7 +85,7 @@ export function purchaseProductWithPromoCode({
email = "email@example.com",
variantsList,
address,
shippingMethodId,
shippingMethod,
voucherCode,
auth
}) {
@ -82,7 +96,7 @@ export function purchaseProductWithPromoCode({
email,
variantsList,
address,
shippingMethodId,
shippingMethodName: shippingMethod.name,
voucherCode,
auth
})
@ -212,7 +226,7 @@ export function createOrderWithNewProduct({
warehouseId,
quantityInWarehouse = 1,
trackInventory = true,
shippingMethodId,
shippingMethod,
address
}) {
let variantsList;
@ -232,7 +246,7 @@ export function createOrderWithNewProduct({
channelSlug: channel.slug,
email: "email@example.com",
variantsList,
shippingMethodId,
shippingMethodName: shippingMethod.name,
address
});
})

View file

@ -4,10 +4,12 @@ import * as categoryRequest from "../../requests/Category";
import { createCollection } from "../../requests/Collections";
import * as productRequest from "../../requests/Product";
import {
createDigitalContent,
createTypeProduct,
deleteProductType,
getProductTypes,
productAttributeAssignmentUpdate
productAttributeAssignmentUpdate,
setProductTypeAsDigital
} from "../../requests/ProductType";
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
import { deleteCollectionsStartsWith } from "../catalog/collectionsUtils";
@ -251,3 +253,14 @@ export function createProductInChannelWithoutVariants({
})
.then(() => product);
}
export function addDigitalContentAndUpdateProductType(
variantId,
productTypeId,
channelId,
price = 1
) {
createDigitalContent(variantId);
setProductTypeAsDigital(productTypeId);
productRequest.updateVariantPrice({ variantId, channelId, price });
}