fix: Shipping profile deletion with options (#8910)
* fix(fulfillment): Prevent deletion of profiles associated to options * add tests * typo * address feedback
This commit is contained in:
+91
-1
@@ -6,13 +6,37 @@ import {
|
||||
MockEventBusService,
|
||||
moduleIntegrationTestRunner,
|
||||
} from "medusa-test-utils"
|
||||
import { buildExpectedEventMessageShape } from "../../__fixtures__"
|
||||
import {
|
||||
buildExpectedEventMessageShape,
|
||||
generateCreateShippingOptionsData,
|
||||
} from "../../__fixtures__"
|
||||
import { FulfillmentEvents, Modules } from "@medusajs/utils"
|
||||
import { resolve } from "path"
|
||||
import { FulfillmentProviderService } from "@services"
|
||||
import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
const moduleOptions = {
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
id: "test-provider",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const providerId = FulfillmentProviderService.getRegistrationIdentifier(
|
||||
FulfillmentProviderServiceFixtures,
|
||||
"test-provider"
|
||||
)
|
||||
|
||||
moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
moduleOptions,
|
||||
testSuite: ({ service }) => {
|
||||
let eventBusEmitSpy
|
||||
|
||||
@@ -121,6 +145,72 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
expect(err.message).toContain("exists")
|
||||
})
|
||||
})
|
||||
|
||||
describe("on delete", () => {
|
||||
it("should delete a shipping profile", async function () {
|
||||
const createData: CreateShippingProfileDTO = {
|
||||
name: "test-default-profile",
|
||||
type: "default",
|
||||
}
|
||||
|
||||
const createdShippingProfile = await service.createShippingProfiles(
|
||||
createData
|
||||
)
|
||||
|
||||
await service.deleteShippingProfiles(createdShippingProfile.id)
|
||||
|
||||
const [shippingProfile] = await service.listShippingProfiles({
|
||||
id: createdShippingProfile.id,
|
||||
})
|
||||
|
||||
expect(shippingProfile).toBeUndefined()
|
||||
})
|
||||
|
||||
it("should not allow to delete a shipping profile that is associated to any shipping options", async function () {
|
||||
const createData: CreateShippingProfileDTO = {
|
||||
name: "test-default-profile",
|
||||
type: "default",
|
||||
}
|
||||
|
||||
const createdShippingProfile = await service.createShippingProfiles(
|
||||
createData
|
||||
)
|
||||
|
||||
const fulfillmentSet = await service.createFulfillmentSets({
|
||||
name: "test",
|
||||
type: "test-type",
|
||||
service_zones: [
|
||||
{
|
||||
name: "test",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await service.createShippingOptions([
|
||||
generateCreateShippingOptionsData({
|
||||
service_zone_id: fulfillmentSet.service_zones[0].id,
|
||||
shipping_profile_id: createdShippingProfile.id,
|
||||
provider_id: providerId,
|
||||
rules: [
|
||||
{
|
||||
attribute: "test-attribute",
|
||||
operator: "in",
|
||||
value: ["test"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
|
||||
const err = await service
|
||||
.deleteShippingProfiles(createdShippingProfile.id)
|
||||
.catch((e) => e)
|
||||
|
||||
expect(err).toBeTruthy()
|
||||
expect(err.message).toContain(
|
||||
`Cannot delete Shipping Profiles ${createdShippingProfile.id} with associated Shipping Options. Delete Shipping Options first and try again.`
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user