feat: add pricing provider boundary
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-09 11:19:27 -04:00
parent 7c4a299838
commit 4effebd2f8
8 changed files with 135 additions and 1 deletions
@@ -0,0 +1,22 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createPricingProvider, createPricingProviderRegistry } from '../../src/modules/pricing/providers/pricing-provider.js';
test('registers pricing providers behind a validated adapter contract', async () => {
const provider = createPricingProvider({
id: 'example',
async observe() { return [{ priceMinor: 2500, sourceIdentifier: 'example-1' }]; },
});
const registry = createPricingProviderRegistry([provider]);
assert.equal(registry.get('example'), provider);
assert.deepEqual(await registry.get('example').observe({}), [{ priceMinor: 2500, sourceIdentifier: 'example-1' }]);
assert.deepEqual(registry.list(), [provider]);
});
test('rejects malformed provider adapters and responses', async () => {
assert.throws(() => createPricingProvider({ id: 'broken' }), /observe function is required/);
const provider = createPricingProvider({ id: 'broken', async observe() { return null; } });
await assert.rejects(() => provider.observe({}), /must return an observation array/);
});
@@ -34,4 +34,16 @@ test('requires a reason for an audited market-value override', async () => {
() => service.override({ sellerId: 'seller-1', actorUserId: 'user-1', inventoryItemId: 'inventory-1', valueMinor: 2000, reason: 'x' }),
(error) => error.code === 'OVERRIDE_REASON_REQUIRED' && error.statusCode === 400,
);
});
test('fails clearly when a requested pricing provider is unavailable', async () => {
const service = createPricingService({
pricingRepository: {},
pricingProviderRegistry: { get() { return null; } },
});
await assert.rejects(
() => service.refresh({ sellerId: 'seller-1', inventoryItemId: 'inventory-1', providerId: 'missing' }),
(error) => error.code === 'PRICING_PROVIDER_UNAVAILABLE' && error.statusCode === 503,
);
});