Skip to content

Commit

Permalink
feat/change-sentences-in-claim-pdf: change two sentences in pdf (#1507)
Browse files Browse the repository at this point in the history
* feat/change-sentences-in-claim-pdf: change two sentences in pdf

* feat/change-sentences-in-claim-pdf: adapt agreement sentence on video trial depending on user answer

Co-authored-by: flo drews <[email protected]>

* ref: outsource addDefendantPartyList for simplify createStatement function and for easier testing

* ref(fgr pdf): move const margin_right to configuration

* ref(fgr pdf): remove width from text

* ref(fgr pdf): remove redundant test

* ref(fgr pdf): add statementClaimSect into addDefendantPartyList

---------

Co-authored-by: flo drews <[email protected]>
  • Loading branch information
judithmh and m0dh4x authored Dec 4, 2024
1 parent 77d7280 commit 65c550d
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 94 deletions.
1 change: 1 addition & 0 deletions app/domains/fluggastrechte/services/pdf/configurations.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const MARGIN_BETWEEN_SECTIONS = 1.5;
export const MARGIN_RIGHT = 10;
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,25 @@ import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/con
import { getTotalCompensationClaim } from "~/domains/fluggastrechte/formular/services/getTotalCompensationClaim";
import { userDataMock } from "~/domains/fluggastrechte/services/pdf/__test__/userDataMock";
import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument";
import { addDefendantPartyList } from "../claimData/addDefendantPartyList";
import {
createStatementClaim,
STATEMENT_CLAIM_AGREEMENT_SENTENCE,
STATEMENT_CLAIM_COURT_SENTENCE,
STATEMENT_CLAIM_SUBTITLE_TEXT,
STATEMENT_CLAIM_TITLE_TEXT,
getDefendantPartyList,
} from "../createStatementClaim";

function assertDefendantPartyList(
mockDoc: PDFKit.PDFDocument,
defendantPartyList: Record<string, string>,
) {
for (const [bullet, claim] of Object.entries(defendantPartyList)) {
expect(mockDoc.text).toHaveBeenCalledWith(bullet, 80, undefined, {
continued: true,
});
expect(mockDoc.text).toHaveBeenCalledWith(claim, { width: 500 });
}
}
const STATEMENT_VIDEO_TRIAL_AGREEMENT =
"Ich stimme der Durchführung einer Videoverhandlung (§ 128a ZPO) zu.";
const STATEMENT_VIDEO_TRIAL_NO_AGREEMENT =
"Ich stimme der Durchführung einer Videoverhandlung (§ 128a ZPO) nicht zu.";

describe("createStatementClaim", () => {
beforeEach(() => {
vi.mock(
"~/domains/fluggastrechte/formular/services/getTotalCompensationClaim",
);
vi.mock("../claimData/addDefendantPartyList");
vi.mocked(getTotalCompensationClaim).mockReturnValue(600);
});

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

const compensation = getTotalCompensationClaim({
startAirport: userDataMock.startAirport,
endAirport: userDataMock.endAirport,
});

const defendantPartyList = getDefendantPartyList(
userDataMock.prozesszinsen,
compensation,
);

assertDefendantPartyList(mockDoc, defendantPartyList);
});

it("should create a list structure with list items", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

createStatementClaim(mockDoc, mockStruct, userDataMock);

expect(mockDoc.struct).toHaveBeenCalledWith("L");
expect(mockDoc.struct).toHaveBeenCalledWith("LI", {}, expect.any(Function));

const defendantPartyList = getDefendantPartyList(
expect(addDefendantPartyList).toHaveBeenCalledWith(
mockDoc,
mockStruct,
userDataMock.prozesszinsen,
600,
);
assertDefendantPartyList(mockDoc, defendantPartyList);
});

describe("createStatementClaim - versaeumnisurteil logic", () => {
Expand Down Expand Up @@ -123,15 +95,47 @@ describe("createStatementClaim", () => {
PDF_MARGIN_HORIZONTAL,
);
});
});

describe("createStatementClaim - videoverhandlung logic", () => {
it("should include videoverhandlung sentence when videoverhandlung is yes", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

const userDataMockWithVersaeumnisurteil = {
...userDataMock,
videoverhandlung: "yes",
} satisfies FluggastrechtContext;

createStatementClaim(
mockDoc,
mockStruct,
userDataMockWithVersaeumnisurteil,
);

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

it("should include agreement sentence regardless of versaeumnisurteil", () => {
it("should not include videoverhandlung sentence when videoverhandlung is no", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

createStatementClaim(mockDoc, mockStruct, userDataMock);
const userDataMockWithoutVersaeumnisurteil = {
...userDataMock,
videoverhandlung: "no",
} satisfies FluggastrechtContext;

createStatementClaim(
mockDoc,
mockStruct,
userDataMockWithoutVersaeumnisurteil,
);

expect(mockDoc.text).toHaveBeenCalledWith(
STATEMENT_CLAIM_AGREEMENT_SENTENCE,
STATEMENT_VIDEO_TRIAL_NO_AGREEMENT,
PDF_MARGIN_HORIZONTAL,
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
mockPdfKitDocument,
mockPdfKitDocumentStructure,
} from "tests/factories/mockPdfKit";
import { MARGIN_RIGHT } from "~/domains/fluggastrechte/services/pdf/configurations";
import {
FONTS_BUNDESSANS_BOLD,
FONTS_BUNDESSANS_REGULAR,
PDF_MARGIN_HORIZONTAL,
} from "~/services/pdf/createPdfKitDocument";
import { addDefendantPartyList } from "../addDefendantPartyList";

describe("addDefendantPartyList", () => {
it("should create document with defendant party list when litigation interest is requested", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addDefendantPartyList(mockDoc, mockStruct, "yes", 600);

expect(mockDoc.font).toHaveBeenCalledWith(FONTS_BUNDESSANS_BOLD);
expect(mockDoc.text).toHaveBeenCalledWith(
"1. ",
PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT,
undefined,
{ continued: true },
);
expect(mockDoc.font).toHaveBeenCalledWith(FONTS_BUNDESSANS_REGULAR);
expect(mockDoc.text).toHaveBeenCalledWith(
"Die beklagte Partei wird verurteilt, an die klagende Partei 600 € nebst Zinsen in Höhe von 5 Prozentpunkten über dem jeweiligen Basiszinssatz seit Rechtshängigkeit zu zahlen.",
);
expect(mockDoc.text).toHaveBeenCalledWith(
"2. ",
PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT,
undefined,
{ continued: true },
);
expect(mockDoc.font).toHaveBeenCalledWith(FONTS_BUNDESSANS_REGULAR);
expect(mockDoc.text).toHaveBeenCalledWith(
"Die beklagte Partei trägt die Kosten des Rechtsstreits.",
);
});

it("should create document with defendant party list when litigation interest is not requested", () => {
const mockStruct = mockPdfKitDocumentStructure();
const mockDoc = mockPdfKitDocument(mockStruct);

addDefendantPartyList(mockDoc, mockStruct, "no", 600);

expect(mockDoc.font).toHaveBeenCalledWith(FONTS_BUNDESSANS_BOLD);
expect(mockDoc.text).toHaveBeenCalledWith(
"1. ",
PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT,
undefined,
{ continued: true },
);
expect(mockDoc.font).toHaveBeenCalledWith(FONTS_BUNDESSANS_REGULAR);
expect(mockDoc.text).toHaveBeenCalledWith(
"Die beklagte Partei wird verurteilt, an die klagende Partei 600 € zu zahlen.",
);
expect(mockDoc.text).toHaveBeenCalledWith(
"2. ",
PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT,
undefined,
{ continued: true },
);
expect(mockDoc.font).toHaveBeenCalledWith(FONTS_BUNDESSANS_REGULAR);
expect(mockDoc.text).toHaveBeenCalledWith(
"Die beklagte Partei trägt die Kosten des Rechtsstreits.",
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type PDFDocument from "pdfkit";
import { MARGIN_RIGHT } from "~/domains/fluggastrechte/services/pdf/configurations";
import {
FONTS_BUNDESSANS_BOLD,
FONTS_BUNDESSANS_REGULAR,
PDF_MARGIN_HORIZONTAL,
} from "~/services/pdf/createPdfKitDocument";

export const addDefendantPartyList = (
doc: typeof PDFDocument,
statementClaimSect: PDFKit.PDFStructureElement,
prozesszinsen: string,
streitwert: number,
) => {
const interestClause =
prozesszinsen === "yes"
? " nebst Zinsen in Höhe von 5 Prozentpunkten über dem jeweiligen Basiszinssatz seit Rechtshängigkeit"
: "";

const defendantPartyList = {
"1. ": `Die beklagte Partei wird verurteilt, an die klagende Partei ${streitwert}${interestClause} zu zahlen.`,
"2. ": "Die beklagte Partei trägt die Kosten des Rechtsstreits.",
};

const statementClaimList = doc.struct("L");

for (const [bullet, claim] of Object.entries(defendantPartyList)) {
statementClaimList.add(
doc.struct("LI", {}, () => {
doc
.font(FONTS_BUNDESSANS_BOLD)
.text(bullet, PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT, undefined, {
continued: true,
})
.font(FONTS_BUNDESSANS_REGULAR)
.text(claim);
doc.moveDown(0.5);
}),
);
}

statementClaimSect.add(statementClaimList);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,26 @@ import {
FONTS_BUNDESSANS_REGULAR,
PDF_MARGIN_HORIZONTAL,
} from "~/services/pdf/createPdfKitDocument";

export const getDefendantPartyList = (
prozesszinsen: string,
streitwert: number,
): Record<string, string> => {
const interestClause =
prozesszinsen === "yes"
? " nebst Zinsen in Höhe von 5 Prozentpunkten über dem jeweiligen Basiszinssatz seit Rechtshängigkeit"
: "";

return {
"1. ": `Die beklagte Partei zu verurteilen, an die klagende Partei ${streitwert}${interestClause} zu zahlen.`,
"2. ": "Die beklagte Partei trägt die Kosten des Rechtsstreits.",
};
};
import { addDefendantPartyList } from "./claimData/addDefendantPartyList";

export const STATEMENT_CLAIM_TITLE_TEXT = "Klageantrag";
export const STATEMENT_CLAIM_SUBTITLE_TEXT = "Es wird beantragt,";
export const STATEMENT_CLAIM_SUBTITLE_TEXT =
"Es werden folgende Anträge gestellt:";
export const STATEMENT_CLAIM_COURT_SENTENCE =
"Sofern die gesetzlichen Voraussetzungen vorliegen, wird hiermit der Erlass eines Versäumnisurteils gem. § 331 Abs. 1 und Abs. 3 ZPO gestellt.";
export const STATEMENT_CLAIM_AGREEMENT_SENTENCE =
"Mit einer Entscheidung im schriftlichen Verfahren ohne mündliche Verhandlung (§ 128 Abs. 2 ZPO) sowie der Durchführung einer Videoverhandlung (§ 128a ZPO) bin ich einverstanden.";
export const MARGIN_RIGHT = 10;

const videoTrialAgreement = (videoverhandlung: string | undefined) => {
return `Ich stimme der Durchführung einer Videoverhandlung (§ 128a ZPO) ${videoverhandlung === "yes" ? "" : "nicht "}zu.`;
};

export const createStatementClaim = (
doc: typeof PDFDocument,
documentStruct: PDFKit.PDFStructureElement,
userData: FluggastrechtContext,
) => {
const { prozesszinsen, versaeumnisurteil } = userData;
const { prozesszinsen, versaeumnisurteil, videoverhandlung } = userData;
const compensationByDistance = getTotalCompensationClaim(userData);

const defendantPartyList = getDefendantPartyList(
prozesszinsen ?? "",
compensationByDistance,
);

const statementClaimSect = doc.struct("Sect");
statementClaimSect.add(
doc.struct("H2", {}, () => {
Expand All @@ -63,33 +46,20 @@ export const createStatementClaim = (
}),
);

const statementClaimList = doc.struct("L");

for (const [bullet, claim] of Object.entries(defendantPartyList)) {
statementClaimList.add(
doc.struct("LI", {}, () => {
doc
.font(FONTS_BUNDESSANS_BOLD)
.text(bullet, PDF_MARGIN_HORIZONTAL + MARGIN_RIGHT, undefined, {
continued: true,
})
.font(FONTS_BUNDESSANS_REGULAR)
.text(claim, { width: 500 });
doc.moveDown(0.5);
}),
);
}

statementClaimSect.add(statementClaimList);
addDefendantPartyList(
doc,
statementClaimSect,
prozesszinsen ?? "",
compensationByDistance,
);

statementClaimSect.add(
doc.struct("P", {}, () => {
if (versaeumnisurteil === "yes") {
doc.text(STATEMENT_CLAIM_COURT_SENTENCE, PDF_MARGIN_HORIZONTAL);
}
doc.text(STATEMENT_CLAIM_AGREEMENT_SENTENCE, PDF_MARGIN_HORIZONTAL);
doc.text(videoTrialAgreement(videoverhandlung), PDF_MARGIN_HORIZONTAL);
}),
);

documentStruct.add(statementClaimSect);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type PDFDocument from "pdfkit";
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";
import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations";
import {
MARGIN_BETWEEN_SECTIONS,
MARGIN_RIGHT,
} from "~/domains/fluggastrechte/services/pdf/configurations";
import {
FONTS_BUNDESSANS_BOLD,
FONTS_BUNDESSANS_REGULAR,
Expand All @@ -20,8 +23,6 @@ export const INFORMATION_BOOKING_AND_ASSIGNMENTS_ANNULLIERUNG_TEXT = `Für sämt
export const EVIDENCE_QUESTION_WITNESSES_TEXT =
"Beweis angeboten durch Vernehmung der folgenden Personen als Zeugen:";

export const MARGIN_RIGHT = 10;

export const addMultiplePersonsInfo = (
doc: typeof PDFDocument,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
mockPdfKitDocumentStructure,
} from "tests/factories/mockPdfKit";
import { userDataMock } from "~/domains/fluggastrechte/services/pdf/__test__/userDataMock";
import { MARGIN_RIGHT } from "~/domains/fluggastrechte/services/pdf/configurations";
import { PDF_MARGIN_HORIZONTAL } from "~/services/pdf/createPdfKitDocument";
import { YesNoAnswer } from "~/services/validation/YesNoAnswer";
import {
Expand All @@ -11,7 +12,6 @@ import {
ATTACHMENT_CONFIRM_BOOKING_TEXT,
CONFIRM_BOOKING_MULTIPLE_PERSONS_TEXT,
CONFIRM_BOOKING_TEXT,
MARGIN_RIGHT,
PLAINTIFF_ON_TIME_MULTIPLE_PERSONS_TEXT,
PLAINTIFF_ON_TIME_TEXT,
} from "../addDetailedReason";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type PDFDocument from "pdfkit";
import type { FluggastrechtContext } from "~/domains/fluggastrechte/formular/context";
import { MARGIN_BETWEEN_SECTIONS } from "~/domains/fluggastrechte/services/pdf/configurations";
import {
MARGIN_BETWEEN_SECTIONS,
MARGIN_RIGHT,
} from "~/domains/fluggastrechte/services/pdf/configurations";
import {
FONTS_BUNDESSANS_BOLD,
FONTS_BUNDESSANS_REGULAR,
Expand All @@ -20,7 +23,6 @@ export const PLAINTIFF_ON_TIME_TEXT =
"Die klagende Partei war pünktlich zum Check-in und Boarding.";
export const PLAINTIFF_ON_TIME_MULTIPLE_PERSONS_TEXT =
"Die klagende Partei und die weiteren Fluggäste waren pünktlich zum Check-in und Boarding.";
export const MARGIN_RIGHT = 10;

const getConfirmationBookingTexts = ({
isWeiterePersonen,
Expand Down
Loading

0 comments on commit 65c550d

Please sign in to comment.