import { beforeEach, describe, expect, it, vi } from 'vitest'; vi.mock('../src/services/notificationService', () => ({ notifyRoleUsers: vi.fn(async () => true), })); vi.mock('../src/services/orderZeroPriceGuard', () => ({ listZeroPriceItems: vi.fn(async () => [ { item_name: '空心菜', sku_code: 'SKU1', quantity: 11, unit: '斤' }, ]), })); import { notifyRoleUsers } from '../src/services/notificationService'; import { notifyZeroSalePriceOrder } from '../src/services/zeroSalePriceNotificationService'; describe('notifyZeroSalePriceOrder', () => { beforeEach(() => { vi.clearAllMocks(); }); it('notifies admin roles with order and item names', async () => { await notifyZeroSalePriceOrder({ orderCode: 'ORD_Z', branchCode: 'BR002', reason: 'submit', count: 1, }); expect(notifyRoleUsers).toHaveBeenCalledWith( expect.objectContaining({ roles: ['operator', 'admin', 'super_admin'], notifyType: 'zero_sale_price', relatedOrderCode: 'ORD_Z', branchCode: 'BR002', title: '销售价为 0:ORD_Z', }) ); const content = String(vi.mocked(notifyRoleUsers).mock.calls[0][0].content); expect(content).toContain('空心菜'); expect(content).toContain('ORD_Z'); }); it('skips when order code empty', async () => { await notifyZeroSalePriceOrder({ orderCode: ' ' }); expect(notifyRoleUsers).not.toHaveBeenCalled(); }); });