feat: add admin inventory Excel export
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-10 01:11:07 -04:00
parent d6b4dbec5f
commit 24f51212e5
8 changed files with 91 additions and 0 deletions
@@ -52,3 +52,18 @@ test('exports inventory as escaped CSV rows', async () => {
'"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>/);
});
@@ -80,3 +80,23 @@ test('downloads seller-scoped inventory CSV for an authenticated admin', async (
assert.equal(response.headers['content-disposition'], 'attachment; filename="inventory.csv"');
assert.equal(response.body, 'id,status\r\n"item-1","ACTIVE"');
});
test('downloads seller-scoped inventory Excel XML for an authenticated admin', async (testContext) => {
const app = buildApp({
authenticateAdmin: async () => ({ sellerId: 'seller-1' }),
adminExportService: {
async inventoryExcel({ sellerId }) {
assert.equal(sellerId, 'seller-1');
return '<?xml version="1.0"?><Workbook />';
},
},
});
testContext.after(() => app.close());
const response = await app.inject({ method: 'GET', url: '/api/v1/admin/exports/inventory.xls' });
assert.equal(response.statusCode, 200);
assert.equal(response.headers['content-type'], 'application/vnd.ms-excel; charset=utf-8');
assert.equal(response.headers['content-disposition'], 'attachment; filename="inventory.xls"');
assert.equal(response.body, '<?xml version="1.0"?><Workbook />');
});