mt940-mbank-ts/src/index.test.ts

55 lines
1.4 KiB
TypeScript

import { promises as fs } from "fs";
import path from "node:path";
import iconv from "iconv-lite";
import { convert } from ".";
import assert from "node:assert";
import * as Diff from "diff";
describe("mt940 converter", () => {
it("converts properly", async () => {
const content = await fs.readFile(
path.resolve(__dirname, "../tests/real_csv.csv"),
{
encoding: null,
}
);
const result = convert(iconv.decode(content, "cp1250"));
const expected_result = await fs.readFile(
path.resolve(__dirname, "../tests/real_mt940.txt"),
"utf-8"
);
try {
assert.strictEqual(result.output, expected_result);
} catch (e) {
console.error("There was a difference. Fixes to apply:");
console.log(
Diff.createPatch("mt940", result.output, expected_result)
);
throw new Error("Texts differ");
}
});
it.only("converts properly", async () => {
const content = await fs.readFile(
path.resolve(__dirname, "../tests/real_csv_2.csv"),
{
encoding: null,
}
);
const result = convert(iconv.decode(content, "cp1250"));
const expected_result = await fs.readFile(
path.resolve(__dirname, "../tests/real_mt940_2.txt"),
"utf-8"
);
try {
assert.strictEqual(result.output, expected_result);
} catch (e) {
console.error("There was a difference. Fixes to apply:");
console.log(
Diff.createPatch("mt940", result.output, expected_result)
);
throw new Error("Texts differ");
}
});
});