feat(medusa): Remove require id from update shipping options validator (#7166)
* feat(medusa): Remove require id from update shipping options validator * update type apply * Create great-stingrays-clap.md
This commit is contained in:
committed by
GitHub
parent
82cb6cfd36
commit
08a9297f76
5
.changeset/great-stingrays-clap.md
Normal file
5
.changeset/great-stingrays-clap.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
feat(medusa): Remove require id from update shipping options validator
|
||||
@@ -204,66 +204,6 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
|
||||
describe("POST /admin/shipping-options/:id", () => {
|
||||
it("should throw error when required params are missing", async () => {
|
||||
const shippingOptionPayload = {
|
||||
name: "Test shipping option",
|
||||
service_zone_id: fulfillmentSet.service_zones[0].id,
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
provider_id: "manual_test-provider",
|
||||
price_type: "flat",
|
||||
type: {
|
||||
label: "Test type",
|
||||
description: "Test description",
|
||||
code: "test-code",
|
||||
},
|
||||
prices: [
|
||||
{
|
||||
currency_code: "usd",
|
||||
amount: 1000,
|
||||
},
|
||||
{
|
||||
region_id: region.id,
|
||||
amount: 1000,
|
||||
},
|
||||
],
|
||||
rules: [shippingOptionRule],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/shipping-options`,
|
||||
shippingOptionPayload,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const shippingOptionId = response.data.shipping_option.id
|
||||
|
||||
const updateShippingOptionPayload = {}
|
||||
|
||||
let err = await api
|
||||
.post(
|
||||
`/admin/shipping-options/${shippingOptionId}`,
|
||||
updateShippingOptionPayload,
|
||||
adminHeaders
|
||||
)
|
||||
.catch((e) => e.response)
|
||||
|
||||
const errorsFields = [
|
||||
{
|
||||
code: "invalid_type",
|
||||
expected: "string",
|
||||
received: "undefined",
|
||||
path: ["id"],
|
||||
message: "Required",
|
||||
},
|
||||
]
|
||||
|
||||
expect(err.status).toEqual(400)
|
||||
expect(err.data).toEqual({
|
||||
type: "invalid_data",
|
||||
message: `Invalid request body: ${JSON.stringify(errorsFields)}`,
|
||||
})
|
||||
})
|
||||
|
||||
it("should update a shipping option successfully", async () => {
|
||||
const shippingOptionPayload = {
|
||||
name: "Test shipping option",
|
||||
@@ -301,7 +241,6 @@ medusaIntegrationTestRunner({
|
||||
(p) => p.currency_code === "eur"
|
||||
)
|
||||
const updateShippingOptionPayload = {
|
||||
id: shippingOptionId,
|
||||
name: "Updated shipping option",
|
||||
provider_id: "manual_test-provider",
|
||||
price_type: "flat",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
AdminShippingOptionDeleteResponse,
|
||||
AdminShippingOptionRetrieveResponse,
|
||||
FulfillmentWorkflow,
|
||||
} from "@medusajs/types"
|
||||
import { AdminUpdateShippingOptionType } from "../validators"
|
||||
import {
|
||||
@@ -21,8 +22,14 @@ export const POST = async (
|
||||
|
||||
const workflow = updateShippingOptionsWorkflow(req.scope)
|
||||
|
||||
const workflowInput: FulfillmentWorkflow.UpdateShippingOptionsWorkflowInput =
|
||||
{
|
||||
id: req.params.id,
|
||||
...shippingOptionPayload,
|
||||
}
|
||||
|
||||
const { result, errors } = await workflow.run({
|
||||
input: [shippingOptionPayload],
|
||||
input: [workflowInput],
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
|
||||
@@ -116,7 +116,6 @@ export type AdminUpdateShippingOptionType = z.infer<
|
||||
>
|
||||
export const AdminUpdateShippingOption = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
name: z.string().optional(),
|
||||
data: z.record(z.unknown()).optional(),
|
||||
price_type: z.nativeEnum(ShippingOptionPriceTypeEnum).optional(),
|
||||
|
||||
Reference in New Issue
Block a user