Add seller-scoped dashboard aggregation and API, private financial summary DTOs, responsive admin metrics, and authenticated E2E coverage.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createDashboardService } from '../../src/modules/dashboard/services/dashboard-service.js';
|
||||
|
||||
test('aggregates seller dashboard counts and financial totals', async () => {
|
||||
const service = createDashboardService({
|
||||
productService: { async listBySellerId() { return [{ id: 'product-1' }]; } },
|
||||
inventoryItemService: { async listBySellerId() { return [{ status: 'ACTIVE' }, { status: 'SOLD' }]; } },
|
||||
listingService: { async list() { return [{ status: 'AVAILABLE', askingPriceMinor: 2500, imageCount: 1 }]; } },
|
||||
saleService: { async list() { return [{ status: 'COMPLETED', netProceedsMinor: 2200, profitMinor: 700 }]; } },
|
||||
acquisitionService: { async list() { return [{ costBasisMinor: 1500 }]; } },
|
||||
});
|
||||
|
||||
const dashboard = await service.get({ sellerId: 'seller-1' });
|
||||
assert.deepEqual(dashboard.counts, {
|
||||
products: 1,
|
||||
inventory: 2,
|
||||
activeInventory: 1,
|
||||
soldInventory: 1,
|
||||
availableListings: 1,
|
||||
sales: 1,
|
||||
acquisitions: 1,
|
||||
missingImages: 0,
|
||||
});
|
||||
assert.deepEqual(dashboard.financials, {
|
||||
totalAcquisitionCostMinor: 1500,
|
||||
totalAskingValueMinor: 2500,
|
||||
totalNetSaleProceedsMinor: 2200,
|
||||
totalProfitMinor: 700,
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { buildApp } from '../../src/app/build-app.js';
|
||||
|
||||
test('returns a seller-scoped dashboard', async (testContext) => {
|
||||
const app = buildApp({
|
||||
authenticateAdmin: async () => ({ sellerId: 'seller-1' }),
|
||||
dashboardService: { async get({ sellerId }) { assert.equal(sellerId, 'seller-1'); return { counts: {}, financials: {}, recentSales: [], recentAcquisitions: [] }; } },
|
||||
});
|
||||
testContext.after(() => app.close());
|
||||
|
||||
const response = await app.inject({ method: 'GET', url: '/api/v1/admin/dashboard' });
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.deepEqual(response.json().data, { counts: {}, financials: {}, recentSales: [], recentAcquisitions: [] });
|
||||
});
|
||||
Reference in New Issue
Block a user