Skip to content

Commit f259167

Browse files
committed
tests(firestore-send-email): refactor tests
1 parent 4021e36 commit f259167

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

firestore-send-email/functions/__tests__/validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ describe("validatePayload", () => {
615615
};
616616
expect(() => validatePayload(invalidPayload)).toThrow(ValidationError);
617617
expect(() => validatePayload(invalidPayload)).toThrow(
618-
"Invalid message configuration: Field 'message.attachments' must be an array"
618+
"Invalid message configuration: Field 'message.attachments' must be an array. If you have a single attachment object, wrap it in an array (e.g., [{ filename: '...', path: '...' }])"
619619
);
620620
});
621621
});

firestore-send-email/functions/src/validation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ function formatZodError(
193193
return `Field '${path}' must be a string`;
194194
}
195195
if (issue.expected === "array") {
196+
if (issue.message && !issue.message.startsWith("Expected")) {
197+
const customMessage = issue.message.replace(
198+
/Field 'attachments'/g,
199+
`Field '${path}'`
200+
);
201+
return customMessage;
202+
}
196203
return `Field '${path}' must be an array`;
197204
}
198205
if (issue.expected === "object") {

0 commit comments

Comments
 (0)