diff --git a/integration-tests/tests/fixtures/components.ts b/integration-tests/tests/fixtures/components.ts index 22dee7df..a8a0ef06 100644 --- a/integration-tests/tests/fixtures/components.ts +++ b/integration-tests/tests/fixtures/components.ts @@ -1,6 +1,7 @@ import { MedusaMiddleware, MedusaRequest, Middleware, Module, Router, Service } from 'medusa-extender'; import { default as MedusaCartService } from '@medusajs/medusa/dist/services/cart'; import { Response, Request, NextFunction } from 'express'; +import { Cart } from "@medusajs/medusa/dist/models/cart"; @Service() export class TestService { @@ -12,6 +13,10 @@ export class CartService extends MedusaCartService { static resolutionKey = 'cartService'; customMethod = jest.fn(); + + removeLineItem(cartId: string, lineItemId: string): Promise { + return Promise.resolve({ id: "cart_dafsdgfds" } as Cart) + } } @Router({ @@ -208,7 +213,7 @@ CustomTopTestPathMiddleware.prototype.consume = jest StoreRouter, StoreTestPathMiddleware, CustomTopRouter, - CustomTopTestPathMiddleware + CustomTopTestPathMiddleware, ], }) export class TestModule {} diff --git a/integration-tests/tests/integration.spec.ts b/integration-tests/tests/integration.spec.ts index 143df318..574dd060 100644 --- a/integration-tests/tests/integration.spec.ts +++ b/integration-tests/tests/integration.spec.ts @@ -103,6 +103,18 @@ describe('Medusa-extender', () => { expect(cartService.customMethod).toHaveBeenCalled(); }); + + it('should load overridden service components and override parent method', async () => { + const cartService: CartService = context.container.resolve(CartService.resolutionKey); + + const cart = await cartService.removeLineItem("1", "1"); + + expect(cart).toEqual( + expect.objectContaining({ + id: "cart_dafsdgfds" + }) + ); + }); }); describe('admin api loader', () => {