Skip to content

Commit df2af16

Browse files
committed
chore(geld): update dependencies for testing and coverage, add test scripts, and refine .npmignore
1 parent a31795b commit df2af16

8 files changed

Lines changed: 1075 additions & 6 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
21+
- name: Setup pnpm
22+
uses: pnpm/action-setup@v2
23+
with:
24+
version: 8
25+
26+
- name: Install dependencies
27+
run: pnpm install
28+
29+
- name: Run tests with coverage
30+
run: cd packages/geld && pnpm coverage
31+
32+
- name: Generate coverage badge
33+
uses: jpb06/jest-badges-action@latest
34+
with:
35+
branches: main
36+
coverage-summary-path: packages/geld/coverage/coverage-summary.json

packages/geld/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
node_modules
33
tsconfig.json
44
src/
5+
test/
6+
coverage/
7+
vitest.config.ts

packages/geld/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
A comprehensive TypeScript/JavaScript library for financial operations and validations. Currently featuring IBAN (International Bank Account Number) validation and formatting, with more financial tools planned for future releases.
44

5+
![Coverage](./coverage/badges/coverage.svg)
6+
57
> 'Geld' means 'money' in German, Dutch and Afrikaans. That's why we chose that name for our financial tools.
68
79
## Installation

packages/geld/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@
3131
},
3232
"homepage": "https://rivo.gg/projects/geld",
3333
"funding": {
34-
3534
"type": "github",
36-
3735
"url": "https://github.com/sponsors/rivo-gg"
38-
3936
},
4037
"scripts": {
4138
"dev": "tsc --watch",
42-
"build": "tsc"
39+
"build": "tsc",
40+
"test": "vitest",
41+
"coverage": "vitest run --coverage"
4342
},
4443
"devDependencies": {
4544
"@rivo-gg/tsconfig": "workspace:*",
46-
"typescript": "latest"
45+
"@vitest/coverage-v8": "^3.2.1",
46+
"typescript": "latest",
47+
"vitest": "^3.2.1"
4748
},
4849
"sideEffects": false
4950
}

packages/geld/test/iban.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { describe, it, expect } from "vitest";
2+
import { iban } from "../index";
3+
4+
describe("IBAN Validation", () => {
5+
it("should validate correct IBANs", () => {
6+
const validIbans = [
7+
"DE89370400440532013000",
8+
"GB29NWBK60161331926819",
9+
"FR1420041010050500013M02606",
10+
"NL91ABNA0417164300",
11+
];
12+
13+
for (const validIban of validIbans) {
14+
expect(iban.isValid(validIban)).toBe(true);
15+
}
16+
});
17+
18+
it("should not validate incorrect IBANs", () => {
19+
const invalidIbans = [
20+
"DE89370400440532013001",
21+
"GB29NWBK6016133192681",
22+
"FR1420041010050500013M0260699",
23+
"XX91ABNA0417164300",
24+
"",
25+
"NOT-AN-IBAN",
26+
];
27+
28+
for (const invalidIban of invalidIbans) {
29+
expect(iban.isValid(invalidIban)).not.toBe(true);
30+
}
31+
});
32+
33+
it("should validate IBANs with spaces when clean option is true", () => {
34+
const formattedIbans = [
35+
"DE89 3704 0044 0532 0130 00",
36+
"GB29 NWBK 6016 1331 9268 19",
37+
"FR14 2004 1010 0505 0001 3M02 606",
38+
];
39+
40+
for (const formattedIban of formattedIbans) {
41+
expect(iban.isValid(formattedIban, true)).toBe(true);
42+
}
43+
});
44+
});
45+
46+
describe("IBAN Formatting", () => {
47+
it("should format IBANs with default spacing", () => {
48+
const testCases = [
49+
{
50+
input: "DE89370400440532013000",
51+
expected: "DE89 3704 0044 0532 0130 00",
52+
},
53+
{
54+
input: "GB29NWBK60161331926819",
55+
expected: "GB29 NWBK 6016 1331 9268 19",
56+
},
57+
];
58+
59+
for (const { input, expected } of testCases) {
60+
expect(iban.printFormat(input)).toBe(expected);
61+
}
62+
});
63+
64+
it("should format IBANs with custom separator", () => {
65+
const testCases = [
66+
{
67+
input: "DE89370400440532013000",
68+
separator: "-",
69+
expected: "DE89-3704-0044-0532-0130-00",
70+
},
71+
{
72+
input: "GB29NWBK60161331926819",
73+
separator: "*",
74+
expected: "GB29*NWBK*6016*1331*9268*19",
75+
},
76+
];
77+
78+
for (const { input, separator, expected } of testCases) {
79+
expect(iban.printFormat(input, separator)).toBe(expected);
80+
}
81+
});
82+
83+
it("should clean and format IBANs with special characters", () => {
84+
const testCases = [
85+
{
86+
input: "DE89-3704.0044/0532-0130-00",
87+
expected: "DE89 3704 0044 0532 0130 00",
88+
},
89+
{
90+
input: "GB29/NWBK.6016-1331.9268.19",
91+
expected: "GB29 NWBK 6016 1331 9268 19",
92+
},
93+
];
94+
95+
for (const { input, expected } of testCases) {
96+
expect(iban.printFormat(input)).toBe(expected);
97+
}
98+
});
99+
});

packages/geld/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"moduleResolution": "node"
66
},
77
"include": ["src", "index.ts"],
8-
"exclude": ["node_modules", "dist"]
8+
"exclude": ["node_modules", "dist", "test", "coverage", "vitest.config.ts"]
99
}

packages/geld/vitest.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
coverage: {
6+
provider: 'v8',
7+
reporter: ['text', 'json-summary', 'html'],
8+
reportsDirectory: './coverage'
9+
},
10+
},
11+
});

0 commit comments

Comments
 (0)