fix(medusa): Shipping profile CRUD (#3154)
**What** - Fixes wrong payload class for `POST /admin/shipping-profiles` - Fixes wrong payload class for `POST /admin/shipping-profiles/:id` - Fixes an issue where updating a shipping profile with products and/or shipping options would fail. - Fixes an issue where passing `profile_id` to `ShippingOptionService.update()` would not update the shipping profile of the option. **Testing** - Adds new `simpleshippingProfileFactory` - Adds new integration test suite for shipping profiles operations. Resolves CORE-1065
This commit is contained in:
+2
@@ -10,6 +10,7 @@ describe("POST /admin/shipping-profiles", () => {
|
||||
subject = await request("POST", "/admin/shipping-profiles", {
|
||||
payload: {
|
||||
name: "Test Profile",
|
||||
type: "default",
|
||||
},
|
||||
adminSession: {
|
||||
jwt: {
|
||||
@@ -27,6 +28,7 @@ describe("POST /admin/shipping-profiles", () => {
|
||||
expect(ShippingProfileServiceMock.create).toHaveBeenCalledTimes(1)
|
||||
expect(ShippingProfileServiceMock.create).toHaveBeenCalledWith({
|
||||
name: "Test Profile",
|
||||
type: "default",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IsString } from "class-validator"
|
||||
import { IsEnum, IsObject, IsOptional, IsString } from "class-validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { ShippingProfileType } from "../../../../models"
|
||||
import { ShippingProfileService } from "../../../../services"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /shipping-profiles
|
||||
@@ -84,12 +85,26 @@ export default async (req, res) => {
|
||||
* type: object
|
||||
* required:
|
||||
* - name
|
||||
* - type
|
||||
* properties:
|
||||
* name:
|
||||
* description: "The name of the Shipping Profile"
|
||||
* description: The name of the Shipping Profile
|
||||
* type: string
|
||||
* type:
|
||||
* description: The type of the Shipping Profile
|
||||
* type: string
|
||||
* enum: [default, gift_card, custom]
|
||||
*/
|
||||
export class AdminPostShippingProfilesReq {
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@IsEnum(ShippingProfileType, {
|
||||
message: "type must be one of 'default', 'custom', 'gift_card'",
|
||||
})
|
||||
type: ShippingProfileType
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
import {
|
||||
IsArray,
|
||||
IsEnum,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from "class-validator"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { ShippingProfileType } from "../../../../models"
|
||||
import { ShippingProfileService } from "../../../../services"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
|
||||
/**
|
||||
* @oas [post] /shipping-profiles/{id}
|
||||
@@ -93,11 +100,44 @@ export default async (req, res) => {
|
||||
* type: object
|
||||
* properties:
|
||||
* name:
|
||||
* description: "The name of the Shipping Profile"
|
||||
* description: The name of the Shipping Profile
|
||||
* type: string
|
||||
* metadata:
|
||||
* description: An optional set of key-value pairs with additional information.
|
||||
* type: object
|
||||
* type:
|
||||
* description: The type of the Shipping Profile
|
||||
* type: string
|
||||
* enum: [default, gift_card, custom]
|
||||
* products:
|
||||
* description: An optional array of product ids to associate with the Shipping Profile
|
||||
* type: array
|
||||
* shipping_options:
|
||||
* description: An optional array of shipping option ids to associate with the Shipping Profile
|
||||
* type: array
|
||||
*/
|
||||
export class AdminPostShippingProfilesProfileReq {
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
name?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
@IsOptional()
|
||||
@IsEnum(ShippingProfileType, {
|
||||
message: "type must be one of 'default', 'custom', 'gift_card'",
|
||||
})
|
||||
type?: ShippingProfileType
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
products?: string[]
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
shipping_options?: string[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user