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:
@@ -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", () => {
|
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 () => {
|
it("should update a shipping option successfully", async () => {
|
||||||
const shippingOptionPayload = {
|
const shippingOptionPayload = {
|
||||||
name: "Test shipping option",
|
name: "Test shipping option",
|
||||||
@@ -301,7 +241,6 @@ medusaIntegrationTestRunner({
|
|||||||
(p) => p.currency_code === "eur"
|
(p) => p.currency_code === "eur"
|
||||||
)
|
)
|
||||||
const updateShippingOptionPayload = {
|
const updateShippingOptionPayload = {
|
||||||
id: shippingOptionId,
|
|
||||||
name: "Updated shipping option",
|
name: "Updated shipping option",
|
||||||
provider_id: "manual_test-provider",
|
provider_id: "manual_test-provider",
|
||||||
price_type: "flat",
|
price_type: "flat",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
AdminShippingOptionDeleteResponse,
|
AdminShippingOptionDeleteResponse,
|
||||||
AdminShippingOptionRetrieveResponse,
|
AdminShippingOptionRetrieveResponse,
|
||||||
|
FulfillmentWorkflow,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { AdminUpdateShippingOptionType } from "../validators"
|
import { AdminUpdateShippingOptionType } from "../validators"
|
||||||
import {
|
import {
|
||||||
@@ -21,8 +22,14 @@ export const POST = async (
|
|||||||
|
|
||||||
const workflow = updateShippingOptionsWorkflow(req.scope)
|
const workflow = updateShippingOptionsWorkflow(req.scope)
|
||||||
|
|
||||||
|
const workflowInput: FulfillmentWorkflow.UpdateShippingOptionsWorkflowInput =
|
||||||
|
{
|
||||||
|
id: req.params.id,
|
||||||
|
...shippingOptionPayload,
|
||||||
|
}
|
||||||
|
|
||||||
const { result, errors } = await workflow.run({
|
const { result, errors } = await workflow.run({
|
||||||
input: [shippingOptionPayload],
|
input: [workflowInput],
|
||||||
throwOnError: false,
|
throwOnError: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ export type AdminUpdateShippingOptionType = z.infer<
|
|||||||
>
|
>
|
||||||
export const AdminUpdateShippingOption = z
|
export const AdminUpdateShippingOption = z
|
||||||
.object({
|
.object({
|
||||||
id: z.string(),
|
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
data: z.record(z.unknown()).optional(),
|
data: z.record(z.unknown()).optional(),
|
||||||
price_type: z.nativeEnum(ShippingOptionPriceTypeEnum).optional(),
|
price_type: z.nativeEnum(ShippingOptionPriceTypeEnum).optional(),
|
||||||
|
|||||||
Reference in New Issue
Block a user