mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
// ── Provider contract test ────────────────────────────────────────────────────
|
|
// This suite is the "gate" for onboarding new payment providers. It does not
|
|
// hardcode "paypal" as the only case — it walks registry.list() and asserts
|
|
// every registered provider satisfies the shape payment.service.js relies on.
|
|
// Drop a second provider into providers/registry.js and this file validates it
|
|
// for free, with zero new test code required.
|
|
|
|
const registry = require('../../providers/registry');
|
|
|
|
const REQUIRED_METHODS = ['createOrder', 'captureOrder', 'refundCapture'];
|
|
|
|
describe('payment provider registry', () => {
|
|
|
|
test('lists at least one provider', () => {
|
|
expect(registry.list().length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('currently registers paypal', () => {
|
|
expect(registry.list()).toContain('paypal');
|
|
});
|
|
|
|
test('get() returns the provider module for a known name', () => {
|
|
const provider = registry.get('paypal');
|
|
expect(provider).toBeDefined();
|
|
});
|
|
|
|
test('get() throws a descriptive error for an unknown provider', () => {
|
|
expect(() => registry.get('stripe')).toThrow(/Unknown payment provider: "stripe"/);
|
|
});
|
|
|
|
test('unknown-provider error lists the available providers so misconfiguration is easy to diagnose', () => {
|
|
try {
|
|
registry.get('does-not-exist');
|
|
throw new Error('expected registry.get to throw');
|
|
} catch (err) {
|
|
registry.list().forEach((name) => {
|
|
expect(err.message).toContain(name);
|
|
});
|
|
}
|
|
});
|
|
|
|
describe.each(registry.list())('provider contract: %s', (name) => {
|
|
const provider = registry.get(name);
|
|
|
|
test.each(REQUIRED_METHODS)('exposes %s as a function', (method) => {
|
|
expect(typeof provider[method]).toBe('function');
|
|
});
|
|
});
|
|
});
|