chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { EventBusTypes } from "@medusajs/types"
|
||||
|
||||
export function buildExpectedEventMessageShape(options: {
|
||||
eventName: string
|
||||
action: string
|
||||
object: string
|
||||
eventGroupId?: string
|
||||
data: any
|
||||
options?: Record<string, unknown>
|
||||
}): EventBusTypes.Message {
|
||||
return {
|
||||
eventName: options.eventName,
|
||||
body: {
|
||||
metadata: {
|
||||
action: options.action,
|
||||
eventGroupId: options.eventGroupId,
|
||||
service: "fulfillment",
|
||||
object: options.object,
|
||||
},
|
||||
data: options.data,
|
||||
},
|
||||
options: options.options,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { CreateFulfillmentDTO } from "@medusajs/types"
|
||||
|
||||
export function generateCreateFulfillmentData(
|
||||
data: Partial<CreateFulfillmentDTO> & {
|
||||
provider_id: string
|
||||
shipping_option_id: string
|
||||
}
|
||||
) {
|
||||
const randomString = Math.random().toString(36).substring(7)
|
||||
|
||||
return {
|
||||
location_id: "test-location",
|
||||
packed_at: null,
|
||||
shipped_at: null,
|
||||
delivered_at: null,
|
||||
canceled_at: null,
|
||||
data: null,
|
||||
provider_id: data.provider_id,
|
||||
shipping_option_id: data.shipping_option_id,
|
||||
metadata: data.metadata ?? null,
|
||||
delivery_address: data.delivery_address ?? {
|
||||
address_1: "test-address_" + randomString,
|
||||
address_2: "test-address_" + randomString,
|
||||
city: "test-city_" + randomString,
|
||||
postal_code: "test-postal-code_" + randomString,
|
||||
country_code: "test-country-code_" + randomString,
|
||||
province: "test-province_" + randomString,
|
||||
phone: "test-phone_" + randomString,
|
||||
full_name: "test-full-name_" + randomString,
|
||||
},
|
||||
items: data.items ?? [
|
||||
{
|
||||
title: "test-title_" + randomString,
|
||||
sku: "test-sku_" + randomString,
|
||||
quantity: 1,
|
||||
barcode: "test-barcode_" + randomString,
|
||||
},
|
||||
],
|
||||
labels: data.labels ?? [
|
||||
{
|
||||
tracking_number: "test-tracking-number_" + randomString,
|
||||
tracking_url: "test-tracking-url_" + randomString,
|
||||
label_url: "test-label-url_" + randomString,
|
||||
},
|
||||
],
|
||||
order: data.order ?? {},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { generateCreateShippingOptionsData } from "./shipping-options"
|
||||
import { generateCreateFulfillmentData } from "./fulfillment"
|
||||
import { IFulfillmentModuleService } from "@medusajs/types"
|
||||
|
||||
export * from "./shipping-options"
|
||||
export * from "./fulfillment"
|
||||
export * from "./events"
|
||||
|
||||
export async function createFullDataStructure(
|
||||
service: IFulfillmentModuleService,
|
||||
{
|
||||
providerId,
|
||||
}: {
|
||||
providerId: string
|
||||
}
|
||||
) {
|
||||
const randomString = Math.random().toString(36).substring(7)
|
||||
|
||||
const shippingProfile = await service.createShippingProfiles({
|
||||
// generate random string
|
||||
name: "test_" + randomString,
|
||||
type: "default",
|
||||
})
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test_" + randomString,
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test_" + randomString,
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: "country",
|
||||
country_code: "US_" + randomString,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const shippingOption = await service.createShippingOptions(
|
||||
generateCreateShippingOptionsData({
|
||||
provider_id: providerId,
|
||||
service_zone_id: serviceZone.id,
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
})
|
||||
)
|
||||
|
||||
await service.createFulfillment(
|
||||
generateCreateFulfillmentData({
|
||||
provider_id: providerId,
|
||||
shipping_option_id: shippingOption.id,
|
||||
})
|
||||
)
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { AbstractFulfillmentProviderService } from "@medusajs/utils/src"
|
||||
|
||||
export class FulfillmentProviderServiceFixtures extends AbstractFulfillmentProviderService {
|
||||
static identifier = "fixtures-fulfillment-provider"
|
||||
|
||||
async createFulfillment(data, items, order, fulfillment): Promise<any> {
|
||||
return {}
|
||||
}
|
||||
|
||||
async cancelFulfillment(fulfillment): Promise<any> {
|
||||
return {}
|
||||
}
|
||||
|
||||
async getFulfillmentOptions(): Promise<any> {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export const services = [FulfillmentProviderServiceFixtures]
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./default-provider"
|
||||
@@ -0,0 +1,41 @@
|
||||
import { CreateShippingOptionDTO } from "@medusajs/types"
|
||||
|
||||
export function generateCreateShippingOptionsData({
|
||||
name,
|
||||
service_zone_id,
|
||||
shipping_profile_id,
|
||||
provider_id,
|
||||
price_type,
|
||||
rules,
|
||||
type,
|
||||
data,
|
||||
}: Omit<CreateShippingOptionDTO, "name" | "price_type" | "type"> & {
|
||||
price_type?: CreateShippingOptionDTO["price_type"]
|
||||
name?: string
|
||||
type?: CreateShippingOptionDTO["type"]
|
||||
}): Required<CreateShippingOptionDTO> {
|
||||
const randomString = Math.random().toString(36).substring(7)
|
||||
|
||||
return {
|
||||
service_zone_id: service_zone_id,
|
||||
shipping_profile_id: shipping_profile_id,
|
||||
provider_id: provider_id,
|
||||
type: type ?? {
|
||||
code: "test-type_" + randomString,
|
||||
description: "test-description_" + randomString,
|
||||
label: "test-label_" + randomString,
|
||||
},
|
||||
data: data ?? {
|
||||
amount: 1000,
|
||||
},
|
||||
name: name ?? Math.random().toString(36).substring(7),
|
||||
price_type: price_type ?? "flat",
|
||||
rules: rules ?? [
|
||||
{
|
||||
attribute: "weight",
|
||||
operator: "eq",
|
||||
value: "test",
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user