fix: Several fixes to store product endpoints, moved several test suites to HTTP (#7601)
* chore: Move publishable api key tests to HTTP * chore: Move store tests to HTTP folder * fix: Add tests for store products, fix several bugs around publishable keys
This commit is contained in:
@@ -2,6 +2,7 @@ import { isPresent } from "@medusajs/utils"
|
||||
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
|
||||
import { refetchProduct, wrapVariantsWithInventoryQuantity } from "../helpers"
|
||||
import { StoreGetProductsParamsType } from "../validators"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
|
||||
export const GET = async (
|
||||
req: MedusaRequest<StoreGetProductsParamsType>,
|
||||
@@ -34,6 +35,13 @@ export const GET = async (
|
||||
req.remoteQueryConfig.fields
|
||||
)
|
||||
|
||||
if (!product) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Product with id: ${req.params.id} was not found`
|
||||
)
|
||||
}
|
||||
|
||||
if (withInventoryQuantity) {
|
||||
await wrapVariantsWithInventoryQuantity(req, product.variants || [])
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
StoreGetProductsParams,
|
||||
StoreGetProductsParamsType,
|
||||
} from "./validators"
|
||||
import { applyParamsAsFilters } from "../../utils/middlewares/common/apply-params-as-filters"
|
||||
|
||||
export const storeProductRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
@@ -57,6 +58,7 @@ export const storeProductRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
StoreGetProductsParams,
|
||||
QueryConfig.retrieveProductQueryConfig
|
||||
),
|
||||
applyParamsAsFilters({ id: "id" }),
|
||||
filterByValidSalesChannels(),
|
||||
setContext({
|
||||
stock_location_id: maybeApplyStockLocationId,
|
||||
|
||||
Reference in New Issue
Block a user