1 import { CreateShippingOptionDTO } from "@medusajs/framework/types"
2
3 export function generateCreateShippingOptionsData({
4 name,
5 service_zone_id,
6 shipping_profile_id,
7 provider_id,
8 price_type,
9 rules,
10 type,
11 data,
12 }: Omit<CreateShippingOptionDTO, "name" | "price_type" | "type"> & {
13 price_type?: CreateShippingOptionDTO["price_type"]
14 name?: string
15 type?: CreateShippingOptionDTO["type"]
16 }): Required<CreateShippingOptionDTO> {
17 const randomString = Math.random().toString(36).substring(7)
18
19 return {
20 service_zone_id: service_zone_id,
21 shipping_profile_id: shipping_profile_id,
22 provider_id: provider_id,
23 type: type ?? {
24 code: "test-type_" + randomString,
25 description: "test-description_" + randomString,
26 label: "test-label_" + randomString,
27 },
28 data: data ?? {
29 amount: 1000,
30 },
31 name: name ?? Math.random().toString(36).substring(7),
32 price_type: price_type ?? "flat",
33 rules: rules ?? [
34 {
35 attribute: "weight",
36 operator: "eq",
37 value: "test",
38 },
39 ],
40 }
41 }