import assert from 'node:assert/strict'; import test from 'node:test'; import { createAdminExportService } from '../../src/modules/exports/services/admin-export-service.js'; test('exports seller inventory through the admin DTO boundary', async () => { const service = createAdminExportService({ inventoryItemService: { async listBySellerId(sellerId) { assert.equal(sellerId, 'seller-1'); return [{ id: 'item-1', productId: 'product-1', conditionId: 'condition-1', status: 'ACTIVE', notes: 'Private note', createdAt: new Date('2026-09-10T00:00:00.000Z'), updatedAt: new Date('2026-09-10T00:00:00.000Z'), }]; }, }, }); assert.deepEqual(await service.inventoryJson({ sellerId: 'seller-1' }), [{ id: 'item-1', productId: 'product-1', conditionId: 'condition-1', status: 'ACTIVE', notes: 'Private note', createdAt: '2026-09-10T00:00:00.000Z', updatedAt: '2026-09-10T00:00:00.000Z', }]); }); test('exports inventory as escaped CSV rows', async () => { const service = createAdminExportService({ inventoryItemService: { async listBySellerId() { return [{ id: 'item-1', productId: 'product-1', conditionId: 'condition-1', status: 'ACTIVE', notes: 'Front, "clean"\nback', }]; }, }, }); assert.equal(await service.inventoryCsv({ sellerId: 'seller-1' }), [ 'id,productId,conditionId,status,notes,createdAt,updatedAt', '"item-1","product-1","condition-1","ACTIVE","Front, ""clean""\nback","",""', ].join('\r\n')); }); test('exports inventory as an escaped Excel XML workbook', async () => { const service = createAdminExportService({ inventoryItemService: { async listBySellerId() { return [{ id: 'item-1', productId: 'product-1', conditionId: 'condition-1', status: 'ACTIVE', notes: 'A ' }]; }, }, }); const workbook = await service.inventoryExcel({ sellerId: 'seller-1' }); assert.match(workbook, /Excel\.Sheet/); assert.match(workbook, /A <note>/); assert.match(workbook, /id<\/Data><\/Cell>/); });