fix(medusa): Pass query transformer config in storefront controllers (#3219)
This commit is contained in:
5
.changeset/green-socks-attack.md
Normal file
5
.changeset/green-socks-attack.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix(medusa): use transformer middleware config when querying store products and store orders endpoints
|
||||
@@ -158,18 +158,14 @@ describe("/store/carts", () => {
|
||||
it("lookup order response contains only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get(
|
||||
"/store/orders?display_id=111&email=test@email.com&fields=status,object"
|
||||
)
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
const response = await api.get(
|
||||
"/store/orders?display_id=111&email=test@email.com&fields=status,email"
|
||||
)
|
||||
|
||||
expect(Object.keys(response.data.order)).toEqual([
|
||||
// fields
|
||||
"status",
|
||||
"object",
|
||||
"email",
|
||||
// relations
|
||||
"shipping_address",
|
||||
"fulfillments",
|
||||
@@ -185,17 +181,12 @@ describe("/store/carts", () => {
|
||||
it("get order response contains only fields defined with `fields` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/store/orders/order_test?fields=status,object")
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
const response = await api.get("/store/orders/order_test?fields=status")
|
||||
|
||||
expect(Object.keys(response.data.order)).toEqual([
|
||||
// fields
|
||||
"status",
|
||||
"object",
|
||||
// relations
|
||||
// default relations
|
||||
"shipping_address",
|
||||
"fulfillments",
|
||||
"items",
|
||||
@@ -207,6 +198,21 @@ describe("/store/carts", () => {
|
||||
])
|
||||
})
|
||||
|
||||
it("get order response contains only fields defined with `fields` and `expand` param", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
"/store/orders/order_test?fields=status&expand=billing_address"
|
||||
)
|
||||
|
||||
expect(Object.keys(response.data.order)).toEqual([
|
||||
// fields
|
||||
"status",
|
||||
// selected relations
|
||||
"billing_address",
|
||||
])
|
||||
})
|
||||
|
||||
it("looks up order", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -53,10 +53,7 @@ export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const orderService: OrderService = req.scope.resolve("orderService")
|
||||
const order = await orderService.retrieveWithTotals(id, {
|
||||
select: defaultStoreOrdersFields,
|
||||
relations: defaultStoreOrdersRelations,
|
||||
})
|
||||
const order = await orderService.retrieveWithTotals(id, req.retrieveConfig)
|
||||
|
||||
res.json({
|
||||
order: cleanResponseData(order, req.allowedProperties || []),
|
||||
|
||||
@@ -92,10 +92,7 @@ export default async (req, res) => {
|
||||
display_id: validated.display_id,
|
||||
email: validated.email,
|
||||
},
|
||||
{
|
||||
select: defaultStoreOrdersFields,
|
||||
relations: defaultStoreOrdersRelations,
|
||||
}
|
||||
req.listConfig
|
||||
)
|
||||
|
||||
if (orders.length !== 1) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { defaultStoreProductsRelations } from ".."
|
||||
import { defaultStoreProductsFields, defaultStoreProductsRelations } from ".."
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { ProductServiceMock } from "../../../../../services/__mocks__/product"
|
||||
|
||||
@@ -22,6 +22,7 @@ describe("Get product by id", () => {
|
||||
expect(ProductServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
IdMap.getId("product1"),
|
||||
{
|
||||
select: defaultStoreProductsFields,
|
||||
relations: defaultStoreProductsRelations,
|
||||
}
|
||||
)
|
||||
@@ -54,6 +55,7 @@ describe("Get product by id", () => {
|
||||
expect(ProductServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
IdMap.getId("variantsWithPrices"),
|
||||
{
|
||||
select: defaultStoreProductsFields,
|
||||
relations: defaultStoreProductsRelations,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -84,9 +84,7 @@ export default async (req, res) => {
|
||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||
const cartService: CartService = req.scope.resolve("cartService")
|
||||
const regionService: RegionService = req.scope.resolve("regionService")
|
||||
const rawProduct = await productService.retrieve(id, {
|
||||
relations: defaultStoreProductsRelations,
|
||||
})
|
||||
const rawProduct = await productService.retrieve(id, req.retrieveConfig)
|
||||
|
||||
let sales_channel_id = validated.sales_channel_id
|
||||
const featureFlagRouter: FlagRouter = req.scope.resolve("featureFlagRouter")
|
||||
|
||||
Reference in New Issue
Block a user