mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 14:15:44 +00:00
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { ManualPaymentSettingsService } from "./manual-payment-settings.service";
|
|
import type { ManualPaymentSetting } from "./entities/manual-payment-setting.entity";
|
|
|
|
/** Single-row repository stub: enough for get/update, nothing more. */
|
|
const repoWith = (row: Partial<ManualPaymentSetting>) => {
|
|
const stored = { id: "settings-1", ...row } as ManualPaymentSetting;
|
|
return {
|
|
findOne: async () => stored,
|
|
create: (v: Partial<ManualPaymentSetting>) => v as ManualPaymentSetting,
|
|
save: async (v: ManualPaymentSetting) => v,
|
|
update: async (_id: string, patch: Partial<ManualPaymentSetting>) => {
|
|
Object.assign(stored, patch);
|
|
},
|
|
};
|
|
};
|
|
|
|
const serviceWith = (row: Partial<ManualPaymentSetting>) =>
|
|
new ManualPaymentSettingsService(repoWith(row) as never);
|
|
|
|
describe("DJF currency switch", () => {
|
|
it("offers DJF, and accepts it, while the switch is on", async () => {
|
|
const service = serviceWith({ djfPaymentsEnabled: true });
|
|
|
|
await expect(service.offeredCurrencies()).resolves.toEqual([
|
|
"ETB",
|
|
"USD",
|
|
"DJF",
|
|
]);
|
|
await expect(service.isCurrencyOffered("DJF")).resolves.toBe(true);
|
|
});
|
|
|
|
it("drops DJF from the offered currencies once switched off", async () => {
|
|
const service = serviceWith({ djfPaymentsEnabled: false });
|
|
|
|
await expect(service.offeredCurrencies()).resolves.toEqual(["ETB", "USD"]);
|
|
await expect(service.isCurrencyOffered("djf")).resolves.toBe(false);
|
|
});
|
|
|
|
it("never switches off ETB or USD — only DJF has a currency-level switch", async () => {
|
|
const service = serviceWith({ djfPaymentsEnabled: false });
|
|
|
|
await expect(service.isCurrencyOffered("ETB")).resolves.toBe(true);
|
|
await expect(service.isCurrencyOffered("USD")).resolves.toBe(true);
|
|
});
|
|
|
|
it("leaves the manual rail alone when the currency switch flips", async () => {
|
|
const service = serviceWith({ djfEnabled: true, djfPaymentsEnabled: true });
|
|
|
|
const updated = await service.update({ djfPaymentsEnabled: false }, "user-1");
|
|
|
|
expect(updated.djfPaymentsEnabled).toBe(false);
|
|
// Existing DJF invoices stay hand-settleable, so nothing is stranded.
|
|
expect(updated.djfEnabled).toBe(true);
|
|
await expect(service.isEnabled("DJF")).resolves.toBe(true);
|
|
});
|
|
});
|