chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
committed by
GitHub
parent
7a351eef09
commit
4eae25e1ef
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,218 @@
|
||||
import { resolve } from "path"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import {
|
||||
generateCreateFulfillmentData,
|
||||
generateCreateShippingOptionsData,
|
||||
} from "../../__fixtures__"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
const moduleOptions = {
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
options: {
|
||||
config: {
|
||||
"test-provider": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const providerId = "fixtures-fulfillment-provider_test-provider"
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
moduleOptions: moduleOptions,
|
||||
testSuite: ({ service }: SuiteOptions<IFulfillmentModuleService>) => {
|
||||
describe("Fulfillment Module Service", () => {
|
||||
describe("read", () => {
|
||||
it("should list fulfillment", async () => {
|
||||
const shippingProfile = await service.createShippingProfiles({
|
||||
name: "test",
|
||||
type: "default",
|
||||
})
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const shippingOption = await service.createShippingOptions(
|
||||
generateCreateShippingOptionsData({
|
||||
provider_id: providerId,
|
||||
service_zone_id: serviceZone.id,
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
})
|
||||
)
|
||||
|
||||
const fulfillment = await service.createFulfillment(
|
||||
generateCreateFulfillmentData({
|
||||
provider_id: providerId,
|
||||
shipping_option_id: shippingOption.id,
|
||||
})
|
||||
)
|
||||
|
||||
const result = await service.listFulfillments({
|
||||
shipping_option_id: shippingOption.id,
|
||||
})
|
||||
|
||||
expect(result.length).toEqual(1)
|
||||
expect(result[0].id).toEqual(fulfillment.id)
|
||||
})
|
||||
|
||||
it("should retrieve the fulfillment options", async () => {
|
||||
const fulfillmentOptions = await service.retrieveFulfillmentOptions(
|
||||
providerId
|
||||
)
|
||||
|
||||
expect(fulfillmentOptions).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
describe("mutations", () => {
|
||||
describe("on create", () => {
|
||||
it("should create a fulfillment", async () => {
|
||||
const shippingProfile = await service.createShippingProfiles({
|
||||
name: "test",
|
||||
type: "default",
|
||||
})
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const shippingOption = await service.createShippingOptions(
|
||||
generateCreateShippingOptionsData({
|
||||
provider_id: providerId,
|
||||
service_zone_id: serviceZone.id,
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
})
|
||||
)
|
||||
|
||||
const fulfillment = await service.createFulfillment(
|
||||
generateCreateFulfillmentData({
|
||||
provider_id: providerId,
|
||||
shipping_option_id: shippingOption.id,
|
||||
})
|
||||
)
|
||||
|
||||
expect(fulfillment).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
packed_at: null,
|
||||
shipped_at: null,
|
||||
delivered_at: null,
|
||||
canceled_at: null,
|
||||
data: null,
|
||||
provider_id: providerId,
|
||||
shipping_option_id: shippingOption.id,
|
||||
metadata: null,
|
||||
delivery_address: expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
}),
|
||||
items: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
}),
|
||||
],
|
||||
labels: [
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
}),
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("on cancel", () => {
|
||||
let fulfillment
|
||||
|
||||
beforeEach(async () => {
|
||||
const shippingProfile = await service.createShippingProfiles({
|
||||
name: "test",
|
||||
type: "default",
|
||||
})
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const shippingOption = await service.createShippingOptions(
|
||||
generateCreateShippingOptionsData({
|
||||
provider_id: providerId,
|
||||
service_zone_id: serviceZone.id,
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
})
|
||||
)
|
||||
|
||||
fulfillment = await service.createFulfillment(
|
||||
generateCreateFulfillmentData({
|
||||
provider_id: providerId,
|
||||
shipping_option_id: shippingOption.id,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should cancel a fulfillment successfully", async () => {
|
||||
const result = await service.cancelFulfillment(fulfillment.id)
|
||||
// should be idempotent
|
||||
const idempotentResult = await service.cancelFulfillment(
|
||||
fulfillment.id
|
||||
)
|
||||
|
||||
expect(result.canceled_at).not.toBeNull()
|
||||
expect(idempotentResult.canceled_at).not.toBeNull()
|
||||
expect(idempotentResult.canceled_at).toEqual(result.canceled_at)
|
||||
})
|
||||
|
||||
it("should fail to cancel a fulfillment that is already shipped", async () => {
|
||||
await service.updateFulfillment(fulfillment.id, {
|
||||
shipped_at: new Date(),
|
||||
})
|
||||
|
||||
const err = await service
|
||||
.cancelFulfillment(fulfillment.id)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(err.message).toEqual(
|
||||
`Fulfillment with id ${fulfillment.id} already shipped`
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to cancel a fulfillment that is already delivered", async () => {
|
||||
await service.updateFulfillment(fulfillment.id, {
|
||||
delivered_at: new Date(),
|
||||
})
|
||||
|
||||
const err = await service
|
||||
.cancelFulfillment(fulfillment.id)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(err.message).toEqual(
|
||||
`Fulfillment with id ${fulfillment.id} already delivered`
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,282 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreateGeoZoneDTO,
|
||||
IFulfillmentModuleService,
|
||||
UpdateGeoZoneDTO,
|
||||
} from "@medusajs/types"
|
||||
import { GeoZoneType } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
testSuite: ({ service }: SuiteOptions<IFulfillmentModuleService>) => {
|
||||
describe("Fulfillment Module Service", () => {
|
||||
describe("read", () => {
|
||||
it("should list geo zones with a filter", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const createdZone1 = await service.createGeoZones({
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
})
|
||||
const createdZone2 = await service.createGeoZones({
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
})
|
||||
|
||||
let listedZones = await service.listGeoZones({
|
||||
type: createdZone1.type,
|
||||
})
|
||||
|
||||
expect(listedZones).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone1.id }),
|
||||
expect.objectContaining({ id: createdZone2.id }),
|
||||
])
|
||||
)
|
||||
|
||||
listedZones = await service.listGeoZones({
|
||||
country_code: createdZone2.country_code,
|
||||
})
|
||||
|
||||
expect(listedZones).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone2.id }),
|
||||
])
|
||||
)
|
||||
expect(listedZones).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone1.id }),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("mutations", () => {
|
||||
describe("on create", () => {
|
||||
it("should create a new geo zone", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const data: CreateGeoZoneDTO = {
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
}
|
||||
|
||||
const geoZone = await service.createGeoZones(data)
|
||||
|
||||
expect(geoZone).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
type: data.type,
|
||||
country_code: data.country_code,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a collection of geo zones", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const data: CreateGeoZoneDTO[] = [
|
||||
{
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
{
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
},
|
||||
]
|
||||
|
||||
const geoZones = await service.createGeoZones(data)
|
||||
|
||||
expect(geoZones).toHaveLength(2)
|
||||
|
||||
let i = 0
|
||||
for (const data_ of data) {
|
||||
expect(geoZones[i]).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
type: data_.type,
|
||||
country_code: data_.country_code,
|
||||
})
|
||||
)
|
||||
++i
|
||||
}
|
||||
})
|
||||
|
||||
it("should fail to create new geo zones that are not valid", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
let data: CreateGeoZoneDTO = {
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.PROVINCE,
|
||||
country_code: "fr",
|
||||
} as any
|
||||
|
||||
let err = await service.createGeoZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(
|
||||
"Missing required property province_code for geo zone type province"
|
||||
)
|
||||
|
||||
data = {
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.CITY,
|
||||
country_code: "fr",
|
||||
province_code: "test",
|
||||
} as any
|
||||
|
||||
err = await service.createGeoZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(
|
||||
"Missing required property city for geo zone type city"
|
||||
)
|
||||
|
||||
data = {
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.ZIP,
|
||||
postal_expression: "test",
|
||||
} as any
|
||||
|
||||
err = await service.createGeoZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(
|
||||
"Missing required property country_code for geo zone type zip"
|
||||
)
|
||||
|
||||
data = {
|
||||
service_zone_id: serviceZone.id,
|
||||
type: "unknown",
|
||||
postal_expression: "test",
|
||||
} as any
|
||||
|
||||
err = await service.createGeoZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(`Invalid geo zone type: unknown`)
|
||||
})
|
||||
})
|
||||
|
||||
describe("on update", () => {
|
||||
it("should update an existing geo zone", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const createData: CreateGeoZoneDTO = {
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
}
|
||||
|
||||
const createdGeoZone = await service.createGeoZones(createData)
|
||||
|
||||
const updateData: UpdateGeoZoneDTO = {
|
||||
id: createdGeoZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
}
|
||||
|
||||
const updatedGeoZone = await service.updateGeoZones(updateData)
|
||||
|
||||
expect(updatedGeoZone).toEqual(
|
||||
expect.objectContaining({
|
||||
id: updateData.id,
|
||||
type: updateData.type,
|
||||
country_code: updateData.country_code,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a collection of geo zones", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const serviceZone = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
|
||||
const createData: CreateGeoZoneDTO[] = [
|
||||
{
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
{
|
||||
service_zone_id: serviceZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
},
|
||||
]
|
||||
|
||||
const createdGeoZones = await service.createGeoZones(createData)
|
||||
|
||||
const updateData: UpdateGeoZoneDTO[] = createdGeoZones.map(
|
||||
(geoZone, index) => ({
|
||||
id: geoZone.id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: index % 2 === 0 ? "us" : "fr",
|
||||
})
|
||||
)
|
||||
|
||||
const updatedGeoZones = await service.updateGeoZones(updateData)
|
||||
|
||||
expect(updatedGeoZones).toHaveLength(2)
|
||||
|
||||
for (const data_ of updateData) {
|
||||
const expectedGeoZone = updatedGeoZones.find(
|
||||
(geoZone) => geoZone.id === data_.id
|
||||
)
|
||||
expect(expectedGeoZone).toEqual(
|
||||
expect.objectContaining({
|
||||
id: data_.id,
|
||||
type: data_.type,
|
||||
country_code: data_.country_code,
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,264 @@
|
||||
import { Modules, ModulesDefinition } from "@medusajs/modules-sdk"
|
||||
import { FulfillmentSetDTO, IFulfillmentModuleService } from "@medusajs/types"
|
||||
import {
|
||||
initModules,
|
||||
moduleIntegrationTestRunner,
|
||||
SuiteOptions,
|
||||
} from "medusa-test-utils/dist"
|
||||
import { resolve } from "path"
|
||||
import { createFullDataStructure } from "../../__fixtures__"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers"
|
||||
|
||||
let moduleOptions = {
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
options: {
|
||||
config: {
|
||||
"test-provider": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
let providerId = "fixtures-fulfillment-provider_test-provider"
|
||||
|
||||
async function list(
|
||||
service: IFulfillmentModuleService,
|
||||
...args: Parameters<IFulfillmentModuleService["list"]>
|
||||
) {
|
||||
const [filters = {}, config = {}] = args
|
||||
|
||||
const finalConfig = {
|
||||
relations: [
|
||||
"service_zones.geo_zones",
|
||||
"service_zones.shipping_options.shipping_profile",
|
||||
"service_zones.shipping_options.provider",
|
||||
"service_zones.shipping_options.type",
|
||||
"service_zones.shipping_options.rules",
|
||||
"service_zones.shipping_options.fulfillments.labels",
|
||||
"service_zones.shipping_options.fulfillments.items",
|
||||
"service_zones.shipping_options.fulfillments.delivery_address",
|
||||
],
|
||||
...config,
|
||||
}
|
||||
|
||||
return await service.list(filters, finalConfig)
|
||||
}
|
||||
|
||||
function expectSoftDeleted(
|
||||
fulfillmentSets: FulfillmentSetDTO[],
|
||||
{ softDeleted = false } = {}
|
||||
) {
|
||||
expect(fulfillmentSets).toHaveLength(1)
|
||||
|
||||
let fulfillmentSet = fulfillmentSets[0]
|
||||
expect(!!fulfillmentSet.deleted_at).toEqual(softDeleted)
|
||||
expect(fulfillmentSet.service_zones).toHaveLength(1)
|
||||
|
||||
let serviceZone = fulfillmentSet.service_zones[0]
|
||||
expect(!!serviceZone.deleted_at).toEqual(softDeleted)
|
||||
expect(serviceZone.geo_zones).toHaveLength(1)
|
||||
expect(serviceZone.shipping_options).toHaveLength(1)
|
||||
|
||||
let geoZone = serviceZone.geo_zones[0]
|
||||
expect(!!geoZone.deleted_at).toEqual(softDeleted)
|
||||
|
||||
let shippingOption = serviceZone.shipping_options[0]
|
||||
expect(!!shippingOption.deleted_at).toEqual(softDeleted)
|
||||
expect(!!shippingOption.shipping_profile.deleted_at).toEqual(false)
|
||||
expect(!!shippingOption.type.deleted_at).toEqual(softDeleted)
|
||||
expect(shippingOption.fulfillments).toHaveLength(1)
|
||||
expect(shippingOption.rules).toHaveLength(1)
|
||||
|
||||
let rule = shippingOption.rules[0]
|
||||
expect(!!rule.deleted_at).toEqual(softDeleted)
|
||||
|
||||
/**
|
||||
* We do not expect the fulfillment to be soft deleted when soft deleting parents entities
|
||||
*/
|
||||
|
||||
let fulfillment = shippingOption.fulfillments[0]
|
||||
expect(!!fulfillment.deleted_at).toEqual(false)
|
||||
expect(fulfillment.labels).toHaveLength(1)
|
||||
expect(fulfillment.items).toHaveLength(1)
|
||||
|
||||
let label = fulfillment.labels[0]
|
||||
expect(!!label.deleted_at).toEqual(false)
|
||||
|
||||
let item = fulfillment.items[0]
|
||||
expect(!!item.deleted_at).toEqual(false)
|
||||
|
||||
let deliveryAddress = fulfillment.delivery_address
|
||||
expect(!!deliveryAddress.deleted_at).toEqual(false)
|
||||
}
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
moduleOptions,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<IFulfillmentModuleService>) =>
|
||||
describe("Fulfillment Module Service", () => {
|
||||
it("should load and save all the providers on bootstrap with the correct is_enabled value", async () => {
|
||||
const databaseConfig = {
|
||||
schema: "public",
|
||||
clientUrl: MikroOrmWrapper.clientUrl,
|
||||
}
|
||||
|
||||
const providersConfig = {}
|
||||
for (let i = 0; i < 10; i++) {
|
||||
providersConfig[`provider-${i}`] = {}
|
||||
}
|
||||
|
||||
let moduleOptions = {
|
||||
databaseConfig,
|
||||
modulesConfig: {
|
||||
[Modules.FULFILLMENT]: {
|
||||
definition: ModulesDefinition[Modules.FULFILLMENT],
|
||||
options: {
|
||||
databaseConfig,
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
options: {
|
||||
config: providersConfig,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
let { shutdown } = await initModules(moduleOptions)
|
||||
|
||||
let fulfillmentProviders = await MikroOrmWrapper.forkManager().execute(
|
||||
`SELECT * FROM fulfillment_provider`
|
||||
)
|
||||
|
||||
expect(fulfillmentProviders).toHaveLength(
|
||||
Object.keys(providersConfig).length + 1 // +1 for the default provider
|
||||
)
|
||||
|
||||
for (const [name] of Object.entries(providersConfig)) {
|
||||
const provider = fulfillmentProviders.find((p) => {
|
||||
return (
|
||||
p.id ===
|
||||
FulfillmentProviderService.getRegistrationIdentifier(
|
||||
FulfillmentProviderServiceFixtures,
|
||||
name
|
||||
)
|
||||
)
|
||||
})
|
||||
expect(provider).toBeDefined()
|
||||
expect(provider.is_enabled).toBeTruthy()
|
||||
}
|
||||
|
||||
await shutdown()
|
||||
|
||||
const providersConfig2 = {}
|
||||
for (let i = 10; i < 20; i++) {
|
||||
providersConfig2[`provider-${i}`] = {}
|
||||
}
|
||||
|
||||
moduleOptions = {
|
||||
databaseConfig,
|
||||
modulesConfig: {
|
||||
[Modules.FULFILLMENT]: {
|
||||
definition: ModulesDefinition[Modules.FULFILLMENT],
|
||||
options: {
|
||||
databaseConfig,
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
options: {
|
||||
config: providersConfig2,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const medusaApp = await initModules(moduleOptions)
|
||||
shutdown = medusaApp.shutdown
|
||||
|
||||
fulfillmentProviders = await MikroOrmWrapper.forkManager().execute(
|
||||
`SELECT * FROM fulfillment_provider`
|
||||
)
|
||||
|
||||
expect(fulfillmentProviders).toHaveLength(
|
||||
Object.keys(providersConfig2).length +
|
||||
Object.keys(providersConfig).length +
|
||||
1 // +1 for the default provider
|
||||
)
|
||||
|
||||
const allProviders = Object.assign(
|
||||
{},
|
||||
providersConfig,
|
||||
providersConfig2
|
||||
)
|
||||
|
||||
for (const [name] of Object.entries(allProviders)) {
|
||||
const provider = fulfillmentProviders.find((p) => {
|
||||
return (
|
||||
p.id ===
|
||||
FulfillmentProviderService.getRegistrationIdentifier(
|
||||
FulfillmentProviderServiceFixtures,
|
||||
name
|
||||
)
|
||||
)
|
||||
})
|
||||
expect(provider).toBeDefined()
|
||||
|
||||
const isEnabled = !!providersConfig2[name]
|
||||
expect(provider.is_enabled).toEqual(isEnabled)
|
||||
}
|
||||
|
||||
await shutdown().catch(() => void 0)
|
||||
})
|
||||
|
||||
it("should soft delete and restore the data respecting the configured cascade", async () => {
|
||||
await createFullDataStructure(service, { providerId })
|
||||
|
||||
let fulfillmentSets = await list(service)
|
||||
expectSoftDeleted(fulfillmentSets)
|
||||
|
||||
/**
|
||||
* Soft delete the fulfillment set
|
||||
*/
|
||||
|
||||
await service.softDelete(fulfillmentSets[0].id)
|
||||
const deletedFulfillmentSets = await list(
|
||||
service,
|
||||
{},
|
||||
{
|
||||
withDeleted: true,
|
||||
}
|
||||
)
|
||||
expectSoftDeleted(deletedFulfillmentSets, { softDeleted: true })
|
||||
|
||||
/**
|
||||
* Restore the fulfillment set
|
||||
*/
|
||||
|
||||
await service.restore(fulfillmentSets[0].id)
|
||||
const restoredFulfillmentSets = await list(service)
|
||||
expectSoftDeleted(restoredFulfillmentSets)
|
||||
})
|
||||
}),
|
||||
})
|
||||
@@ -0,0 +1,445 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreateServiceZoneDTO,
|
||||
GeoZoneDTO,
|
||||
IFulfillmentModuleService,
|
||||
UpdateServiceZoneDTO,
|
||||
} from "@medusajs/types"
|
||||
import { GeoZoneType } from "@medusajs/utils"
|
||||
import { SuiteOptions, moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
testSuite: ({ service }: SuiteOptions<IFulfillmentModuleService>) => {
|
||||
describe("Fulfillment Module Service", () => {
|
||||
describe("read", () => {
|
||||
it("should list service zones with a filter", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const createdZone1 = await service.createServiceZones({
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
})
|
||||
const createdZone2 = await service.createServiceZones({
|
||||
name: "test2",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
let listedZones = await service.listServiceZones({
|
||||
name: createdZone2.name,
|
||||
})
|
||||
|
||||
expect(listedZones).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone2.id }),
|
||||
])
|
||||
)
|
||||
expect(listedZones).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone1.id }),
|
||||
])
|
||||
)
|
||||
|
||||
listedZones = await service.listServiceZones({
|
||||
geo_zones: { country_code: "fr" },
|
||||
})
|
||||
|
||||
expect(listedZones).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone2.id }),
|
||||
])
|
||||
)
|
||||
expect(listedZones).not.toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ id: createdZone1.id }),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("mutations", () => {
|
||||
describe("on create", () => {
|
||||
it("should create a new service zone", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const data: CreateServiceZoneDTO = {
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const serviceZone = await service.createServiceZones(data)
|
||||
|
||||
expect(serviceZone).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: data.name,
|
||||
geo_zones: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type: (data.geo_zones![0] as GeoZoneDTO).type,
|
||||
country_code: (data.geo_zones![0] as GeoZoneDTO)
|
||||
.country_code,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a collection of service zones", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const data: CreateServiceZoneDTO[] = [
|
||||
{
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "test3",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "uk",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const serviceZones = await service.createServiceZones(data)
|
||||
|
||||
expect(serviceZones).toHaveLength(3)
|
||||
|
||||
let i = 0
|
||||
for (const data_ of data) {
|
||||
expect(serviceZones[i]).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: data_.name,
|
||||
geo_zones: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type: (data_.geo_zones![0] as GeoZoneDTO).type,
|
||||
country_code: (data_.geo_zones![0] as GeoZoneDTO)
|
||||
.country_code,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
++i
|
||||
}
|
||||
})
|
||||
|
||||
it("should fail on duplicated service zone name", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const data: CreateServiceZoneDTO = {
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
await service.createServiceZones(data)
|
||||
const err = await service.createServiceZones(data).catch((e) => e)
|
||||
|
||||
expect(err).toBeDefined()
|
||||
expect(err.message).toContain("exists")
|
||||
})
|
||||
|
||||
it("should fail on creating a service zone and new geo zones that are not valid", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
let data: CreateServiceZoneDTO = {
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.PROVINCE,
|
||||
country_code: "fr",
|
||||
} as any,
|
||||
],
|
||||
}
|
||||
|
||||
let err = await service.createServiceZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(
|
||||
"Missing required property province_code for geo zone type province"
|
||||
)
|
||||
|
||||
data = {
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.CITY,
|
||||
country_code: "fr",
|
||||
province_code: "test",
|
||||
} as any,
|
||||
],
|
||||
}
|
||||
|
||||
err = await service.createServiceZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(
|
||||
"Missing required property city for geo zone type city"
|
||||
)
|
||||
|
||||
data = {
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.ZIP,
|
||||
postal_expression: "test",
|
||||
} as any,
|
||||
],
|
||||
}
|
||||
|
||||
err = await service.createServiceZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(
|
||||
"Missing required property country_code for geo zone type zip"
|
||||
)
|
||||
|
||||
data = {
|
||||
name: "test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: "unknown",
|
||||
postal_expression: "test",
|
||||
} as any,
|
||||
],
|
||||
}
|
||||
|
||||
err = await service.createServiceZones(data).catch((e) => e)
|
||||
expect(err.message).toBe(`Invalid geo zone type: unknown`)
|
||||
})
|
||||
})
|
||||
|
||||
describe("on update", () => {
|
||||
it("should update an existing service zone", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const createData: CreateServiceZoneDTO = {
|
||||
name: "service-zone-test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const createdServiceZone = await service.createServiceZones(
|
||||
createData
|
||||
)
|
||||
|
||||
const updateData = {
|
||||
name: "updated-service-zone-test",
|
||||
geo_zones: [
|
||||
{
|
||||
id: createdServiceZone.geo_zones[0].id,
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const updatedServiceZone = await service.updateServiceZones(
|
||||
createdServiceZone.id,
|
||||
updateData
|
||||
)
|
||||
|
||||
expect(updatedServiceZone).toEqual(
|
||||
expect.objectContaining({
|
||||
id: createdServiceZone.id,
|
||||
name: updateData.name,
|
||||
geo_zones: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: updateData.geo_zones[0].id,
|
||||
type: updateData.geo_zones[0].type,
|
||||
country_code: updateData.geo_zones[0].country_code,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail on duplicated service zone name", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const createData: CreateServiceZoneDTO[] = [
|
||||
{
|
||||
name: "service-zone-test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "service-zone-test2",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const createdServiceZones = await service.createServiceZones(
|
||||
createData
|
||||
)
|
||||
|
||||
const updateData: UpdateServiceZoneDTO = {
|
||||
name: "service-zone-test",
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const err = await service
|
||||
.updateServiceZones(createdServiceZones[1].id, updateData)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(err).toBeDefined()
|
||||
expect(err.message).toContain("exists")
|
||||
})
|
||||
})
|
||||
|
||||
describe("on upsert", () => {
|
||||
it("should upsert a collection of service zones", async function () {
|
||||
const fulfillmentSet = await service.create({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
})
|
||||
|
||||
const createData: CreateServiceZoneDTO[] = [
|
||||
{
|
||||
name: "service-zone-test",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "fr",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "service-zone-test2",
|
||||
fulfillment_set_id: fulfillmentSet.id,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: "us",
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const createdServiceZones = await service.createServiceZones(
|
||||
createData
|
||||
)
|
||||
|
||||
const updateData: UpdateServiceZoneDTO[] = createdServiceZones.map(
|
||||
(serviceZone, index) => ({
|
||||
id: serviceZone.id,
|
||||
name: `updated-service-zone-test${index + 1}`,
|
||||
geo_zones: [
|
||||
{
|
||||
type: GeoZoneType.COUNTRY,
|
||||
country_code: index % 2 === 0 ? "us" : "fr",
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
|
||||
const updatedServiceZones = await service.upsertServiceZones(
|
||||
updateData
|
||||
)
|
||||
|
||||
expect(updatedServiceZones).toHaveLength(2)
|
||||
|
||||
for (const data_ of updateData) {
|
||||
const expectedServiceZone = updatedServiceZones.find(
|
||||
(serviceZone) => serviceZone.id === data_.id
|
||||
)
|
||||
expect(expectedServiceZone).toEqual(
|
||||
expect.objectContaining({
|
||||
id: data_.id,
|
||||
name: data_.name,
|
||||
geo_zones: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type: (data_.geo_zones![0] as GeoZoneDTO).type,
|
||||
country_code: (data_.geo_zones![0] as GeoZoneDTO)
|
||||
.country_code,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,82 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreateShippingProfileDTO,
|
||||
IFulfillmentModuleService,
|
||||
} from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
testSuite: ({ service }: SuiteOptions<IFulfillmentModuleService>) => {
|
||||
describe("Fulfillment Module Service", () => {
|
||||
describe("mutations", () => {
|
||||
describe("on create", () => {
|
||||
it("should create a new shipping profile", async function () {
|
||||
const createData: CreateShippingProfileDTO = {
|
||||
name: "test-default-profile",
|
||||
type: "default",
|
||||
}
|
||||
|
||||
const createdShippingProfile = await service.createShippingProfiles(
|
||||
createData
|
||||
)
|
||||
|
||||
expect(createdShippingProfile).toEqual(
|
||||
expect.objectContaining({
|
||||
name: createData.name,
|
||||
type: createData.type,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create multiple new shipping profiles", async function () {
|
||||
const createData: CreateShippingProfileDTO[] = [
|
||||
{
|
||||
name: "test-profile-1",
|
||||
type: "default",
|
||||
},
|
||||
{
|
||||
name: "test-profile-2",
|
||||
type: "custom",
|
||||
},
|
||||
]
|
||||
|
||||
const createdShippingProfiles =
|
||||
await service.createShippingProfiles(createData)
|
||||
|
||||
expect(createdShippingProfiles).toHaveLength(2)
|
||||
|
||||
let i = 0
|
||||
for (const data_ of createData) {
|
||||
expect(createdShippingProfiles[i]).toEqual(
|
||||
expect.objectContaining({
|
||||
name: data_.name,
|
||||
type: data_.type,
|
||||
})
|
||||
)
|
||||
++i
|
||||
}
|
||||
})
|
||||
|
||||
it("should fail on duplicated shipping profile name", async function () {
|
||||
const createData: CreateShippingProfileDTO = {
|
||||
name: "test-default-profile",
|
||||
type: "default",
|
||||
}
|
||||
|
||||
await service.createShippingProfiles(createData)
|
||||
|
||||
const err = await service
|
||||
.createShippingProfiles(createData)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(err).toBeDefined()
|
||||
expect(err.message).toContain("exists")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user