All files / packages/app/utils debts.ts

100% Statements 4/4
100% Branches 6/6
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19        147x 59x       147x           681x      
import type { Debt, Receipt } from "~app/trpc-types";
 
type DebtPartial = Pick<Debt, "amount" | "currencyCode" | "timestamp">;
 
export const areDebtsSynced = (debt: DebtPartial, theirDebt: DebtPartial) =>
	debt.amount === theirDebt.amount &&
	debt.currencyCode === theirDebt.currencyCode &&
	Temporal.PlainDate.compare(debt.timestamp, theirDebt.timestamp) === 0;
 
export const isDebtInSyncWithReceipt = (
	receiptDebt: Pick<Receipt, "currencyCode" | "issued" | "id"> & {
		participantSum: number;
	},
	debt: DebtPartial,
) =>
	receiptDebt.currencyCode === debt.currencyCode &&
	receiptDebt.participantSum === debt.amount &&
	Temporal.PlainDate.compare(receiptDebt.issued, debt.timestamp) === 0;