Andrew Wallo 7 kuukautta sitten
vanhempi
commit
b03b86ac01
3 muutettua tiedostoa jossa 74 lisäystä ja 7 poistoa
  1. 6
    6
      package-lock.json
  2. 2
    1
      resources/data/lang/en.json
  3. 66
    0
      tests/Feature/Setting/LocalizationTest.php

+ 6
- 6
package-lock.json Näytä tiedosto

@@ -1524,18 +1524,18 @@
1524 1524
             }
1525 1525
         },
1526 1526
         "node_modules/get-intrinsic": {
1527
-            "version": "1.2.7",
1528
-            "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.7.tgz",
1529
-            "integrity": "sha512-VW6Pxhsrk0KAOqs3WEd0klDiF/+V7gQOpAvY1jVU/LHmaD/kQO4523aiJuikX/QAKYiW6x8Jh+RJej1almdtCA==",
1527
+            "version": "1.3.0",
1528
+            "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
1529
+            "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
1530 1530
             "dev": true,
1531 1531
             "license": "MIT",
1532 1532
             "dependencies": {
1533
-                "call-bind-apply-helpers": "^1.0.1",
1533
+                "call-bind-apply-helpers": "^1.0.2",
1534 1534
                 "es-define-property": "^1.0.1",
1535 1535
                 "es-errors": "^1.3.0",
1536
-                "es-object-atoms": "^1.0.0",
1536
+                "es-object-atoms": "^1.1.1",
1537 1537
                 "function-bind": "^1.1.2",
1538
-                "get-proto": "^1.0.0",
1538
+                "get-proto": "^1.0.1",
1539 1539
                 "gopd": "^1.2.0",
1540 1540
                 "has-symbols": "^1.1.0",
1541 1541
                 "hasown": "^2.0.2",

+ 2
- 1
resources/data/lang/en.json Näytä tiedosto

@@ -196,5 +196,6 @@
196 196
     "Dates & Time": "Dates & Time",
197 197
     "account": "account",
198 198
     "currency": "currency",
199
-    "Estimate": "Estimate"
199
+    "Estimate": "Estimate",
200
+    "Column Labels": "Column Labels"
200 201
 }

+ 66
- 0
tests/Feature/Setting/LocalizationTest.php Näytä tiedosto

@@ -0,0 +1,66 @@
1
+<?php
2
+
3
+use App\Models\Setting\Localization;
4
+use App\Utilities\RateCalculator;
5
+
6
+// RateCalculator Basic Operations
7
+it('calculates percentage correctly', function () {
8
+    $valueInCents = 100000; // 1000 dollars in cents
9
+    $scaledRate = RateCalculator::decimalToScaledRate(0.025); // 2.5%
10
+
11
+    expect(RateCalculator::calculatePercentage($valueInCents, $scaledRate))
12
+        ->toBe(2500); // Should be 25 dollars in cents
13
+});
14
+
15
+it('converts between scaled rates and decimals correctly', function (float $decimal, int $scaled) {
16
+    // Test decimal to scaled
17
+    expect(RateCalculator::decimalToScaledRate($decimal))->toBe($scaled)
18
+        ->and(RateCalculator::scaledRateToDecimal($scaled))->toBe($decimal);
19
+})->with([
20
+    [0.25, 250000],     // 0.25 * 1000000 = 250000
21
+    [0.1, 100000],      // 0.1 * 1000000 = 100000
22
+    [0.01, 10000],      // 0.01 * 1000000 = 10000
23
+    [0.001, 1000],      // 0.001 * 1000000 = 1000
24
+    [0.0001, 100],      // 0.0001 * 1000000 = 100
25
+]);
26
+
27
+it('handles rate formatting correctly for different computations', function () {
28
+    $localization = Localization::firstOrFail();
29
+    $localization->update(['language' => 'en']);
30
+
31
+    // Test fixed amount formatting
32
+    expect(rateFormat(100000, 'fixed', 'USD'))->toBe('$100,000.00 USD');
33
+
34
+    // Test percentage formatting
35
+    $scaledRate = RateCalculator::decimalToScaledRate(0.000025); // 0.25%
36
+    expect(rateFormat($scaledRate, 'percentage'))->toBe('25%');
37
+});
38
+
39
+// Edge Cases and Error Handling
40
+it('handles edge cases correctly', function () {
41
+    $localization = Localization::firstOrFail();
42
+    $localization->update(['language' => 'en']);
43
+
44
+    expect(RateCalculator::formatScaledRate(0))->toBe('0')
45
+        ->and(RateCalculator::formatScaledRate(1))->toBe('0.0001')
46
+        ->and(RateCalculator::formatScaledRate(10000000))->toBe('1,000')
47
+        ->and(RateCalculator::formatScaledRate(-250000))->toBe('-25');
48
+});
49
+
50
+// Precision Tests
51
+it('maintains precision correctly', function () {
52
+    $localization = Localization::firstOrFail();
53
+    $localization->update(['language' => 'en']);
54
+
55
+    $testCases = [
56
+        '1.0000' => '1',
57
+        '1.2300' => '1.23',
58
+        '1.2340' => '1.234',
59
+        '1.2345' => '1.2345',
60
+    ];
61
+
62
+    foreach ($testCases as $input => $expected) {
63
+        $scaled = RateCalculator::parseLocalizedRate($input);
64
+        expect(RateCalculator::formatScaledRate($scaled))->toBe($expected);
65
+    }
66
+});

Loading…
Peruuta
Tallenna