Quality / test (push) Canceled after 0s
Add acquisition persistence, cost-basis calculation, seller-scoped admin routes, contracts, validation, migration, and focused application/HTTP tests.
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
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,
|
|
);
|
|
}); |