Skip to content

Commit 0ab597d

Browse files
committed
Fix unit tests, add joinParts utility
1 parent 7d21c46 commit 0ab597d

3 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/pdfs/ri/pc8.1-change-of-name/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { formatBirthplaceCountryOrState } from "../../../utils/formatBirthplaceCountryOrState";
22
import { formatDateMMDDYYYY } from "../../../utils/formatDateMMDDYYYY";
33
import { joinNames } from "../../../utils/joinNames";
4+
import { joinParts } from "../../../utils/joinParts";
45
import { definePdf } from "../../utils/definePdf";
56
import pdf from "./pc8.1-change-of-name.pdf";
67
import type { PdfFieldName } from "./schema";
@@ -24,29 +25,25 @@ export default definePdf<PdfFieldName>({
2425
residenceZipCode: data.residenceZipCode,
2526
phoneNumber: data.phoneNumber,
2627
mailingStreetAddress: data.mailingStreetAddress,
27-
mailingCityStateAndZip: [
28+
mailingCityStateAndZip: joinParts(
2829
data.mailingCity,
2930
data.mailingState,
3031
data.mailingZipCode,
31-
]
32-
.filter(Boolean)
33-
.join(", "),
32+
),
3433
email: data.email,
3534
nameOnOriginalBirthRecord: joinNames(
3635
data.oldFirstName,
3736
data.oldMiddleName,
3837
data.oldLastName,
3938
),
4039
dateOfBirth: formatDateMMDDYYYY(data.dateOfBirth),
41-
placeOfBirth: [
40+
placeOfBirth: joinParts(
4241
data.birthplaceCity,
4342
formatBirthplaceCountryOrState(
4443
data.birthplaceCountry,
4544
data.birthplaceState,
4645
),
47-
]
48-
.filter(Boolean)
49-
.join(", "),
46+
),
5047
mothersMaidenName: joinNames(
5148
data.mothersFirstName,
5249
data.mothersMiddleName,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, expect, it } from "vitest";
2+
import { joinParts } from "../joinParts";
3+
4+
describe("joinParts", () => {
5+
it("joins all parts with a comma", () => {
6+
expect(joinParts("Providence", "RI", "02903")).toBe("Providence, RI, 02903");
7+
});
8+
9+
it("filters out undefined values", () => {
10+
expect(joinParts("Providence", undefined, "02903")).toBe("Providence, 02903");
11+
});
12+
13+
it("returns undefined when all values are undefined", () => {
14+
expect(joinParts(undefined, undefined, undefined)).toBeUndefined();
15+
});
16+
17+
it("returns undefined when called with no arguments", () => {
18+
expect(joinParts()).toBeUndefined();
19+
});
20+
21+
it("returns a single value without a trailing comma", () => {
22+
expect(joinParts(undefined, "RI", undefined)).toBe("RI");
23+
});
24+
});

src/utils/joinParts.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const joinParts = (...parts: (string | undefined)[]): string | undefined => {
2+
const result = parts.filter(Boolean).join(", ");
3+
return result || undefined;
4+
};

0 commit comments

Comments
 (0)