feat(types,fulfillment): ability to delete a canceled fulfillment (#10602)
This commit is contained in:
1 parent
7c773fc108
commit
90ad2566fd
4 files changed
+103
-2
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/fulfillment": patch
|
||||||
|
"@medusajs/types": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(types,fulfillment): ability to delete a canceled fulfillment
|
||||||
@@ -2459,6 +2459,18 @@ export interface IFulfillmentModuleService extends IModuleService {
|
|||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<FulfillmentDTO>
|
): Promise<FulfillmentDTO>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method deletes fulfillment by IDs after cancelation.
|
||||||
|
*
|
||||||
|
* @param {string} id - The ID of the fulfillment.
|
||||||
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
|
* @returns {Promise<void>} Resolves when the fulfillment set is deleted successfully.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* await fulfillmentModuleService.deleteFulfillment("ful_123")
|
||||||
|
*/
|
||||||
|
deleteFulfillment(id: string, sharedContext?: Context): Promise<void>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates a fulfillment and call the provider to create a return.
|
* This method creates a fulfillment and call the provider to create a return.
|
||||||
*
|
*
|
||||||
|
|||||||
+63
-2
@@ -1,18 +1,18 @@
|
|||||||
import { resolve } from "path"
|
|
||||||
import {
|
import {
|
||||||
IFulfillmentModuleService,
|
IFulfillmentModuleService,
|
||||||
UpdateFulfillmentDTO,
|
UpdateFulfillmentDTO,
|
||||||
} from "@medusajs/framework/types"
|
} from "@medusajs/framework/types"
|
||||||
|
import { FulfillmentEvents, Modules } from "@medusajs/framework/utils"
|
||||||
import {
|
import {
|
||||||
MockEventBusService,
|
MockEventBusService,
|
||||||
moduleIntegrationTestRunner,
|
moduleIntegrationTestRunner,
|
||||||
} from "@medusajs/test-utils"
|
} from "@medusajs/test-utils"
|
||||||
|
import { resolve } from "path"
|
||||||
import {
|
import {
|
||||||
buildExpectedEventMessageShape,
|
buildExpectedEventMessageShape,
|
||||||
generateCreateFulfillmentData,
|
generateCreateFulfillmentData,
|
||||||
generateCreateShippingOptionsData,
|
generateCreateShippingOptionsData,
|
||||||
} from "../../__fixtures__"
|
} from "../../__fixtures__"
|
||||||
import { FulfillmentEvents, Modules } from "@medusajs/framework/utils"
|
|
||||||
|
|
||||||
jest.setTimeout(100000)
|
jest.setTimeout(100000)
|
||||||
|
|
||||||
@@ -509,6 +509,67 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("on delete", () => {
|
||||||
|
let fulfillment
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const shippingProfile = await service.createShippingProfiles({
|
||||||
|
name: "test",
|
||||||
|
type: "default",
|
||||||
|
})
|
||||||
|
|
||||||
|
const fulfillmentSet = await service.createFulfillmentSets({
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should delete a canceled fulfillment successfully", async () => {
|
||||||
|
await service.cancelFulfillment(fulfillment.id)
|
||||||
|
await service.deleteFulfillment(fulfillment.id)
|
||||||
|
|
||||||
|
const retrieveError = await service
|
||||||
|
.retrieveFulfillment(fulfillment.id)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(retrieveError.message).toEqual(
|
||||||
|
`Fulfillment with id: ${fulfillment.id} was not found`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should fail to delete an uncanceled fulfillment", async () => {
|
||||||
|
const deleteError = await service
|
||||||
|
.deleteFulfillment(fulfillment.id)
|
||||||
|
.catch((e) => e)
|
||||||
|
|
||||||
|
expect(deleteError.message).toEqual(
|
||||||
|
`Fulfillment with id ${fulfillment.id} needs to be canceled first before deleting`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -653,6 +653,28 @@ export default class FulfillmentModuleService
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@InjectManager()
|
||||||
|
@EmitEvents()
|
||||||
|
async deleteFulfillment(
|
||||||
|
id: string,
|
||||||
|
@MedusaContext() sharedContext: Context = {}
|
||||||
|
): Promise<void> {
|
||||||
|
const fulfillment = await this.fulfillmentService_.retrieve(
|
||||||
|
id,
|
||||||
|
{},
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!isPresent(fulfillment.canceled_at)) {
|
||||||
|
throw new MedusaError(
|
||||||
|
MedusaError.Types.INVALID_DATA,
|
||||||
|
`Fulfillment with id ${fulfillment.id} needs to be canceled first before deleting`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.fulfillmentService_.delete(id, sharedContext)
|
||||||
|
}
|
||||||
|
|
||||||
@InjectManager()
|
@InjectManager()
|
||||||
@EmitEvents()
|
@EmitEvents()
|
||||||
async createReturnFulfillment(
|
async createReturnFulfillment(
|
||||||
|
|||||||
Reference in new issue
Block a user