saleor-dashboard/cypress/support/api/utils/ordersUtils.js

333 lines
7.8 KiB
JavaScript
Raw Normal View History

import * as checkoutRequest from "../requests/Checkout";
import * as orderRequest from "../requests/Order";
import {
getPaymentMethodStripeId,
2022-08-04 10:59:42 +00:00
sendConfirmationToStripe,
} from "../requests/stripe";
import { createProductInChannel } from "./products/productsUtils";
export function createWaitingForCaptureOrder({
channelSlug,
email,
variantsList,
shippingMethodName,
2022-08-04 10:59:42 +00:00
address,
}) {
let checkout;
const auth = "token";
cy.loginInShop();
return checkoutRequest
.createCheckout({
channelSlug,
email,
variantsList,
address,
billingAddress: address,
2022-08-04 10:59:42 +00:00
auth,
})
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
const shippingMethodId = getShippingMethodIdFromCheckout(
checkout,
2022-08-04 10:59:42 +00:00
shippingMethodName,
);
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
})
.then(() => addPayment(checkout.id))
.then(() => checkoutRequest.completeCheckout(checkout.id))
.then(({ order }) => ({ checkout, order }));
}
export function getShippingMethodIdFromCheckout(checkout, shippingMethodName) {
const availableShippingMethodsLength = checkout.shippingMethods.length;
if (availableShippingMethodsLength === 0) {
return null;
} else {
return checkout.shippingMethods.find(
2022-08-04 10:59:42 +00:00
element => element.name === shippingMethodName,
).id;
}
}
export function updateShippingInCheckout(checkoutToken, shippingMethodName) {
return checkoutRequest.getCheckout(checkoutToken).then(checkout => {
const shippingMethodId = getShippingMethodIdFromCheckout(
checkout,
2022-08-04 10:59:42 +00:00
shippingMethodName,
);
return checkoutRequest.checkoutShippingMethodUpdate(
checkout.id,
2022-08-04 10:59:42 +00:00
shippingMethodId,
);
});
}
export function createCheckoutWithVoucher({
channelSlug,
email = "email@example.com",
variantsList,
productQuantity = 1,
address,
shippingMethodName,
voucherCode,
2022-08-04 10:59:42 +00:00
auth,
}) {
let checkout;
return checkoutRequest
.createCheckout({
channelSlug,
productQuantity,
email,
variantsList,
address,
billingAddress: address,
2022-08-04 10:59:42 +00:00
auth,
})
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
const shippingMethodId = getShippingMethodIdFromCheckout(
checkout,
2022-08-04 10:59:42 +00:00
shippingMethodName,
);
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
})
.then(() => {
checkoutRequest.addVoucher(checkout.id, voucherCode);
})
.then(resp => ({
addPromoCodeResp: resp.body.data.checkoutAddPromoCode,
2022-08-04 10:59:42 +00:00
checkout,
}));
}
export function purchaseProductWithPromoCode({
channelSlug,
email = "email@example.com",
variantsList,
address,
shippingMethodName,
voucherCode,
2022-08-04 10:59:42 +00:00
auth,
}) {
let checkout;
return createCheckoutWithVoucher({
channelSlug,
email,
variantsList,
address,
shippingMethodName,
voucherCode,
2022-08-04 10:59:42 +00:00
auth,
})
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => checkoutRequest.completeCheckout(checkout.id))
.then(({ order }) => ({ checkout, order }));
}
export function createReadyToFulfillOrder({
customerId,
shippingMethod,
channelId,
Feature - channels per plugin (#1093) * Update schema * Update queries, mutations, and types * Add render with dividers util function * Add plugin details channels card component * Update plugin details to use channels * Update stories * Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match" * Update schema * Update types * Update plugins list to show channels and global statuses, add plugin channel status, update status label component * Add render with dividers util function * Comment out some stuff for types to match - temporary * Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more * Change filters logic to be able to display multiple fields in a field section and add it to plugins view * Add scroll option to plugin availability popup on plugin list * Fix plugin list page story * Temporarily comment some stuff out, fix some types * Add filters errors WIP * Fix filters not updating list * Add error handling to plugins list filters and filters in general * Rename some components according to review * Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly * Fix imports * Move render collection with dividers to a component, fix usages * Replace channels with load more and search query to base channels query * Change render with dividers function to take in a component instead of render function * Update tests * Extract messages * Remove unnecessary imports * Fix filters - autocomplete messing items order sometimes & some fields not working * Update plugin update mutation variables - change channelId to channel * fix failing tests * Add test ids * fix failing tests * fix failing tests * Rename misc.tsx to ts * Remove usage of render collection with diviers, change it to CollectionWithDividers component * Remove unnecessary imports * Update messages ids * Update snapshots Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 13:58:09 +00:00
variantsList,
2022-08-04 10:59:42 +00:00
address,
}) {
let order;
return orderRequest
.createDraftOrder({ customerId, channelId, address })
.then(orderResp => {
order = orderResp;
assignVariantsToOrder(order, variantsList);
})
.then(orderResp => {
shippingMethod = getShippingMethodIdFromCheckout(
orderResp.order,
shippingMethod.name,
);
orderRequest.addShippingMethod(order.id, shippingMethod);
})
2022-08-04 10:59:42 +00:00
.then(() => orderRequest.completeOrder(order.id))
.then(() => orderRequest.markOrderAsPaid(order.id));
}
export function createFulfilledOrder({
customerId,
shippingMethod,
channelId,
variantsList,
address,
warehouse,
2022-08-04 10:59:42 +00:00
quantity = 1,
}) {
return createReadyToFulfillOrder({
customerId,
shippingMethod,
channelId,
variantsList,
2022-08-04 10:59:42 +00:00
address,
}).then(({ order }) => {
orderRequest.fulfillOrder({
orderId: order.id,
warehouse,
quantity,
2022-08-04 10:59:42 +00:00
linesId: order.lines,
});
});
}
export function createOrder({
customerId,
shippingMethod,
channelId,
Feature - channels per plugin (#1093) * Update schema * Update queries, mutations, and types * Add render with dividers util function * Add plugin details channels card component * Update plugin details to use channels * Update stories * Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match" * Update schema * Update types * Update plugins list to show channels and global statuses, add plugin channel status, update status label component * Add render with dividers util function * Comment out some stuff for types to match - temporary * Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more * Change filters logic to be able to display multiple fields in a field section and add it to plugins view * Add scroll option to plugin availability popup on plugin list * Fix plugin list page story * Temporarily comment some stuff out, fix some types * Add filters errors WIP * Fix filters not updating list * Add error handling to plugins list filters and filters in general * Rename some components according to review * Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly * Fix imports * Move render collection with dividers to a component, fix usages * Replace channels with load more and search query to base channels query * Change render with dividers function to take in a component instead of render function * Update tests * Extract messages * Remove unnecessary imports * Fix filters - autocomplete messing items order sometimes & some fields not working * Update plugin update mutation variables - change channelId to channel * fix failing tests * Add test ids * fix failing tests * fix failing tests * Rename misc.tsx to ts * Remove usage of render collection with diviers, change it to CollectionWithDividers component * Remove unnecessary imports * Update messages ids * Update snapshots Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 13:58:09 +00:00
variantsList,
2022-08-04 10:59:42 +00:00
address,
}) {
let order;
return orderRequest
.createDraftOrder({ customerId, channelId, address })
.then(orderResp => {
order = orderResp;
assignVariantsToOrder(order, variantsList);
})
.then(orderResp => {
shippingMethod = getShippingMethodIdFromCheckout(
orderResp.order,
shippingMethod.name,
);
orderRequest.addShippingMethod(order.id, shippingMethod);
})
.then(() => orderRequest.completeOrder(order.id))
.then(resp => (order = resp.order));
}
function assignVariantsToOrder(order, variantsList) {
variantsList.forEach(variantElement => {
orderRequest.addProductToOrder(order.id, variantElement.id);
});
}
Order details datagrid (#3325) * Show available channels * Add price and updatedAt columns * Fix sorting, only sort on selected columns * Sort by channel * Allow delete name and product type * Fix show not product found * Extract mssages * Product datagrid custom column picker * Column picker in data grid in dirty hack for bug * fix storybook props * Restore Datagrid defalt column picker with custom render * Add sort by attributes * Use datagrid loading cells * Fix product searching * Show attributes before last updated * Readonly all fields in datagrid * Fix creating new datagrid row * Remove add new procut button from datagrid * Show only active sorted column * Temp fix for column filter * Fix column mismatch * Add comments and spred props to ColumnPicker * Cleanup * Update avatar size and styles * On row click with hover on row styles * Use new theme * Change placeholder image * Draw rounded image with border * Readonly product datagrid * Use new theme colors in datagrid * Add vertical borders control to datagrid * Add empty column to add padding * Add coursor to datagrid * Restore vertical borders, fix cursor pointer * Add custom freezed column * Initial tooltip for column * Move tooltip to datagrid * Adjust datagrid colors style, add possibility to select column * Change datagrid selected cells colors * Fix typo and extract messages * Base order datagrid * Cleanup Datagrid component * Cleanup and code refactor * Remove cursor pointer props from readonlyCell * Use money cell for total column * Add custom cell renderers and fix types * Simple tags implemenrtion for status and payment col * Add colors from theme * Make tagCell more dynamic * Refactor Datagrid file structure * Add loading indicators * Selecting column without cells in readonly * Add sort icons to orders list * Refactor after CR. fix typos * Change color of selected colum cell on hover * Improve selected header text contrast * Move useColumnPickerColumns to hooks dir with tests * Add less padding to column picker button * Remove double border top * Fix cursor pointer for tagCell and moneyCell * useGetCellContent hook * On loading show only one row * Add missing darkmod color for warning tag * Refactor columns in datagrid * Add new macaw theme provider to storybook * Fix passing props in datagrid * Trigger deployment * Fix column picker in products * useDatagridColumns * Fix one more time * Add column picker with default columns * Change color for selected header change to textBrandDefault * Remove unused code, move attributes colums as last * Cleanup useDatagridColumns * Improve DatagridProps * Static datagrid for products (#3144) * Migrate top nav of product list page to new MacawUI (#3290) * feat: migrate top nav of product page * feat: add proper deprecation links --------- Co-authored-by: Michał Droń <dron.official@yahoo.com> * Datagrin on order details intial * Adjust ExtraInfoLines * Remove padding on datagrid card content * Remove datagrid card paddding (#3310) * Disable column icon when no rows in orders * Datagrid row hover show only when readonly and row clickable * Implement card view for product list (#3292) * Add temporary view switcher * Add basic product tile view * Bump macaw-ui * Add ellipsis * Bump macaw-ui * Add status dot & fix non-rectangular thumbnails * Bump macaw-ui * Add variable size placeholder icon * Improve loader * Fix top nav menu key error * Add pagination * Add unit tests * Extract messages * Extract status color to function * CR Refactor * Hold product view state in local storage (#3315) * Remember view state for product list * Use util status function for status dots * Datagrin in orderDraftDetails * Remove not used components * Fix for empty column and hover in datagrid for product (#3324) * Remove datagrid card paddding (#3310) * Fix for empty column and hover in datagrid for product (#3324) * Use themeValues from macaw (#3326) * Upgrade macaw * Use themeValues * Use themeValues from macaw (#3326) * Upgrade macaw * Use themeValues * Add empty column from datagrid, improve theme types * Use theme type from typeof * Use empty column and themeValues * Filter empty column from default * New product header (#3346) * Extraxt messages * Remve title left padding * Fix switching view * Add margin right to nav button * Improve view switch * Update switch view icons * Add spacing to switch * Add more space * Add new filterbar to order list * Code refactor and tests * Refactor OrderDraftDetailsDatagrid * Extract messages * Refactor OrderDraftDetailsDatagrid * Update alert messages * Extract messages * Write unit tests * Improve switch component * Overwrite Pill styles * Common method to get status color for pills * Local Pill component POC * Add ThemeProvider to test wrapper * Extract messages * Refactor Pill * Fix Pill path * Fix tests mocks * Remove scrollbar and border bottom * Add custom border to to datagrid * Fix borders * Fix border bottom * Refactor and cleanup * Remove not needed selectionActions code * Move logic code t misc * Fix scrollbar and zindex datagrid borders * Fix product tiles condition * Use utils functions, remove not used code * Refactor to hooks * Loading prps instead of disabled * use getStatusColor * Move getMenuItems to separate function * Fix loading props * Use empty colum hook in OrderDetailsDatagrid * Fix empty column when save column change * Fix bottom line in layout overlap * Show moneCell with discounted price * Make quantity ediable in order draft datagrid * Readonly datagrid cells * Update onyl when column is quantity * Fix message * Keep first column in datagrid not removable * Fix for not existing column * Add loader over datagrid, fix problem with border top when empty text in variants * Fix error color and change color in datagrid * Use formatMoneyAmount * Fix remove order draft product with discount * Extract messages * Add product sku to order draft details datagrid * Fix loading state and change cell color * Add MoneyDiscuntedCell * Use MoneyDiscuntedCell in order draft details datagrid * Add trash bin icon * Restor discount modal for order draft summary * Fix problem with deleting quantity * Improve await for promises and handler zero quantity error * Fix column order issue * Add discount modal box shadow * Allow decimal as percentage value for discount * Fix max fixed value * Remove double border * Fix z-index issue on discount modal * Remove padding on order details datagrid * Add proper error message to common discount modal * Fix is submit disabled * Move status as last column in datagrid * Add padding to money discount cell editor * Make quantity column smaller * Fix recalculating disount value * Fix calculate change discount type * Store calculated value without triming decimal, trim decimal in input * Refactor money cells * markCellsDirty rename to areCellsDirty * Remove discount from MoneyCell * Use const to store row height in discount editor * Fix copy in discount modal * Remove past on money discount cell * Remove locale in product varaints * Fix nullable sku * Extract messages * Fix keeping always first column * Remove padding on tracking info * Fix story * Fix render 0 money amount * Fix displaying not empty string money * adding new tests: add new product, change quantity, add inline discount, delete product for grid - on orders details view (#3652) * adding new e2e for grid on orders details view * merging conflicts fix - and adding new TC numbers to new tests * trigger tests * failing tests fixes --------- Co-authored-by: Michał Droń <dron.official@yahoo.com> Co-authored-by: Krzysztof Żuraw <9116238+krzysztofzuraw@users.noreply.github.com> Co-authored-by: Michał Droń <droniu@droniu.dev> Co-authored-by: wojteknowacki <124166231+wojteknowacki@users.noreply.github.com> Co-authored-by: wojteknowacki <wojciech.nowacki@saleor.io>
2023-05-18 07:52:13 +00:00
export function createUnconfirmedOrder({
customerId,
shippingMethod,
channelId,
variantsList,
address,
}) {
let order;
return orderRequest
.createDraftOrder({ customerId, channelId, address })
.then(orderResp => {
order = orderResp;
assignVariantsToOrder(order, variantsList);
})
.then(orderResp => {
shippingMethod = getShippingMethodIdFromCheckout(
orderResp.order,
shippingMethod.name,
);
orderRequest.addShippingMethod(order.id, shippingMethod);
});
}
Feature - channels per plugin (#1093) * Update schema * Update queries, mutations, and types * Add render with dividers util function * Add plugin details channels card component * Update plugin details to use channels * Update stories * Update plugin configuration type across the app, fix some other types, temporarily comment some things out in plugins list so types match" * Update schema * Update types * Update plugins list to show channels and global statuses, add plugin channel status, update status label component * Add render with dividers util function * Comment out some stuff for types to match - temporary * Add useChannelsSearchWithLoadMore util to imitate loading more from backend for channels list with load more * Change filters logic to be able to display multiple fields in a field section and add it to plugins view * Add scroll option to plugin availability popup on plugin list * Fix plugin list page story * Temporarily comment some stuff out, fix some types * Add filters errors WIP * Fix filters not updating list * Add error handling to plugins list filters and filters in general * Rename some components according to review * Move useChannelsSearch and useChannelsSearchWithLoadMore to hooks, change some imports accordingly * Fix imports * Move render collection with dividers to a component, fix usages * Replace channels with load more and search query to base channels query * Change render with dividers function to take in a component instead of render function * Update tests * Extract messages * Remove unnecessary imports * Fix filters - autocomplete messing items order sometimes & some fields not working * Update plugin update mutation variables - change channelId to channel * fix failing tests * Add test ids * fix failing tests * fix failing tests * Rename misc.tsx to ts * Remove usage of render collection with diviers, change it to CollectionWithDividers component * Remove unnecessary imports * Update messages ids * Update snapshots Co-authored-by: Karolina Rakoczy <rakoczy.karolina@gmail.com>
2021-05-11 13:58:09 +00:00
export function addPayment(checkoutId) {
return checkoutRequest.addPayment({
checkoutId,
gateway: "mirumee.payments.dummy",
2022-08-04 10:59:42 +00:00
token: "not-charged",
});
}
export function addAdyenPayment(checkoutId, amount) {
return checkoutRequest.addPayment({
checkoutId,
gateway: "mirumee.payments.adyen",
2022-08-04 10:59:42 +00:00
amount,
});
}
export function addStripePayment(checkoutId, amount, token) {
return checkoutRequest.addPayment({
checkoutId,
gateway: "saleor.payments.stripe",
amount,
2022-08-04 10:59:42 +00:00
token,
});
}
export function createAndCompleteCheckoutWithoutShipping({
channelSlug,
email,
variantsList,
billingAddress,
2022-08-04 10:59:42 +00:00
auth,
}) {
let checkout;
return checkoutRequest
.createCheckout({ channelSlug, email, variantsList, billingAddress, auth })
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => checkoutRequest.completeCheckout(checkout.id))
.then(({ order }) => ({ checkout, order }));
}
export function createOrderWithNewProduct({
attributeId,
categoryId,
productTypeId,
channel,
name,
warehouseId,
quantityInWarehouse = 1,
trackInventory = true,
shippingMethod,
2022-08-04 10:59:42 +00:00
address,
}) {
let variantsList;
return createProductInChannel({
attributeId,
categoryId,
productTypeId,
channelId: channel.id,
name,
warehouseId,
quantityInWarehouse,
2022-08-04 10:59:42 +00:00
trackInventory,
})
.then(({ variantsList: variantsListResp }) => {
variantsList = variantsListResp;
createWaitingForCaptureOrder({
channelSlug: channel.slug,
email: "email@example.com",
variantsList,
shippingMethodName: shippingMethod.name,
2022-08-04 10:59:42 +00:00
address,
});
})
.then(({ order, checkout }) => ({ order, checkout, variantsList }));
}
export function addStripePaymentAndGetConfirmationData({
card,
checkoutId,
2022-08-04 10:59:42 +00:00
amount,
}) {
let paymentMethodId;
return getPaymentMethodStripeId(card)
.then(resp => {
paymentMethodId = resp.body.id;
addStripePayment(checkoutId, amount, resp.body.id);
})
.then(() => {
checkoutRequest.completeCheckout(checkoutId);
})
.then(resp => {
const confirmationData = JSON.parse(resp.confirmationData);
sendConfirmationToStripe(paymentMethodId, confirmationData.id, false);
})
.then(resp => resp);
}