Backfill the completed acquisitions, sales, dashboard, pricing, search, public detail, worker, migration, contracts, validation, tests, and implementation-status changes into one verified application slice.
78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
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 [
|
|
{ id: "item-1", status: "ACTIVE" },
|
|
{ id: "item-2", 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 }];
|
|
},
|
|
},
|
|
pricingRepository: {
|
|
async listLatestValuationsForSeller() {
|
|
return [
|
|
{
|
|
inventoryItemId: "item-1",
|
|
valueMinor: 2800,
|
|
calculatedAt: new Date(),
|
|
},
|
|
];
|
|
},
|
|
},
|
|
pricingRefreshJobRepository: {
|
|
async countFailedForSeller() {
|
|
return 2;
|
|
},
|
|
},
|
|
});
|
|
|
|
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,
|
|
missingPricing: 1,
|
|
stalePricing: 0,
|
|
failedPricingJobs: 2,
|
|
});
|
|
assert.deepEqual(dashboard.financials, {
|
|
totalAcquisitionCostMinor: 1500,
|
|
totalAskingValueMinor: 2500,
|
|
totalNetSaleProceedsMinor: 2200,
|
|
totalProfitMinor: 700,
|
|
totalMarketValueMinor: 2800,
|
|
});
|
|
});
|