Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fluggastrechte pdf problems #1455

Merged
merged 21 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bc469c3
refactor(addReason): add missing comma
aaschlote Nov 20, 2024
2a28908
refactor(addDetailedReason): add space and extra word
aaschlote Nov 20, 2024
cf77190
refactor(addCompensationAmount): add missing s
aaschlote Nov 20, 2024
5085f91
refactor(createBankInformation): check if account holder has empty st…
aaschlote Nov 20, 2024
d9fda6f
test(createBankInformation): add test for empty space string
aaschlote Nov 20, 2024
8eecbcb
refactor: create subfolder compensationAmount
aaschlote Nov 20, 2024
77b93d6
refactor(addOtherDetailsItinerary): move to own function
aaschlote Nov 20, 2024
81983c6
test(addOtherDetailsItinerary): make eslint happy
aaschlote Nov 20, 2024
b2c8770
refactor(addWitnessesInfo): move to own function
aaschlote Nov 20, 2024
52a6c7b
refactor(addDistanceInfo): move to own function
aaschlote Nov 20, 2024
d2f0876
test(addWitnessesInfo): rename file
aaschlote Nov 20, 2024
0d3abd7
Merge branch 'main' into fix-fluggastrechte-pdf-problems
aaschlote Nov 20, 2024
b0072eb
Merge branch 'main' into fix-fluggastrechte-pdf-problems
aaschlote Nov 20, 2024
1cc6281
refactor(addTableInfo): move inside to addTable
aaschlote Nov 20, 2024
0a1b321
test(addTable): add unit test
aaschlote Nov 20, 2024
b097d13
refactor: set the width option when use doc.heightOfString
aaschlote Nov 20, 2024
a774bbb
refactor(addTableInfo): check when start to print table info
aaschlote Nov 20, 2024
b923836
Merge branch 'main' into fix-fluggastrechte-pdf-problems
aaschlote Nov 20, 2024
d4277d6
refactor(addTableInfo): add COLUMN_HEIGHT to calculate if jumps to a …
aaschlote Nov 20, 2024
9bc3682
Merge branch 'main' into fix-fluggastrechte-pdf-problems
aaschlote Nov 20, 2024
722c641
refactor: fix overlap gap
aaschlote Nov 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,46 @@ describe("createBankInformation", () => {
);
});

it("should default to vorname and nachname if account holder is empty string", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);
const userDataNoAccountHolder = {
...userDataMock,
kontoinhaber: "",
vorname: "Max",
nachname: "Mustermann",
};

createBankInformation(mockDoc, mockStruct, userDataNoAccountHolder);

expect(mockDoc.struct).toHaveBeenCalledWith("P", {}, expect.any(Function));
expect(mockDoc.text).toHaveBeenCalledWith(
"Kontoinhaber: Mustermann, Max | IBAN: DE68500123456789000000",
expect.anything(),
expect.anything(),
);
});

it("should default to vorname and nachname if account holder has empty space string", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);
const userDataNoAccountHolder = {
...userDataMock,
kontoinhaber: " ",
vorname: "Max",
nachname: "Mustermann",
};

createBankInformation(mockDoc, mockStruct, userDataNoAccountHolder);

expect(mockDoc.struct).toHaveBeenCalledWith("P", {}, expect.any(Function));
expect(mockDoc.text).toHaveBeenCalledWith(
"Kontoinhaber: Mustermann, Max | IBAN: DE68500123456789000000",
expect.anything(),
expect.anything(),
);
});

it("should not add bank information if IBAN is missing", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);
Expand Down Expand Up @@ -95,4 +135,32 @@ describe("createBankInformation", () => {
expect.anything(),
);
});

it("should not create document given undefined iban", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataWithoutIban = {
...userDataMock,
iban: undefined,
};

createBankInformation(mockDoc, mockStruct, userDataWithoutIban);

expect(mockDoc.text).not.toBeCalled();
});

it("should not create document given an empty iban", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataWithoutIban = {
...userDataMock,
iban: "",
};

createBankInformation(mockDoc, mockStruct, userDataWithoutIban);

expect(mockDoc.text).not.toBeCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
export const createBankInformation = (
doc: typeof PDFDocument,
footerSect: PDFKit.PDFStructureElement,
userData: FluggastrechtContext,
{ kontoinhaber, vorname, nachname, iban }: FluggastrechtContext,
) => {
const bankAccountHolder =
userData.kontoinhaber ?? `${userData.nachname}, ${userData.vorname}`;
typeof kontoinhaber !== "undefined" && kontoinhaber.trim().length > 0
? kontoinhaber
: `${nachname}, ${vorname}`;

if (userData?.iban) {
const bankInfo = `Kontoinhaber: ${bankAccountHolder} | IBAN: ${userData.iban}`;
if (iban) {
const bankInfo = `Kontoinhaber: ${bankAccountHolder} | IBAN: ${iban}`;
footerSect.add(
doc.struct("P", {}, () => {
doc
Expand Down

This file was deleted.

Loading
Loading