Files
Zumri-Backend/tests/unit/catalogue.service.test.js
Sathira Sri Sathara 5643d89236 feat: implement business pricing service and money utilities
- Added `businessPricing.service.js` to handle business customer pricing logic.
- Introduced `money.js` for money parsing, formatting, and calculations.
- Created `pricing.service.js` to manage variant quoting and promotion application.
- Updated validation schemas in `catalogue.schemas.js` and `inventoryMerchandising.schemas.js` for new pricing and inventory features.
- Implemented cron job for inventory reservation expiry in `inventoryReservationExpiry.cron.js`.
- Created database migrations for catalogue and inventory structures.
- Added unit tests for catalogue localization, validation, and inventory merchandising functionalities.
2026-09-03 19:25:13 +05:30

8 lines
1.5 KiB
JavaScript

describe("catalogue hierarchy and publication rules",()=>{beforeEach(()=>jest.resetModules());
const setup=(nodes={})=>{const models={Category:{findByPk:jest.fn(async id=>nodes[id]||null)},ProductTranslation:{findOne:jest.fn()},ProductVariant:{findOne:jest.fn()},ProductMedia:{findOne:jest.fn()}};jest.doMock("../../app/models",()=>models);return{service:require("../../app/services/catalogue/catalogue.service"),models};};
test("blocks self-parent",async()=>{const {service}=setup();await expect(service.assertCategoryParent("a","a",{})).rejects.toMatchObject({code:"CATEGORY_SELF_PARENT"});});
test("blocks category cycle",async()=>{const {service}=setup({b:{id:"b",parent_id:"a"}});await expect(service.assertCategoryParent("a","b",{})).rejects.toMatchObject({code:"CATEGORY_CYCLE"});});
test("accepts valid hierarchy",async()=>{const {service}=setup({b:{id:"b",parent_id:null}});await expect(service.assertCategoryParent("a","b",{})).resolves.toBeUndefined();});
test("publish requires English translation, variant, and primary media",async()=>{const {service,models}=setup();models.ProductTranslation.findOne.mockResolvedValue(null);await expect(service.validatePublish({id:"p",slug:"p",brand_id:"b"},{})).rejects.toMatchObject({code:"PUBLISH_REQUIREMENTS_NOT_MET"});models.ProductTranslation.findOne.mockResolvedValue({});models.ProductVariant.findOne.mockResolvedValue({});models.ProductMedia.findOne.mockResolvedValue({});await expect(service.validatePublish({id:"p",slug:"p",brand_id:"b"},{})).resolves.toBeUndefined();});
});