hotfix: joins discounts when creating claims (#760)
* fix: join discounts when creating claims * fix: rm verbose/only * fix: rm dup tests
This commit is contained in:
@@ -359,6 +359,38 @@ describe("/admin/orders", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("creates a claim on order with discount", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/orders/discount-order/claims",
|
||||
{
|
||||
type: "refund",
|
||||
claim_items: [
|
||||
{
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
tags: ["fluff"],
|
||||
images: ["https://test.image.com"],
|
||||
},
|
||||
],
|
||||
additional_items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("creates a claim on a claim", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
const {
|
||||
ShippingProfile,
|
||||
Customer,
|
||||
MoneyAmount,
|
||||
Discount,
|
||||
DiscountRule,
|
||||
LineItem,
|
||||
Country,
|
||||
ShippingOption,
|
||||
ShippingMethod,
|
||||
MoneyAmount,
|
||||
Order,
|
||||
Payment,
|
||||
Product,
|
||||
ProductVariant,
|
||||
Region,
|
||||
Payment,
|
||||
Order,
|
||||
ShippingMethod,
|
||||
ShippingOption,
|
||||
ShippingProfile,
|
||||
Swap,
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
@@ -320,4 +321,76 @@ module.exports = async (connection, data = {}) => {
|
||||
id: "o-pay4",
|
||||
...paymentTemplate(),
|
||||
})
|
||||
|
||||
const drule = manager.create(DiscountRule, {
|
||||
id: "test-rule",
|
||||
description: "Test Discount",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
})
|
||||
|
||||
const discount = manager.create(Discount, {
|
||||
id: "test-discount-o",
|
||||
code: "TEST1234",
|
||||
is_dynamic: false,
|
||||
rule: drule,
|
||||
is_disabled: false,
|
||||
regions: [
|
||||
{
|
||||
id: "test-region",
|
||||
},
|
||||
],
|
||||
})
|
||||
await manager.save(discount)
|
||||
|
||||
const payment = manager.create(Payment, {
|
||||
id: "test-payment-d",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test-pay",
|
||||
captured_at: new Date(),
|
||||
data: {},
|
||||
})
|
||||
|
||||
const discountedOrder = manager.create(Order, {
|
||||
id: "discount-order",
|
||||
customer_id: "test-customer",
|
||||
email: "test@email.com",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
discounts: [discount],
|
||||
billing_address: {
|
||||
id: "test-billing-address",
|
||||
first_name: "lebron",
|
||||
},
|
||||
shipping_address: {
|
||||
id: "test-shipping-address",
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
payments: [payment],
|
||||
items: [],
|
||||
})
|
||||
|
||||
await manager.save(discountedOrder)
|
||||
|
||||
const dli = manager.create(LineItem, {
|
||||
id: "test-item",
|
||||
fulfilled_quantity: 1,
|
||||
returned_quantity: 0,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
order_id: "discount-order",
|
||||
})
|
||||
|
||||
await manager.save(dli)
|
||||
}
|
||||
|
||||
@@ -198,16 +198,11 @@ export default async (req, res) => {
|
||||
case "started": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
const order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, {
|
||||
relations: [
|
||||
"items",
|
||||
"cart",
|
||||
"cart.discounts",
|
||||
"cart.discounts.rule",
|
||||
],
|
||||
relations: ["items", "discounts", "discounts.rule"],
|
||||
})
|
||||
|
||||
await claimService.withTransaction(manager).create({
|
||||
@@ -241,7 +236,7 @@ export default async (req, res) => {
|
||||
case "claim_created": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
let claim = await claimService.withTransaction(manager).list({
|
||||
idempotency_key: idempotencyKey.idempotency_key,
|
||||
})
|
||||
@@ -279,7 +274,7 @@ export default async (req, res) => {
|
||||
case "refund_handled": {
|
||||
const { key, error } = await idempotencyKeyService.workStage(
|
||||
idempotencyKey.idempotency_key,
|
||||
async manager => {
|
||||
async (manager) => {
|
||||
let order = await orderService
|
||||
.withTransaction(manager)
|
||||
.retrieve(id, {
|
||||
|
||||
Reference in New Issue
Block a user