Files
pokemon-inventory/apps/api/tests/application/pricing-service.test.js
T
fragginwagon 75c0e89511
Quality / test (push) Canceled after 0s
feat: add pricing quality controls
Add robust outlier detection, stale valuation metadata, and audited seller-scoped market-value overrides with migration and tests.
2026-09-09 01:19:51 -04:00

37 lines
1.6 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { createPricingService } from '../../src/modules/pricing/services/pricing-service.js';
test('records an owned pricing observation and calculates a valuation', async () => {
const service = createPricingService({
pricingRepository: {
async addObservationForSeller({ observation, sellerId }) {
assert.equal(sellerId, 'seller-1');
return { status: 'CREATED', observation };
},
async markOutliersForSeller() {
return { status: 'UPDATED' };
},
async calculateForSeller() {
return { status: 'CALCULATED', valuation: { valueMinor: 2500 }, observations: [] };
},
},
});
const observation = await service.addObservation({
sellerId: 'seller-1', productId: 'product-1', inventoryItemId: 'inventory-1',
providerId: 'manual', priceMinor: 2500, sourceIdentifier: 'source-1', conditionId: 'condition-1',
});
assert.equal(observation.priceMinor, 2500);
const valuation = await service.calculate({ sellerId: 'seller-1', inventoryItemId: 'inventory-1' });
assert.equal(valuation.valuation.valueMinor, 2500);
});
test('requires a reason for an audited market-value override', async () => {
const service = createPricingService({ pricingRepository: { async createOverride() { throw new Error('should not run'); } } });
await assert.rejects(
() => service.override({ sellerId: 'seller-1', actorUserId: 'user-1', inventoryItemId: 'inventory-1', valueMinor: 2000, reason: 'x' }),
(error) => error.code === 'OVERRIDE_REASON_REQUIRED' && error.statusCode === 400,
);
});