Skip to content

Commit 5ee1633

Browse files
committed
tests: Add tests for adaptReplyToRecipient function to validate recipient handling
1 parent 7e6376f commit 5ee1633

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/__tests__/adapters/recipients.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import adaptRecipients, {
22
adaptSingleRecipient,
3+
adaptReplyToRecipient,
34
} from "../../adapters/recipients";
45

56
describe("adapters/recipients: ", () => {
@@ -85,4 +86,60 @@ describe("adapters/recipients: ", () => {
8586
expect(result).toEqual(expectedResult);
8687
});
8788
});
89+
90+
describe("adaptReplyToRecipient(): ", () => {
91+
it("returns undefined if recipients is invalid.", () => {
92+
const recipients = undefined;
93+
94+
const expectedResult = undefined;
95+
const result = adaptReplyToRecipient(recipients);
96+
97+
expect(result).toEqual(expectedResult);
98+
});
99+
100+
it("returns undefined if recipients is empty array.", () => {
101+
const recipients: any = [];
102+
103+
const expectedResult = undefined;
104+
const result = adaptReplyToRecipient(recipients);
105+
106+
expect(result).toEqual(expectedResult);
107+
});
108+
109+
it("returns adapted recipients if it's not an array.", () => {
110+
const recipients = {
111+
name: "mock-name",
112+
address: "mock-email",
113+
};
114+
115+
const expectedResult = {
116+
name: recipients.name,
117+
email: recipients.address,
118+
};
119+
const result = adaptReplyToRecipient(recipients);
120+
121+
expect(result).toEqual(expectedResult);
122+
});
123+
124+
it("returns first adapted recipient if it's an array.", () => {
125+
const recipients = [
126+
{
127+
name: "mock-name-1",
128+
address: "mock-email-1",
129+
},
130+
{
131+
name: "mock-name-2",
132+
address: "mock-email-2",
133+
},
134+
];
135+
136+
const expectedResult = {
137+
name: recipients[0].name,
138+
email: recipients[0].address,
139+
};
140+
const result = adaptReplyToRecipient(recipients);
141+
142+
expect(result).toEqual(expectedResult);
143+
});
144+
});
88145
});

0 commit comments

Comments
 (0)