Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/fints/src/__tests__/test-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Format } from "../format";

// FinTS 3.0 Formals TIME datatype (https://www.hbci-zka.de/downloads/FinTS_3_0/FinTS3.0_Formals_2010-12-20_final_version.pdf)
// specifies HHmmss with minutes rather than months.
describe("Format.time", () => {
it("formats hours, minutes, and seconds as HHmmss", () => {
const date = new Date(Date.UTC(2024, 11, 24, 8, 3, 45));
expect(Format.time(date)).toBe("080345");
});

it("does not substitute the month for minutes", () => {
const date = new Date(Date.UTC(2024, 5, 15, 12, 59, 1));
expect(Format.time(date)).toBe("125901");
});
});
4 changes: 2 additions & 2 deletions packages/fints/src/__tests__/test-pin-tan-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const productId = "fints";
let client: PinTanClient;

beforeEach(() => {
jest.spyOn(Format, "date").mockImplementation((date) => (date ? format(date, "HHMMss") : "20180101"));
jest.spyOn(Format, "time").mockImplementation((time) => (time ? format(time, "HHMMss") : "120000"));
jest.spyOn(Format, "date").mockImplementation((date) => (date ? format(date, "yyyyMMdd") : "20180101"));
jest.spyOn(Format, "time").mockImplementation((time) => (time ? format(time, "HHmmss") : "120000"));
Comment on lines 17 to +19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Refresh pin-tan snapshots for new time format

Switching the Format.date/time spies to format(..., "HHmmss") means the generated request payloads now encode minutes instead of months, but the stored snapshot in packages/fints/src/__tests__/__snapshots__/test-pin-tan-client.ts.snap still expects month-based values such as ...+N+120100+121000++. Running the existing test-pin-tan-client snapshot test will therefore fail until the snapshot (or the spy formatting) is updated to match the new HHmmss output.

Useful? React with 👍 / 👎.

jest.spyOn(Math, "random").mockReturnValue(0.5);
client = new PinTanClient({ blz, name, pin, url, productId });
});
Expand Down
3 changes: 2 additions & 1 deletion packages/fints/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export const Format = {
*/
time(date?: Date) {
const dateToFormat = date ? date : new Date();
return format(dateToFormat, "HHMMss");
// FinTS 3.0 Formals (TIME datatype) requires HHmmss with minutes, see https://www.hbci-zka.de/downloads/FinTS_3_0/FinTS3.0_Formals_2010-12-20_final_version.pdf.
return format(dateToFormat, "HHmmss");
},
/**
* Return an empty string.
Expand Down
Loading