fix(medusa): cart now returns 404 when not found (#13622)
FIXES #10218 FIXES CORE-739
This commit is contained in:
6
.changeset/warm-bobcats-prove.md
Normal file
6
.changeset/warm-bobcats-prove.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"integration-tests-http": patch
|
||||
---
|
||||
|
||||
fix(medusa): cart now returns 404 when not found
|
||||
@@ -9,11 +9,7 @@ import {
|
||||
PromotionStatus,
|
||||
PromotionType,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
createAdminUser,
|
||||
generatePublishableKey,
|
||||
generateStoreHeaders,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
import { createAdminUser, generatePublishableKey, generateStoreHeaders, } from "../../../../helpers/create-admin-user"
|
||||
import { setupTaxStructure } from "../../../../modules/__tests__/fixtures"
|
||||
import { createAuthenticatedCustomer } from "../../../../modules/helpers/create-authenticated-customer"
|
||||
import { medusaTshirtProduct } from "../../../__fixtures__/product"
|
||||
@@ -152,6 +148,17 @@ medusaIntegrationTestRunner({
|
||||
).data.promotion
|
||||
})
|
||||
|
||||
describe("GET /store/carts/[id]", () => {
|
||||
it("should return 404 when trying to fetch a cart that does not exist", async () => {
|
||||
const response = await api.get(
|
||||
`/store/carts/fake`,
|
||||
storeHeadersWithCustomer
|
||||
).catch((e) => e)
|
||||
|
||||
expect(response.response.status).toEqual(404)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
it("should successfully create a cart", async () => {
|
||||
const response = await api.post(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { MedusaContainer } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
|
||||
@@ -18,5 +19,12 @@ export const refetchCart = async (
|
||||
|
||||
const [cart] = await remoteQuery(queryObject)
|
||||
|
||||
if (!cart) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Cart with id '${id}' not found`
|
||||
)
|
||||
}
|
||||
|
||||
return cart
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user