saleor-dashboard/src/orders/utils/data.test.ts

1334 lines
32 KiB
TypeScript
Raw Normal View History

Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
/* eslint-disable sort-keys */
import { FormsetData } from "@saleor/hooks/useFormset";
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
import {
FulfillmentStatus,
OrderStatus,
PaymentChargeStatusEnum
} from "@saleor/types/globalTypes";
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
import { LineItemData } from "../components/OrderReturnPage/form";
import {
OrderDetails_order,
OrderDetails_order_fulfillments_lines,
OrderDetails_order_lines
} from "../types/OrderDetails";
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
import {
OrderRefundData_order_fulfillments,
OrderRefundData_order_lines
} from "../types/OrderRefundData";
import {
getAllFulfillmentLinesPriceSum,
getPreviouslyRefundedPrice,
getRefundedLinesPriceSum,
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
getReplacedProductsAmount,
getReturnSelectedProductsAmount,
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
mergeRepeatedOrderLines,
OrderWithTotalAndTotalCaptured
} from "./data";
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
const orderBase: OrderDetails_order = {
__typename: "Order",
actions: [],
availableShippingMethods: [],
canFinalize: true,
channel: null,
billingAddress: {
__typename: "Address",
city: "Port Danielshire",
cityArea: "",
companyName: "",
country: {
__typename: "CountryDisplay",
code: "SE",
country: "Szwecja"
},
countryArea: "",
firstName: "Elizabeth",
id: "QWRkcmVzczoy",
lastName: "Vaughn",
phone: "",
postalCode: "52203",
streetAddress1: "419 Ruiz Orchard Apt. 199",
streetAddress2: ""
},
created: "2018-09-11T09:37:30.124154+00:00",
id: "T3JkZXI6MTk=",
number: "19",
paymentStatus: PaymentChargeStatusEnum.FULLY_CHARGED,
status: OrderStatus.FULFILLED,
// @ts-ignore
total: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 1215.89,
currency: "USD"
}
}
};
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
describe("Get previously refunded price", () => {
it("is able to calculate refunded price from order", () => {
const order: OrderWithTotalAndTotalCaptured = {
total: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 160,
currency: "USD"
}
},
totalCaptured: {
__typename: "Money",
amount: 100,
currency: "USD"
}
};
const refundedPrice = getPreviouslyRefundedPrice(order);
expect(refundedPrice.amount).toBe(-60);
});
});
describe("Get refunded lines price sum", () => {
const lines: OrderRefundData_order_lines[] = [
{
__typename: "OrderLine",
id: "1",
productName: "Milk 1",
quantity: 1,
quantityFulfilled: 1,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 10,
currency: "USD"
}
}
},
{
__typename: "OrderLine",
id: "2",
productName: "Milk 2",
quantity: 2,
quantityFulfilled: 2,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 6,
currency: "USD"
}
}
},
{
__typename: "OrderLine",
id: "3",
productName: "Milk 3",
quantity: 4,
quantityFulfilled: 4,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 4,
currency: "USD"
}
}
}
];
it("is able to sum lines prices", () => {
const refundedProductQuantities: FormsetData<null, string> = [
{
data: null,
id: "1",
label: null,
value: "1"
},
{
data: null,
id: "2",
label: null,
value: "1"
},
{
data: null,
id: "3",
label: null,
value: "1"
}
];
const refundedLinesPriceSum = getRefundedLinesPriceSum(
lines,
refundedProductQuantities
);
expect(refundedLinesPriceSum).toBe(20);
});
it("is able to sum lines prices multiplied by different quantities", () => {
const refundedProductQuantities: FormsetData<null, string> = [
{
data: null,
id: "1",
label: null,
value: "0"
},
{
data: null,
id: "2",
label: null,
value: "2"
},
{
data: null,
id: "3",
label: null,
value: "4"
}
];
const refundedLinesPriceSum = getRefundedLinesPriceSum(
lines,
refundedProductQuantities
);
expect(refundedLinesPriceSum).toBe(28);
});
});
describe("Get get all fulfillment lines price sum", () => {
const fulfillments: OrderRefundData_order_fulfillments[] = [
{
__typename: "Fulfillment",
fulfillmentOrder: 1,
id: "1",
lines: [
{
__typename: "FulfillmentLine",
id: "1-fulfillment-1",
orderLine: {
__typename: "OrderLine",
id: "1-line-1",
productName: "Milk 1",
quantity: 1,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 10,
currency: "USD"
}
}
},
quantity: 1
}
],
status: FulfillmentStatus.FULFILLED
},
{
__typename: "Fulfillment",
fulfillmentOrder: 2,
id: "2",
lines: [
{
__typename: "FulfillmentLine",
id: "2-fulfillment-1",
orderLine: {
__typename: "OrderLine",
id: "2-line-1",
productName: "Milk 1",
quantity: 2,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 6,
currency: "USD"
}
}
},
quantity: 1
},
{
__typename: "FulfillmentLine",
id: "2-fulfillment-2",
orderLine: {
__typename: "OrderLine",
id: "2-line-2",
productName: "Milk 2",
quantity: 2,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 6,
currency: "USD"
}
}
},
quantity: 1
}
],
status: FulfillmentStatus.FULFILLED
},
{
__typename: "Fulfillment",
fulfillmentOrder: 1,
id: "3",
lines: [
{
__typename: "FulfillmentLine",
id: "3-fulfillment-1",
orderLine: {
__typename: "OrderLine",
id: "3-line-1",
productName: "Milk 1",
quantity: 4,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 4,
currency: "USD"
}
}
},
quantity: 1
},
{
__typename: "FulfillmentLine",
id: "3-fulfillment-2",
orderLine: {
__typename: "OrderLine",
id: "3-line-2",
productName: "Milk 2",
quantity: 4,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 4,
currency: "USD"
}
}
},
quantity: 1
},
{
__typename: "FulfillmentLine",
id: "3-fulfillment-3",
orderLine: {
__typename: "OrderLine",
id: "3-line-3",
productName: "Milk 3",
quantity: 4,
thumbnail: undefined,
unitPrice: {
__typename: "TaxedMoney",
gross: {
__typename: "Money",
amount: 4,
currency: "USD"
}
}
},
quantity: 1
}
],
status: FulfillmentStatus.FULFILLED
}
];
it("is able to sum fulfillment lines prices", () => {
const refundedFulfilledProductQuantities: FormsetData<null, string> = [
{
data: null,
id: "1-fulfillment-1",
label: null,
value: "1"
},
{
data: null,
id: "2-fulfillment-1",
label: null,
value: "1"
},
{
data: null,
id: "2-fulfillment-2",
label: null,
value: "1"
},
{
data: null,
id: "3-fulfillment-1",
label: null,
value: "1"
},
{
data: null,
id: "3-fulfillment-2",
label: null,
value: "1"
},
{
data: null,
id: "3-fulfillment-3",
label: null,
value: "1"
}
];
const allFulfillmentLinesPriceSum = getAllFulfillmentLinesPriceSum(
fulfillments,
refundedFulfilledProductQuantities
);
expect(allFulfillmentLinesPriceSum).toBe(34);
});
it("is able to sum fulfillment lines prices multiplied by different quantities", () => {
const refundedFulfilledProductQuantities: FormsetData<null, string> = [
{
data: null,
id: "1-fulfillment-1",
label: null,
value: "0"
},
{
data: null,
id: "2-fulfillment-1",
label: null,
value: "2"
},
{
data: null,
id: "2-fulfillment-2",
label: null,
value: "2"
},
{
data: null,
id: "3-fulfillment-1",
label: null,
value: "4"
},
{
data: null,
id: "3-fulfillment-2",
label: null,
value: "4"
},
{
data: null,
id: "3-fulfillment-3",
label: null,
value: "4"
}
];
const allFulfillmentLinesPriceSum = getAllFulfillmentLinesPriceSum(
fulfillments,
refundedFulfilledProductQuantities
);
expect(allFulfillmentLinesPriceSum).toBe(72);
});
});
Feature/order reissue (#910) * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add change to changelog * Remove console.log * Update tests * Extract messages * Add utils functions for selecting only ulfulfilled order lines * Add optional value selection for line item * Update tests * Add optional rendering of unfulfilled items card and refactor a bit * Update displaying of items card title when refunded card * UUpdate utils, form data etc. not to include refunded items when calculating replaced items amount * Uppdate return items card not to display replace buttons for refunded items * Refactor and small fixes after review * Update extracted messages * Fix card title when no fullfilemtn id * wip * Initially stitch returns page. Update types, add mutation * remove unnecessary component display names * Add loading status from form submission & refactor * Add errors from response * Add errors from response and refactor * Remove comments * Add optional error adding when no data from return create request * Update messages * wip * Update snapshots * Remove unnecessary console.log * Add better typing for getParsedLineData function * Update & refactor card title to match cards both in return and order details * Add handling of new statuses to order details cards. Also refactor, and devide order fulfillment card into couple of smaller components * Update messages * Update schema to match api * Update types * Update status label component to match colors with new designs and order details cards * RUpdate and refactor order fulfillment card components to be reusable. Also add replaced status handling * Updayte card title component to handle all cases and statuses * Update oorder unfulfilled items card and order details page, reduce some of the boilerplate * Fix card title types and adjust returns card to match * Update messages * Update snapshots * RUpdate order fulfillment card with subtitles and buttons for returned status * Add onRefund to order fulfillment card * Fix typo and wrong message in card title * Add missing condition in return form submission utils to decice if to refund products * Update fulfillment subtitles row and tests * Update messages * Change naming and locations of OrderFulfillment and items card components * Update messages * U[pdate names of components again to even better ones * Update messages * changelog * Update schema and types so that order history event also includes user first and last name * Add extended timeline event and event header components. Move some of the logic to utils and add way to display links in the event header. * FFix types * Update messages * Change naming of isOfType -> isTimelineEventOfType and refactor extended timeline event messages selection to be less complicated * Add ids and update messages * Add ids and update messages some more * Update storybook decorator to work with react router context in components and tests * Refactor after review * Update messages * Add rredirecting to draft order * Add handling draft creation from replacement * Add related order to order event fragment and update lots and lots of types * Update extended timeline event to match related order type on order history event * Update fixtures * Refactor ExtendedTimelineEvent Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com> * Fix typing * Update messages * Fix missing history event for replacement draft created for replaced products * Update messages * Handle new statuses for returned and partially returned orders * Update messages * update snapshots * BBump empty line to rebuild ci * Change status to proper color * Change replaceable items in return for replace to be auto off instead of on * Add utils functions and make order details menu not show option to return items when there are returnable items in the order * Fix replace checkbox showing when previously hidden and clicked set maximal quantities * Fix return form invalid money values * Add default values to avoid returning of NaN in utils for return amount and refactor * Add ggeneral error alerts * Add eproduct error box component and style. style a lot. * Fixes * Fix lint * Add cannot refund error title + description * Extract messages * Refactor after review * Add better, nicer and fancier imports to product error cell * Use error color from palette in product error cell * Fix max refund when 0 for return * Add ddisable ability to refund products button so it's disabled when 0 products selected * Add class for order return form data parsing and add condition to not do refund when total captured on order is 0 * Update snapshots * Add condition for order lines quantity in order products table row * Fix return amount submit button * Add change to changelog Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2021-01-20 16:16:43 +00:00
describe("Get the total value of all replaced products", () => {
it("sums up correctly", () => {
const unfulfilledLines: OrderDetails_order_lines[] = [
{
id: "1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 2,
quantityFulfilled: 2,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
{
id: "2",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 10,
quantityFulfilled: 2,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
{
id: "3",
isShippingRequired: true,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6Mjg2",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "T-shirt",
productSku: "29810068",
quantity: 6,
quantityFulfilled: 1,
unitPrice: {
gross: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
net: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleordemoproduct_cl_boot06_1-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
}
];
const fulfilledLines: OrderDetails_order_fulfillments_lines[] = [
{
id: "4",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 20,
quantityFulfilled: 6,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "5",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 25,
quantityFulfilled: 8,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "6",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ3",
isShippingRequired: true,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6Mjg2",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "T-shirt",
productSku: "29810068",
quantity: 10,
quantityFulfilled: 3,
unitPrice: {
gross: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
net: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleordemoproduct_cl_boot06_1-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "7",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 20,
quantityFulfilled: 6,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "8",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 25,
quantityFulfilled: 8,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
}
];
const unfulfiledItemsQuantities: FormsetData<LineItemData, number> = [
{
data: { isFulfillment: false, isRefunded: false },
id: "1",
label: null,
value: 0
},
{
data: { isFulfillment: false, isRefunded: false },
id: "2",
label: null,
value: 2
},
{
data: { isFulfillment: false, isRefunded: false },
id: "3",
label: null,
value: 1
}
];
const fulfiledItemsQuantities: FormsetData<LineItemData, number> = [
{
data: { isFulfillment: true, isRefunded: false },
id: "4",
label: null,
value: 4
},
{
data: { isFulfillment: true, isRefunded: false },
id: "5",
label: null,
value: 0
},
{
data: { isFulfillment: true, isRefunded: false },
id: "6",
label: null,
value: 3
},
{
data: { isFulfillment: true, isRefunded: true },
id: "7",
label: null,
value: 4
},
{
data: { isFulfillment: true, isRefunded: true },
id: "8",
label: null,
value: 3
}
];
const itemsToBeReplaced: FormsetData<LineItemData, boolean> = [
{
data: { isFulfillment: false, isRefunded: false },
id: "1",
label: null,
value: true
},
{
data: { isFulfillment: false, isRefunded: false },
id: "2",
label: null,
value: false
},
{
data: { isFulfillment: false, isRefunded: false },
id: "3",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: false },
id: "4",
label: null,
value: false
},
{
data: { isFulfillment: true, isRefunded: false },
id: "5",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: false },
id: "6",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: true },
id: "7",
label: null,
value: false
},
{
data: { isFulfillment: true, isRefunded: true },
id: "8",
label: null,
value: true
}
];
const totalValue = getReplacedProductsAmount(
{
...orderBase,
lines: unfulfilledLines,
fulfillments: [
{
id: "#1",
fulfillmentOrder: 1,
status: FulfillmentStatus.FULFILLED,
warehouse: null,
trackingNumber: "",
lines: fulfilledLines,
__typename: "Fulfillment"
}
]
},
{
itemsToBeReplaced,
unfulfiledItemsQuantities,
fulfiledItemsQuantities
}
);
expect(totalValue).toBe(10);
});
});
describe("Get the total value of all selected products", () => {
it("sums up correctly", () => {
const unfulfilledLines: OrderDetails_order_lines[] = [
{
id: "1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 2,
quantityFulfilled: 2,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
{
id: "2",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 10,
quantityFulfilled: 2,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
{
id: "3",
isShippingRequired: true,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6Mjg2",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "T-shirt",
productSku: "29810068",
quantity: 6,
quantityFulfilled: 1,
unitPrice: {
gross: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
net: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleordemoproduct_cl_boot06_1-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
}
];
const fulfilledLines: OrderDetails_order_fulfillments_lines[] = [
{
id: "4",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 20,
quantityFulfilled: 6,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "5",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 25,
quantityFulfilled: 8,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "6",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ3",
isShippingRequired: true,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6Mjg2",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "T-shirt",
productSku: "29810068",
quantity: 10,
quantityFulfilled: 3,
unitPrice: {
gross: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
net: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleordemoproduct_cl_boot06_1-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
}
];
const unfulfiledItemsQuantities: FormsetData<null, number> = [
{
data: null,
id: "1",
label: null,
value: 0
},
{
data: null,
id: "2",
label: null,
value: 2
},
{
data: null,
id: "3",
label: null,
value: 1
}
];
const fulfiledItemsQuantities: FormsetData<null, number> = [
{
data: null,
id: "4",
label: null,
value: 4
},
{
data: null,
id: "5",
label: null,
value: 0
},
{
data: null,
id: "6",
label: null,
value: 3
}
];
const itemsToBeReplaced: FormsetData<LineItemData, boolean> = [
{
data: { isFulfillment: false, isRefunded: false },
id: "1",
label: null,
value: true
},
{
data: { isFulfillment: false, isRefunded: false },
id: "2",
label: null,
value: false
},
{
data: { isFulfillment: false, isRefunded: false },
id: "3",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: false },
id: "4",
label: null,
value: false
},
{
data: { isFulfillment: true, isRefunded: false },
id: "5",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: false },
id: "6",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: true },
id: "7",
label: null,
value: true
},
{
data: { isFulfillment: true, isRefunded: true },
id: "8",
label: null,
value: true
}
];
const totalValue = getReturnSelectedProductsAmount(
{
...orderBase,
lines: unfulfilledLines,
fulfillments: [
{
id: "#1",
fulfillmentOrder: 1,
status: FulfillmentStatus.FULFILLED,
warehouse: null,
trackingNumber: "",
lines: fulfilledLines,
__typename: "Fulfillment"
}
]
},
{
itemsToBeReplaced,
unfulfiledItemsQuantities,
fulfiledItemsQuantities
}
);
expect(totalValue).toBe(59.94);
});
});
Refunds (#870) * 1721 - add refunds miscellaneous view (#860) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Fix refund details on order details page (#879) * Update order details view for refunds (#874) * 1719 - add refund entry to order history (#875) * Add refund order history entry * Update refund event with the right query * 1722 - add refunds product view (#873) * Create new page for Miscellaneous Refunds * Replace refund order dialog with dedicated page * Add data test ids * Create refund products table * Implement refund products view * Update refund mutation with product lines input * Fix products quantities on refund page * Fix order refund submission * Fix products refund submission input variables * Filter out fulfillments on refund page * Update refund page in storybook * Fix test snapshots after wrong refunds rebase * Set max refund as captured amount * Refund queries adjustments * Display refund values with nullish coalescing operator * Update test snapshots with refunds * Refactor order refund values calculation * Create and use refund order line fragment * Use old simple refund mutation for miscellaneous refund * Submit for refund only lines with non-zero quantity set * Fix showing refund error * Add missing refund amount to order history * Merge repeated order lines in fulfillment lines * Update order history events types and test snapshots * Update changelog with refunds changes
2020-12-01 13:13:05 +00:00
describe("Merge repeated order lines of fulfillment lines", () => {
it("is able to merge repeated order lines and sum their quantities", () => {
const lines: OrderDetails_order_fulfillments_lines[] = [
{
id: "RnVsZmlsbG1lbnRMaW5lOjMx",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 2,
quantityFulfilled: 2,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "RnVsZmlsbG1lbnRMaW5lOjMy",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ1",
isShippingRequired: false,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6MzE3",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "Lake Tunes",
productSku: "lake-tunes-mp3",
quantity: 2,
quantityFulfilled: 2,
unitPrice: {
gross: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
net: {
amount: 9.99,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleor-digital-03_2-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
},
{
id: "RnVsZmlsbG1lbnRMaW5lOjMz",
quantity: 1,
orderLine: {
id: "T3JkZXJMaW5lOjQ3",
isShippingRequired: true,
variant: {
id: "UHJvZHVjdFZhcmlhbnQ6Mjg2",
quantityAvailable: 50,
__typename: "ProductVariant"
},
productName: "T-shirt",
productSku: "29810068",
quantity: 3,
quantityFulfilled: 1,
unitPrice: {
gross: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
net: {
amount: 2.5,
currency: "USD",
__typename: "Money"
},
__typename: "TaxedMoney"
},
thumbnail: {
url:
"http://localhost:8000/media/__sized__/products/saleordemoproduct_cl_boot06_1-thumbnail-255x255.png",
__typename: "Image"
},
__typename: "OrderLine"
},
__typename: "FulfillmentLine"
}
];
const mergedLines = mergeRepeatedOrderLines(lines);
expect(mergedLines).toHaveLength(2);
expect(
mergedLines.find(
fulfillmentLine => fulfillmentLine.orderLine.id === "T3JkZXJMaW5lOjQ1"
).quantity
).toBe(2);
});
});