Skip to content

Commit

Permalink
test(integration): Add a new test case to validate method overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Jun 29, 2022
1 parent ffa0c49 commit fca67d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion integration-tests/tests/fixtures/components.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -12,6 +13,10 @@ export class CartService extends MedusaCartService {
static resolutionKey = 'cartService';

customMethod = jest.fn();

removeLineItem(cartId: string, lineItemId: string): Promise<Cart> {
return Promise.resolve({ id: "cart_dafsdgfds" } as Cart)
}
}

@Router({
Expand Down Expand Up @@ -208,7 +213,7 @@ CustomTopTestPathMiddleware.prototype.consume = jest
StoreRouter,
StoreTestPathMiddleware,
CustomTopRouter,
CustomTopTestPathMiddleware
CustomTopTestPathMiddleware,
],
})
export class TestModule {}
12 changes: 12 additions & 0 deletions integration-tests/tests/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit fca67d1

Please sign in to comment.