diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 9891010..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "env": { - "browser": true, - "node": true - }, - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": ["@typescript-eslint"], - "rules": { - "no-var": "error", - "linebreak-style": ["error", "unix"], - "quotes": [ - "error", - "double", - { - "allowTemplateLiterals": true - } - ], - "semi": ["error", "always"], - "no-warning-comments": [ - "error", - { - "terms": ["todo", "fixme"], - "location": "anywhere" - } - ] - } -} diff --git a/bun.lockb b/bun.lockb index 7fc937d..4b638ef 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/jest.config.cjs b/jest.config.cjs deleted file mode 100644 index 1cda9c6..0000000 --- a/jest.config.cjs +++ /dev/null @@ -1,8 +0,0 @@ -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { - transform: { - "^.+\\.(t|j)sx?$": ["@swc/jest"], - }, - preset: "ts-jest", - testEnvironment: "node", -}; diff --git a/package.json b/package.json index 4b61430..608842b 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "deploy:docs": "pnpm run docs && gh-pages -d docs", "format:test": "prettier --check \"src/*.{ts,tsx}\"", "format:write": "prettier --write \"src/*.{ts,tsx}\"", - "lint": "eslint src/**/*.ts", - "test": "jest && pnpm run format:test && pnpm run lint", + "test": "bun test && pnpm run format:test", "prepare": "pnpm run build", "prepublishOnly": "pnpm run test && pnpm run deploy:docs", "preversion": "pnpm run test", @@ -34,16 +33,10 @@ "devDependencies": { "@swc/cli": "^0.4.0", "@swc/core": "^1.7.0", - "@swc/jest": "^0.2.36", "@types/bun": "^1.1.6", - "@types/jest": "^29.5.12", - "@typescript-eslint/eslint-plugin": "^7.16.1", - "@typescript-eslint/parser": "^7.16.1", "dayjs": "^1.11.12", - "eslint": "^9.7.0", "gh-pages": "^6.1.1", "gzip-size-cli": "^5.1.0", - "jest": "^29.7.0", "prettier": "^3.3.3", "ts-jest": "^29.2.3", "typedoc": "^0.26.5", diff --git a/src/index.test.ts b/src/index.test.ts index d99bb45..a1365e7 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,229 +1,228 @@ -import { createSepaXML } from "./index"; +import { expect, test } from "bun:test"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; +import { createSepaXML } from "./index"; dayjs.extend(utc); -describe("createSepaXML", () => { - it("check valid xml", () => { - expect( - createSepaXML({ - painVersion: "pain.001.001.02", - id: "1", - creationDate: dayjs.utc("2022-06-16").toDate(), - initiatorName: "Test", - positions: [ - { - name: "Test", - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - requestedExecutionDate: dayjs.utc("2022-06-16").toDate(), - id: "123", - payments: [ - { - id: "Payment 1 ", - amount: 123, - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - name: "Test", - remittanceInformation: "WOW 1", - }, - { - id: "Payment 2", - amount: 123.83, - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - name: "Test", - remittanceInformation: "WOW 2", - }, - { - id: "Payment 3", - amount: 69, - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - name: "Test", - remittanceInformation: "WOW 3", - }, - ], - }, - ], - }), - ).toEqual( - `12022-06-16T00:00:00true3315.83MIXDTest123TRFSEPA2022-06-16TestDE02701500000000594937SSKMDEMMSLEVPayment 1 123.00SSKMDEMMTestDE02701500000000594937WOW 1Payment 2123.83SSKMDEMMTestDE02701500000000594937WOW 2Payment 369.00SSKMDEMMTestDE02701500000000594937WOW 3`, - ); - }); - - it("check currency", () => { - expect( - createSepaXML({ - painVersion: "pain.001.001.02", - id: "1", - creationDate: dayjs.utc("2022-06-16").toDate(), - initiatorName: "Test", - positions: [ - { - name: "Test", - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - requestedExecutionDate: dayjs.utc("2022-06-16").toDate(), - id: "123", - payments: [ - { - id: "Payment 1 ", - amount: 123, - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - name: "Test", - remittanceInformation: "WOW 1", - currency: "USD", - }, - { - id: "Payment 2", - amount: 123.83, - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - name: "Test", - remittanceInformation: "WOW 2", - currency: "USD", - }, - { - id: "Payment 3", - amount: 69, - iban: "DE02701500000000594937", - bic: "SSKMDEMM", - name: "Test", - remittanceInformation: "WOW 3", - currency: "USD", - }, - ], - }, - ], - }), - ).toEqual( - `12022-06-16T00:00:00true3315.83MIXDTest123TRFSEPA2022-06-16TestDE02701500000000594937SSKMDEMMSLEVPayment 1 123.00SSKMDEMMTestDE02701500000000594937WOW 1Payment 2123.83SSKMDEMMTestDE02701500000000594937WOW 2Payment 369.00SSKMDEMMTestDE02701500000000594937WOW 3`, - ); - }); - - it("check id error", () => { - try { - createSepaXML( +test("check valid xml", () => { + expect( + createSepaXML({ + painVersion: "pain.001.001.02", + id: "1", + creationDate: dayjs.utc("2022-06-16").toDate(), + initiatorName: "Test", + positions: [ { - id: "123456789123456789123456789123456789", - creationDate: new Date(), - initiatorName: "Test", - positions: [], + name: "Test", + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + requestedExecutionDate: dayjs.utc("2022-06-16").toDate(), + id: "123", + payments: [ + { + id: "Payment 1 ", + amount: 123, + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + name: "Test", + remittanceInformation: "WOW 1", + }, + { + id: "Payment 2", + amount: 123.83, + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + name: "Test", + remittanceInformation: "WOW 2", + }, + { + id: "Payment 3", + amount: 69, + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + name: "Test", + remittanceInformation: "WOW 3", + }, + ], }, + ], + }), + ).toEqual( + `12022-06-16T00:00:00true3315.83MIXDTest123TRFSEPA2022-06-16TestDE02701500000000594937SSKMDEMMSLEVPayment 1 123.00SSKMDEMMTestDE02701500000000594937WOW 1Payment 2123.83SSKMDEMMTestDE02701500000000594937WOW 2Payment 369.00SSKMDEMMTestDE02701500000000594937WOW 3`, + ); +}); + +test("check currency", () => { + expect( + createSepaXML({ + painVersion: "pain.001.001.02", + id: "1", + creationDate: dayjs.utc("2022-06-16").toDate(), + initiatorName: "Test", + positions: [ { - checkIBAN: true, - checkBIC: true, + name: "Test", + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + requestedExecutionDate: dayjs.utc("2022-06-16").toDate(), + id: "123", + payments: [ + { + id: "Payment 1 ", + amount: 123, + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + name: "Test", + remittanceInformation: "WOW 1", + currency: "USD", + }, + { + id: "Payment 2", + amount: 123.83, + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + name: "Test", + remittanceInformation: "WOW 2", + currency: "USD", + }, + { + id: "Payment 3", + amount: 69, + iban: "DE02701500000000594937", + bic: "SSKMDEMM", + name: "Test", + remittanceInformation: "WOW 3", + currency: "USD", + }, + ], }, + ], + }), + ).toEqual( + `12022-06-16T00:00:00true3315.83MIXDTest123TRFSEPA2022-06-16TestDE02701500000000594937SSKMDEMMSLEVPayment 1 123.00SSKMDEMMTestDE02701500000000594937WOW 1Payment 2123.83SSKMDEMMTestDE02701500000000594937WOW 2Payment 369.00SSKMDEMMTestDE02701500000000594937WOW 3`, + ); +}); + +test("check id error", () => { + try { + createSepaXML( + { + id: "123456789123456789123456789123456789", + creationDate: new Date(), + initiatorName: "Test", + positions: [], + }, + { + checkIBAN: true, + checkBIC: true, + }, + ); + } catch (e) { + if (e instanceof Error) { + expect(e.message).toEqual( + "Max length for sepaData.id is 35 (123456789123456789123456789123456789)", ); - } catch (e) { - if (e instanceof Error) { - expect(e.message).toEqual( - "Max length for sepaData.id is 35 (123456789123456789123456789123456789)", - ); - return; - } + return; } + } - throw new Error("Error not thrown"); - }); + throw new Error("Error not thrown"); +}); - it("check iban validation", () => { - try { - createSepaXML({ - id: "Test", - creationDate: new Date(), - initiatorName: "Test", - positions: [ - { - name: "Test", - iban: "Test", - bic: "Test", - id: "123", - payments: [], - requestedExecutionDate: new Date(), - }, - ], - }); - } catch (e) { - if (e instanceof Error) { - expect(e.message).toEqual( - "sepaData.positions[0].iban is not valid (Test)", - ); - return; - } +test("check iban validation", () => { + try { + createSepaXML({ + id: "Test", + creationDate: new Date(), + initiatorName: "Test", + positions: [ + { + name: "Test", + iban: "Test", + bic: "Test", + id: "123", + payments: [], + requestedExecutionDate: new Date(), + }, + ], + }); + } catch (e) { + if (e instanceof Error) { + expect(e.message).toEqual( + "sepaData.positions[0].iban is not valid (Test)", + ); + return; } + } - throw new Error("Error not thrown"); - }); + throw new Error("Error not thrown"); +}); - it("check bic validation", () => { - try { - createSepaXML({ - id: "Test", - creationDate: new Date(), - initiatorName: "Test", - positions: [ - { - name: "Test", - iban: "DE02701500000000594937", - bic: "Test", - id: "123", - payments: [], - requestedExecutionDate: new Date(), - }, - ], - }); - } catch (e) { - if (e instanceof Error) { - expect(e.message).toEqual( - "sepaData.positions[0].bic is not valid (Test)", - ); - return; - } +test("check bic validation", () => { + try { + createSepaXML({ + id: "Test", + creationDate: new Date(), + initiatorName: "Test", + positions: [ + { + name: "Test", + iban: "DE02701500000000594937", + bic: "Test", + id: "123", + payments: [], + requestedExecutionDate: new Date(), + }, + ], + }); + } catch (e) { + if (e instanceof Error) { + expect(e.message).toEqual( + "sepaData.positions[0].bic is not valid (Test)", + ); + return; } + } - throw new Error("Error not thrown"); - }); + throw new Error("Error not thrown"); +}); - it("issue #172", () => { - const result = createSepaXML( - { - painVersion: "pain.001.001.03", - id: "Test1345", - creationDate: dayjs.utc("2022-06-16").toDate(), - initiatorName: "Test Company", - positions: [ - { - id: "Test123", - batchBooking: false, - iban: "DE02701500000000594937", - bic: "Test", - requestedExecutionDate: dayjs.utc("2022-06-16").toDate(), - name: "Pos 1", - payments: [ - { - id: "123", - amount: 230, - currency: "EUR", - bic: "Test", - name: "Money Company", - iban: "DE02701500000000594937", - remittanceInformation: "Money please", - end2endReference: "lol", - }, - ], - }, - ], - }, - { - checkIBAN: false, - checkBIC: false, - }, - ); - expect(result).toBe( - `Test13452022-06-16T00:00:001230.00Test CompanyTest123TRFfalse1230.00SEPA2022-06-16Pos 1DE02701500000000594937TestSLEV123lol230.00TestMoney CompanyDE02701500000000594937Money please`, - ); - }); +test("issue #172", () => { + const result = createSepaXML( + { + painVersion: "pain.001.001.03", + id: "Test1345", + creationDate: dayjs.utc("2022-06-16").toDate(), + initiatorName: "Test Company", + positions: [ + { + id: "Test123", + batchBooking: false, + iban: "DE02701500000000594937", + bic: "Test", + requestedExecutionDate: dayjs.utc("2022-06-16").toDate(), + name: "Pos 1", + payments: [ + { + id: "123", + amount: 230, + currency: "EUR", + bic: "Test", + name: "Money Company", + iban: "DE02701500000000594937", + remittanceInformation: "Money please", + end2endReference: "lol", + }, + ], + }, + ], + }, + { + checkIBAN: false, + checkBIC: false, + }, + ); + expect(result).toBe( + `Test13452022-06-16T00:00:001230.00Test CompanyTest123TRFfalse1230.00SEPA2022-06-16Pos 1DE02701500000000594937TestSLEV123lol230.00TestMoney CompanyDE02701500000000594937Money please`, + ); });