38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { createPricingProvider, createPricingProviderRegistry } from '../../src/modules/pricing/providers/pricing-provider.js';
|
|
import { createFixturePricingProvider } from '../../src/modules/pricing/providers/fixture-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/);
|
|
});
|
|
|
|
test('fixture provider returns deterministic normalized observations', async () => {
|
|
const [observation] = await createFixturePricingProvider().observe({
|
|
productId: 'product-1', inventoryItemId: 'item-1', conditionId: 'condition-1',
|
|
});
|
|
assert.deepEqual(observation, {
|
|
productId: 'product-1',
|
|
inventoryItemId: 'item-1',
|
|
conditionId: 'condition-1',
|
|
priceMinor: 2500,
|
|
currency: 'USD',
|
|
sourceIdentifier: 'fixture-item-1',
|
|
qualityScore: 50,
|
|
});
|
|
}); |