fix(medusa): Pass query transformer config in storefront controllers (#3219)
This commit is contained in:
1 parent
8c5219a31e
commit
61b0b2f3aa
6 files changed
+31
-26
No files matched your search
@@ -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 () => {
|
it("lookup order response contains only fields defined with `fields` param", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api
|
const response = await api.get(
|
||||||
.get(
|
"/store/orders?display_id=111&email=test@email.com&fields=status,email"
|
||||||
"/store/orders?display_id=111&email=test@email.com&fields=status,object"
|
|
||||||
)
|
)
|
||||||
.catch((err) => {
|
|
||||||
return err.response
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(Object.keys(response.data.order)).toEqual([
|
expect(Object.keys(response.data.order)).toEqual([
|
||||||
// fields
|
// fields
|
||||||
"status",
|
"status",
|
||||||
"object",
|
"email",
|
||||||
// relations
|
// relations
|
||||||
"shipping_address",
|
"shipping_address",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
@@ -185,17 +181,12 @@ describe("/store/carts", () => {
|
|||||||
it("get order response contains only fields defined with `fields` param", async () => {
|
it("get order response contains only fields defined with `fields` param", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
const response = await api
|
const response = await api.get("/store/orders/order_test?fields=status")
|
||||||
.get("/store/orders/order_test?fields=status,object")
|
|
||||||
.catch((err) => {
|
|
||||||
return err.response
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(Object.keys(response.data.order)).toEqual([
|
expect(Object.keys(response.data.order)).toEqual([
|
||||||
// fields
|
// fields
|
||||||
"status",
|
"status",
|
||||||
"object",
|
// default relations
|
||||||
// relations
|
|
||||||
"shipping_address",
|
"shipping_address",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
"items",
|
"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 () => {
|
it("looks up order", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -53,10 +53,7 @@ export default async (req, res) => {
|
|||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
|
|
||||||
const orderService: OrderService = req.scope.resolve("orderService")
|
const orderService: OrderService = req.scope.resolve("orderService")
|
||||||
const order = await orderService.retrieveWithTotals(id, {
|
const order = await orderService.retrieveWithTotals(id, req.retrieveConfig)
|
||||||
select: defaultStoreOrdersFields,
|
|
||||||
relations: defaultStoreOrdersRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
order: cleanResponseData(order, req.allowedProperties || []),
|
order: cleanResponseData(order, req.allowedProperties || []),
|
||||||
|
|||||||
@@ -92,10 +92,7 @@ export default async (req, res) => {
|
|||||||
display_id: validated.display_id,
|
display_id: validated.display_id,
|
||||||
email: validated.email,
|
email: validated.email,
|
||||||
},
|
},
|
||||||
{
|
req.listConfig
|
||||||
select: defaultStoreOrdersFields,
|
|
||||||
relations: defaultStoreOrdersRelations,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (orders.length !== 1) {
|
if (orders.length !== 1) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { IdMap } from "medusa-test-utils"
|
import { IdMap } from "medusa-test-utils"
|
||||||
import { defaultStoreProductsRelations } from ".."
|
import { defaultStoreProductsFields, defaultStoreProductsRelations } from ".."
|
||||||
import { request } from "../../../../../helpers/test-request"
|
import { request } from "../../../../../helpers/test-request"
|
||||||
import { ProductServiceMock } from "../../../../../services/__mocks__/product"
|
import { ProductServiceMock } from "../../../../../services/__mocks__/product"
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@ describe("Get product by id", () => {
|
|||||||
expect(ProductServiceMock.retrieve).toHaveBeenCalledWith(
|
expect(ProductServiceMock.retrieve).toHaveBeenCalledWith(
|
||||||
IdMap.getId("product1"),
|
IdMap.getId("product1"),
|
||||||
{
|
{
|
||||||
|
select: defaultStoreProductsFields,
|
||||||
relations: defaultStoreProductsRelations,
|
relations: defaultStoreProductsRelations,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -54,6 +55,7 @@ describe("Get product by id", () => {
|
|||||||
expect(ProductServiceMock.retrieve).toHaveBeenCalledWith(
|
expect(ProductServiceMock.retrieve).toHaveBeenCalledWith(
|
||||||
IdMap.getId("variantsWithPrices"),
|
IdMap.getId("variantsWithPrices"),
|
||||||
{
|
{
|
||||||
|
select: defaultStoreProductsFields,
|
||||||
relations: defaultStoreProductsRelations,
|
relations: defaultStoreProductsRelations,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -84,9 +84,7 @@ export default async (req, res) => {
|
|||||||
const pricingService: PricingService = req.scope.resolve("pricingService")
|
const pricingService: PricingService = req.scope.resolve("pricingService")
|
||||||
const cartService: CartService = req.scope.resolve("cartService")
|
const cartService: CartService = req.scope.resolve("cartService")
|
||||||
const regionService: RegionService = req.scope.resolve("regionService")
|
const regionService: RegionService = req.scope.resolve("regionService")
|
||||||
const rawProduct = await productService.retrieve(id, {
|
const rawProduct = await productService.retrieve(id, req.retrieveConfig)
|
||||||
relations: defaultStoreProductsRelations,
|
|
||||||
})
|
|
||||||
|
|
||||||
let sales_channel_id = validated.sales_channel_id
|
let sales_channel_id = validated.sales_channel_id
|
||||||
const featureFlagRouter: FlagRouter = req.scope.resolve("featureFlagRouter")
|
const featureFlagRouter: FlagRouter = req.scope.resolve("featureFlagRouter")
|
||||||
|
|||||||
Reference in new issue
Block a user