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:
Stevche Radevski
2024-06-04 21:00:07 +02:00
committed by GitHub
parent d104d1a256
commit e44fe78b96
24 changed files with 2301 additions and 2763 deletions
@@ -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,