feat: add acquisition API foundation
Quality / test (push) Canceled after 0s

Add acquisition persistence, cost-basis calculation, seller-scoped admin routes, contracts, validation, migration, and focused application/HTTP tests.
This commit is contained in:
2026-09-09 00:39:56 -04:00
parent 26405d4ace
commit eee8e1978f
14 changed files with 291 additions and 0 deletions
@@ -0,0 +1,41 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createAcquisitionService } from '../../src/modules/acquisitions/services/acquisition-service.js';
test('creates an owned acquisition and calculates cost basis', async () => {
let received;
const service = createAcquisitionService({
acquisitionRepository: {
async createForSeller(input) {
received = input;
return { status: 'CREATED', acquisition: { id: 'acquisition-1', ...input.acquisition } };
},
},
});
const result = await service.create({
sellerId: 'seller-1',
inventoryItemId: 'inventory-1',
method: 'PURCHASE',
costMinor: 1000,
shippingMinor: 150,
taxMinor: 75,
otherFeesMinor: 50,
estimatedTradeValueMinor: 200,
});
assert.equal(received.sellerId, 'seller-1');
assert.equal(result.costBasisMinor, 1075);
});
test('rejects acquisition for an inventory item outside the seller account', async () => {
const service = createAcquisitionService({
acquisitionRepository: { async createForSeller() { return { status: 'NOT_FOUND' }; } },
});
await assert.rejects(
() => service.create({ sellerId: 'seller-1', inventoryItemId: 'inventory-1', method: 'PURCHASE', costMinor: 100 }),
(error) => error.code === 'INVENTORY_NOT_FOUND' && error.statusCode === 404,
);
});