Files
pokemon-inventory/apps/api/tests/application/admin-export-service.test.js
T
2026-09-10 01:11:07 -04:00

70 lines
2.2 KiB
JavaScript

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 <note>' }];
},
},
});
const workbook = await service.inventoryExcel({ sellerId: 'seller-1' });
assert.match(workbook, /Excel\.Sheet/);
assert.match(workbook, /A &lt;note&gt;/);
assert.match(workbook, /<Cell ss:StyleID="Header"><Data ss:Type="String">id<\/Data><\/Cell>/);
});