fix(medeusa): Transform query includes options should only be added to allowed props if there is already at least one allowed props (#3362)

**What**
when `fields` only contain includes options, it should return the entire object plus the include options. If the fields contains the included options + other fields, it should only return the requested fields + the included options
This commit is contained in:
Adrien de Peretti
2023-03-07 12:52:14 +01:00
committed by GitHub
parent 15f47baf56
commit 33c6ccf059
6 changed files with 160 additions and 83 deletions

View File

@@ -2443,11 +2443,90 @@ describe("/admin/orders", () => {
)
expect(order.status).toEqual(200)
expect(order.data.order).toEqual(
expect.objectContaining({
id: "test-order",
})
// id + totals + region relation
expect(order.data.order).toEqual({
id: "test-order",
region: expect.any(Object),
shipping_total: 1000,
discount_total: 800,
tax_total: 0,
refunded_total: 0,
total: 8200,
subtotal: 8000,
paid_total: 0,
refundable_amount: 0,
gift_card_total: 0,
gift_card_tax_total: 0,
})
})
it("retrieves an order with expand returnable_items only should return the entire object and only returnable_items as relation", async () => {
const api = useApi()
const order = await api.get(
`/admin/orders/${testOrderId}?expand=returnable_items`,
adminReqConfig
)
expect(order.status).toEqual(200)
// all order properties + totals + returnable_items relation
expect(order.data.order).toEqual({
id: "test-order",
status: "pending",
fulfillment_status: "fulfilled",
payment_status: "captured",
display_id: expect.any(Number),
cart_id: null,
draft_order_id: null,
customer_id: "test-customer",
email: "test@email.com",
region_id: "test-region",
currency_code: "usd",
tax_rate: 0,
canceled_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
metadata: null,
no_notification: null,
sales_channel_id: null,
returnable_items: expect.any(Array),
shipping_total: 1000,
discount_total: 800,
tax_total: 0,
refunded_total: 0,
total: 8200,
subtotal: 8000,
paid_total: 10000,
refundable_amount: 10000,
gift_card_total: 0,
gift_card_tax_total: 0,
})
})
it("retrieves an order with expand returnable_items and field id should return the id and the retunable_items", async () => {
const api = useApi()
const order = await api.get(
`/admin/orders/${testOrderId}?expand=returnable_items&fields=id`,
adminReqConfig
)
expect(order.status).toEqual(200)
// id + totals + returnable_items relation
expect(order.data.order).toEqual({
id: "test-order",
returnable_items: expect.any(Array),
shipping_total: 1000,
discount_total: 800,
tax_total: 0,
refunded_total: 0,
total: 8200,
subtotal: 8000,
paid_total: 10000,
refundable_amount: 10000,
gift_card_total: 0,
gift_card_tax_total: 0,
})
})
it("retrieves an order should include the items totals", async () => {

View File

@@ -301,7 +301,7 @@ describe("/admin/swaps", () => {
// ********* CREATE SWAP *********
const createSwap = await api.post(
`/admin/orders/${completedOrder.data.data.id}/swaps?fields=returnable_items`,
`/admin/orders/${completedOrder.data.data.id}/swaps`,
{
return_items: [
{
@@ -318,13 +318,6 @@ describe("/admin/swaps", () => {
}
)
expect(createSwap.data.order.returnable_items).toHaveLength(1)
expect(createSwap.data.order.returnable_items[0]).toEqual(
expect.objectContaining({
id: "line-item",
})
)
let swap = createSwap.data.order.swaps[0]
// ********* PREPARE SWAP CART *********