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

Pdf fluggastechte multi persons #1447

Merged
merged 19 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c058b2c
refactor(createStatementClaim): print total claim value
aaschlote Nov 18, 2024
8e34184
refactor(addPlannedFlightDetails): print total claim value
aaschlote Nov 18, 2024
744f9fd
refactor(addReason): print text for multiple persons
aaschlote Nov 18, 2024
df8bd15
refactor(addDetailedReason): print text for multiple persons
aaschlote Nov 18, 2024
9036ce3
refactor(getFullPlaintiffName): set parameter to get the full plainti…
aaschlote Nov 18, 2024
c5c2aa8
fix: call function getTotalCompensationClaim with correct parameters
aaschlote Nov 18, 2024
b0f6085
refactor(addDetailedReason): print text for multiple persons
aaschlote Nov 18, 2024
80f127d
refactor(addCompensationAmount): print text for multiple persons
aaschlote Nov 19, 2024
3aff082
refactor: jump to new page in case the table doesn't fit
aaschlote Nov 19, 2024
f6ef0c4
refactor(addMultiplePersonsInfo): print text for multiple persons
aaschlote Nov 19, 2024
880048d
refactor(addCompensationAmount): fix test for multi persons
aaschlote Nov 19, 2024
d038bf6
refactor(createLegalAssessment): fix amount value and jump to new page
aaschlote Nov 19, 2024
c6ac8b4
test: fix unit tests
aaschlote Nov 19, 2024
ac43cea
refactor(createFactsOfCases): increase margin top
aaschlote Nov 19, 2024
b143c01
test(addMultiplePersonsInfo): add unit test
aaschlote Nov 19, 2024
aa6161c
test(addDetailedReason): add unit test
aaschlote Nov 19, 2024
41ee763
Merge branch 'main' into pdf-fluggastechte-multi-persons
aaschlote Nov 19, 2024
b871373
refactor(addMultiplePersonsInfo): add condition for different bereich
aaschlote Nov 19, 2024
302994b
refactor(addDetailedReason): add missing address for multiple persons
aaschlote Nov 19, 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
@@ -1,49 +1,26 @@
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";
import { getFullPlaintiffName } from "../getFullPlaintiffName";

describe("getFullPlaintiffName", () => {
it("should return the full plaintiff name given the vorname and nachname", () => {
const userData: FluggastrechtContext = {
vorname: "Test",
nachname: "Test",
};

const actual = getFullPlaintiffName(userData);
const actual = getFullPlaintiffName(undefined, undefined, "Test", "Test");

expect(actual).toEqual("Test Test");
});

it("should return the full plaintiff name with capitalized vorname given the vorname lower case and nachname", () => {
const userData: FluggastrechtContext = {
vorname: "test",
nachname: "Test",
};

const actual = getFullPlaintiffName(userData);
const actual = getFullPlaintiffName(undefined, undefined, "test", "Test");

expect(actual).toEqual("Test Test");
});

it("should return the full plaintiff name given the title, vorname and nachname", () => {
const userData: FluggastrechtContext = {
title: "dr",
vorname: "Test",
nachname: "Test",
};

const actual = getFullPlaintiffName(userData);
const actual = getFullPlaintiffName(undefined, "dr", "Test", "Test");

expect(actual).toEqual("Dr. Test Test");
});

it("should return the full plaintiff name given the anrede, vorname and nachname", () => {
const userData: FluggastrechtContext = {
anrede: "Herr",
vorname: "Test",
nachname: "Test",
};

const actual = getFullPlaintiffName(userData);
const actual = getFullPlaintiffName("Herr", undefined, "Test", "Test");

expect(actual).toEqual("Herr Test Test");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
mockPdfKitDocumentStructure,
} from "tests/factories/mockPdfKit";
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";
import { getCompensationPayment } from "~/domains/fluggastrechte/services/airports/getCompensationPayment";
import { getTotalCompensationClaim } from "~/domains/fluggastrechte/formular/services/getTotalCompensationClaim";
import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument";
import {
createStatementClaim,
Expand All @@ -30,9 +30,9 @@ function assertDefendantPartyList(
describe("createStatementClaim", () => {
beforeEach(() => {
vi.mock(
"~/domains/fluggastrechte/services/airports/getCompensationPayment",
"~/domains/fluggastrechte/formular/services/getTotalCompensationClaim",
);
vi.mocked(getCompensationPayment).mockReturnValue("600");
vi.mocked(getTotalCompensationClaim).mockReturnValue(600);
});

afterEach(() => {
Expand All @@ -52,7 +52,7 @@ describe("createStatementClaim", () => {
expect(mockDoc.text).toHaveBeenCalledWith(STATEMENT_CLAIM_TITLE_TEXT);
expect(mockDoc.text).toHaveBeenCalledWith(STATEMENT_CLAIM_SUBTITLE_TEXT);

const compensation = getCompensationPayment({
const compensation = getTotalCompensationClaim({
startAirport: userDataMock.startAirport,
endAirport: userDataMock.endAirport,
});
Expand All @@ -76,7 +76,7 @@ describe("createStatementClaim", () => {

const defendantPartyList = getDefendantPartyList(
userDataMock.prozesszinsen,
"600",
600,
);
assertDefendantPartyList(mockDoc, defendantPartyList);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
mockPdfKitDocument,
mockPdfKitDocumentStructure,
} from "tests/factories/mockPdfKit";
import { getCompensationPayment } from "~/domains/fluggastrechte/services/airports/getCompensationPayment";
import { getTotalCompensationClaim } from "~/domains/fluggastrechte/formular/services/getTotalCompensationClaim";
import {
addPlannedFlightDetails,
AFFECTED_FLIGHT_TEXT,
Expand All @@ -12,7 +12,7 @@ import {
PLANNED_DEPARTURE_DATE_TEXT,
} from "../addPlannedFlightDetails";

vi.mock("~/domains/fluggastrechte/services/airports/getCompensationPayment");
vi.mock("~/domains/fluggastrechte/formular/services/getTotalCompensationClaim");

describe("addPlannedFlightDetails", () => {
it("should create document with flight details", () => {
Expand All @@ -39,15 +39,12 @@ describe("addPlannedFlightDetails", () => {
it("should calculate compensation based on start and end airport", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);
const mockCompensation = "400";
vi.mocked(getCompensationPayment).mockReturnValue(mockCompensation);
const mockCompensation = 400;
vi.mocked(getTotalCompensationClaim).mockReturnValue(mockCompensation);

addPlannedFlightDetails(mockDoc, userDataMock);

expect(getCompensationPayment).toHaveBeenCalledWith({
startAirport: userDataMock.startAirport,
endAirport: userDataMock.endAirport,
});
expect(getTotalCompensationClaim).toHaveBeenCalled();
expect(mockDoc.text).toHaveBeenCalledWith(
`Streitwert: ${mockCompensation}€`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ export const SEPARATOR = " | ";

export const addPlaintiffDetails = (
doc: typeof PDFDocument,
userData: FluggastrechtContext,
{
anrede,
title,
vorname,
nachname,
strasseHausnummer,
telefonnummer,
plz,
ort,
}: FluggastrechtContext,
) => {
const plaintiffName = getFullPlaintiffName(userData);
const address = userData.strasseHausnummer ?? "";
const phoneNumber = userData.telefonnummer ?? "";
const zipCode = userData.plz ?? "";
const city = userData.ort ?? "";
const plaintiffName = getFullPlaintiffName(anrede, title, vorname, nachname);
const address = strasseHausnummer ?? "";
const phoneNumber = telefonnummer ?? "";
const zipCode = plz ?? "";
const city = ort ?? "";

doc
.fontSize(10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type PDFDocument from "pdfkit";
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";
import { getCompensationPayment } from "~/domains/fluggastrechte/services/airports/getCompensationPayment";
import { getTotalCompensationClaim } from "~/domains/fluggastrechte/formular/services/getTotalCompensationClaim";
import {
FONTS_BUNDESSANS_BOLD,
FONTS_BUNDESSANS_REGULAR,
Expand All @@ -17,11 +17,7 @@ export const addPlannedFlightDetails = (
doc: typeof PDFDocument,
userData: FluggastrechtContext,
) => {
const { startAirport, endAirport } = userData;
const compensationByDistance = getCompensationPayment({
startAirport,
endAirport,
});
const compensationByDistance = getTotalCompensationClaim(userData);
doc.fontSize(12).font(FONTS_BUNDESSANS_BOLD).text(DUE_REASON_TEXT);
doc.font(FONTS_BUNDESSANS_BOLD).text(AFFECTED_FLIGHT_TEXT);
doc.moveDown(0.5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type PDFDocument from "pdfkit";
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";
import { getCompensationPayment } from "~/domains/fluggastrechte/services/airports/getCompensationPayment";
import { getTotalCompensationClaim } from "~/domains/fluggastrechte/formular/services/getTotalCompensationClaim";
import {
FONTS_BUNDESSANS_BOLD,
FONTS_BUNDESSANS_REGULAR,
Expand All @@ -9,7 +9,7 @@ import {

export const getDefendantPartyList = (
prozesszinsen: string,
streitwert: string,
streitwert: number,
): Record<string, string> => {
const interestClause =
prozesszinsen === "yes"
Expand All @@ -35,12 +35,8 @@ export const createStatementClaim = (
documentStruct: PDFKit.PDFStructureElement,
userData: FluggastrechtContext,
) => {
const { startAirport, endAirport, prozesszinsen, versaeumnisurteil } =
userData;
const compensationByDistance = getCompensationPayment({
startAirport,
endAirport,
});
const { prozesszinsen, versaeumnisurteil } = userData;
const compensationByDistance = getTotalCompensationClaim(userData);

const defendantPartyList = getDefendantPartyList(
prozesszinsen ?? "",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import capitalize from "lodash/capitalize";
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";

export const getFullPlaintiffName = (userData: FluggastrechtContext) => {
const { anrede, title, vorname, nachname } = userData;

export const getFullPlaintiffName = (
anrede?: string,
title?: "" | "dr",
vorname?: string,
nachname?: string,
) => {
const mappedTitle = title === "dr" ? "Dr." : title;
const capitalizedVorname = capitalize(vorname);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const MAX_VERTICAL_SPACE = PDF_HEIGHT_SEIZE - 90;

export const addNewPageInCaseMissingVerticalSpace = (
doc: typeof PDFDocument,
extraYPosition = 0,
): void => {
if (doc.y >= MAX_VERTICAL_SPACE) {
if (doc.y + extraYPosition >= MAX_VERTICAL_SPACE) {
doc.addPage();
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ import {
DEMANDED_COMPENSATION_PAYMENT_TEXT,
OTHER_DETAILS_ITINERARY,
OTHER_PASSENGERS_DEMANDED_COMPENSATION_PAYMENT_TEXT,
PLAINTIFF_WITNESSES_MULTIPLE_PERSONS_TEXT,
PLAINTIFF_WITNESSES_TEXT,
} from "../addCompensationAmount";
import { addMultiplePersonsInfo } from "../addMultiplePersonsInfo";

vi.mock("~/domains/fluggastrechte/services/airports/getCompensationPayment");
vi.mock("~/domains/fluggastrechte/services/airports/getAirportNameByIataCode");
vi.mock(
"~/domains/fluggastrechte/services/airports/calculateDistanceBetweenAirports",
);
vi.mock("../../addNewPageInCaseMissingVerticalSpace");
vi.mock("../addMultiplePersonsInfo");

const distanceValueMock = 100;

Expand Down Expand Up @@ -137,7 +140,7 @@ describe("addCompensationAmount", () => {

const userDataWeiterePersonenMock = {
...userDataMock,
isWeiterePersonen: YesNoAnswer.Enum.yes,
isWeiterePersonen: YesNoAnswer.Enum.no,
};

addCompensationAmount(mockDoc, mockStruct, userDataWeiterePersonenMock, 0);
Expand All @@ -149,18 +152,58 @@ describe("addCompensationAmount", () => {
);
});

it("should have the text for plaintiff witnesses in case the hasZeugen is yes", () => {
it("should have the text distance airport for multiple persons", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataWeiterePersonenMock = {
...userDataMock,
isWeiterePersonen: YesNoAnswer.Enum.yes,
};

addCompensationAmount(mockDoc, mockStruct, userDataWeiterePersonenMock, 0);

expect(mockDoc.text).toHaveBeenCalledWith(
`Die Distanz zwischen ${startAirportMock} und ${endAirportMock} beträgt nach Großkreismethode ca. ${distanceValueMock} km. ${ARTICLE_AIR_PASSENGER_REGULATION_TEXT} ${compensationValueMock} € pro Person, insgesamt aus eigenem und abgetretenem Recht damit eine Gesamtsumme von ${compensationValueMock} €.`,
PDF_MARGIN_HORIZONTAL,
undefined,
);
});

it("should have the text for plaintiff witnesses in case the hasZeugen is yes and weitere person is no", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataHasZeugenMock = {
...userDataMock,
hasZeugen: YesNoAnswer.Enum.yes,
isWeiterePersonen: YesNoAnswer.Enum.no,
};

addCompensationAmount(mockDoc, mockStruct, userDataHasZeugenMock, 0);

expect(mockDoc.text).toHaveBeenCalledWith(
PLAINTIFF_WITNESSES_TEXT,
PDF_MARGIN_HORIZONTAL,
);
});

it("should have the text for plaintiff witnesses for multiple persons in case the hasZeugen and weitere personen is yes", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataHasZeugenMock = {
...userDataMock,
hasZeugen: YesNoAnswer.Enum.yes,
isWeiterePersonen: YesNoAnswer.Enum.yes,
};

addCompensationAmount(mockDoc, mockStruct, userDataHasZeugenMock, 0);

expect(mockDoc.text).toHaveBeenCalledWith(PLAINTIFF_WITNESSES_TEXT);
expect(mockDoc.text).toHaveBeenCalledWith(
PLAINTIFF_WITNESSES_MULTIPLE_PERSONS_TEXT,
PDF_MARGIN_HORIZONTAL,
);
});

it("should not have the text for plaintiff witnesses in case the hasZeugen is no", () => {
Expand All @@ -177,7 +220,7 @@ describe("addCompensationAmount", () => {
expect(mockDoc.text).not.toHaveBeenCalledWith(PLAINTIFF_WITNESSES_TEXT);
});

it("should call addNewPageInCaseMissingVerticalSpace three times in case the hasZeugen is yes ", () => {
it("should call addNewPageInCaseMissingVerticalSpace four times in case the hasZeugen is yes ", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

Expand All @@ -188,10 +231,24 @@ describe("addCompensationAmount", () => {

addCompensationAmount(mockDoc, mockStruct, userDataHasZeugenMock, 0);

expect(addNewPageInCaseMissingVerticalSpace).toBeCalledTimes(4);
});

it("should call addNewPageInCaseMissingVerticalSpace three times in case the hasZeugen is no", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataHasZeugenMock = {
...userDataMock,
hasZeugen: YesNoAnswer.Enum.no,
};

addCompensationAmount(mockDoc, mockStruct, userDataHasZeugenMock, 0);

expect(addNewPageInCaseMissingVerticalSpace).toBeCalledTimes(3);
});

it("should call addNewPageInCaseMissingVerticalSpace two times in case the hasZeugen is no", () => {
it("should call addMultiplePersonsInfo once", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

Expand All @@ -202,6 +259,6 @@ describe("addCompensationAmount", () => {

addCompensationAmount(mockDoc, mockStruct, userDataHasZeugenMock, 0);

expect(addNewPageInCaseMissingVerticalSpace).toBeCalledTimes(2);
expect(addMultiplePersonsInfo).toBeCalledTimes(1);
});
});
Loading
Loading