This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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',
|
||||
}]);
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { buildApp } from '../../src/app/build-app.js';
|
||||
import { createAdminExportService } from '../../src/modules/exports/services/admin-export-service.js';
|
||||
|
||||
test('downloads seller-scoped inventory JSON for an authenticated admin', async (testContext) => {
|
||||
const app = buildApp({
|
||||
authenticateAdmin: async () => ({ sellerId: 'seller-1' }),
|
||||
adminExportService: 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',
|
||||
}];
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/admin/exports/inventory.json',
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(response.headers['content-type'], 'application/json; charset=utf-8');
|
||||
assert.equal(response.headers['content-disposition'], 'attachment; filename="inventory.json"');
|
||||
assert.deepEqual(JSON.parse(response.body), [{
|
||||
id: 'item-1',
|
||||
productId: 'product-1',
|
||||
conditionId: 'condition-1',
|
||||
status: 'ACTIVE',
|
||||
notes: 'Private note',
|
||||
}]);
|
||||
});
|
||||
|
||||
test('requires authentication for inventory JSON exports', async (testContext) => {
|
||||
const app = buildApp({
|
||||
adminExportService: createAdminExportService({
|
||||
inventoryItemService: { async listBySellerId() { return []; } },
|
||||
}),
|
||||
});
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const response = await app.inject({
|
||||
method: 'GET',
|
||||
url: '/api/v1/admin/exports/inventory.json',
|
||||
});
|
||||
|
||||
assert.equal(response.statusCode, 401);
|
||||
assert.equal(response.json().error.code, 'UNAUTHORIZED');
|
||||
});
|
||||
Reference in New Issue
Block a user