flexpay-engine 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,76 +0,0 @@
1
- import { describe, test, expect } from "bun:test";
2
- import { toCents, fromCents, formatCents } from "./cents";
3
-
4
- describe("toCents", () => {
5
- test("converts basic decimals", () => {
6
- expect(toCents(16.15)).toBe(1615);
7
- expect(toCents(0)).toBe(0);
8
- expect(toCents(1)).toBe(100);
9
- expect(toCents(100)).toBe(10000);
10
- });
11
-
12
- test("handles string input (from DB numeric columns)", () => {
13
- expect(toCents("16.15")).toBe(1615);
14
- expect(toCents("196.80")).toBe(19680);
15
- expect(toCents("0")).toBe(0);
16
- });
17
-
18
- test("handles the float precision edge cases", () => {
19
- // 0.1 + 0.2 === 0.30000000000000004 in IEEE 754
20
- expect(toCents(0.1 + 0.2)).toBe(30);
21
- expect(toCents(1.005)).toBe(101); // rounds up correctly
22
- expect(toCents(196.80000019073486)).toBe(19680); // real incident value
23
- });
24
-
25
- test("handles null and undefined gracefully", () => {
26
- expect(toCents(null)).toBe(0);
27
- expect(toCents(undefined)).toBe(0);
28
- });
29
-
30
- test("throws on invalid input", () => {
31
- expect(() => toCents(NaN)).toThrow();
32
- expect(() => toCents(Infinity)).toThrow();
33
- expect(() => toCents("not a number")).toThrow();
34
- });
35
-
36
- test("handles negative values (for reversals)", () => {
37
- expect(toCents(-16.15)).toBe(-1615);
38
- expect(toCents(-0.01)).toBe(-1);
39
- });
40
- });
41
-
42
- describe("fromCents", () => {
43
- test("converts basic cents", () => {
44
- expect(fromCents(1615)).toBe(16.15);
45
- expect(fromCents(0)).toBe(0);
46
- expect(fromCents(100)).toBe(1);
47
- expect(fromCents(19680)).toBe(196.8);
48
- });
49
-
50
- test("handles negative values", () => {
51
- expect(fromCents(-1615)).toBe(-16.15);
52
- });
53
-
54
- test("throws on non-integer input", () => {
55
- expect(() => fromCents(16.15)).toThrow();
56
- expect(() => fromCents(1.5)).toThrow();
57
- });
58
- });
59
-
60
- describe("roundtrip", () => {
61
- test("toCents then fromCents returns original", () => {
62
- const values = [0, 1, 16.15, 196.8, 1000, 99.99, 0.01, 0.5];
63
- for (const v of values) {
64
- expect(fromCents(toCents(v))).toBe(v);
65
- }
66
- });
67
- });
68
-
69
- describe("formatCents", () => {
70
- test("formats with 2 decimals", () => {
71
- expect(formatCents(1615)).toBe("16.15");
72
- expect(formatCents(0)).toBe("0.00");
73
- expect(formatCents(100)).toBe("1.00");
74
- expect(formatCents(19680)).toBe("196.80");
75
- });
76
- });