feat(form): add submission link webhook placeholder
This commit is contained in:
@@ -30,6 +30,9 @@ export function previewWebhookTemplate(
|
||||
const key = variable.toLowerCase();
|
||||
if (key === "username" || key === "displayname") return "Example User";
|
||||
if (key === "id") return "123456789";
|
||||
if (key === "link") {
|
||||
return "https://erika.sudloh.com/admin/form/example-form/result/example-submission";
|
||||
}
|
||||
if (key === "update") return "Question 1: Previous answer → Example answer";
|
||||
if (/^\d+$/.test(key)) return `Example answer ${key}`;
|
||||
return `{${variable}}`;
|
||||
|
||||
@@ -31,6 +31,7 @@ test("uses an image URL for image-only placeholders", () => {
|
||||
isUpdate: false,
|
||||
userName: "Gunshiz",
|
||||
discordId: "123",
|
||||
submissionLink: "https://erika.sudloh.com/admin/form/form-1/result/submission-1",
|
||||
questions,
|
||||
answers: [{
|
||||
questionId: "name",
|
||||
@@ -48,12 +49,26 @@ test("uses the configured template", () => {
|
||||
isUpdate: false,
|
||||
userName: "Gunshiz",
|
||||
discordId: "123",
|
||||
submissionLink: "https://erika.sudloh.com/admin/form/form-1/result/submission-1",
|
||||
questions,
|
||||
answers,
|
||||
oldAnswersByQuestionId: {},
|
||||
})).toBe("New answer: Erika by Gunshiz (123)");
|
||||
});
|
||||
|
||||
test("uses a submission result link placeholder", () => {
|
||||
expect(submissionWebhookMessage({
|
||||
template: "Review: {link}",
|
||||
isUpdate: false,
|
||||
userName: "Gunshiz",
|
||||
discordId: "123",
|
||||
submissionLink: "https://erika.sudloh.com/admin/form/form-1/result/submission-1",
|
||||
questions,
|
||||
answers,
|
||||
oldAnswersByQuestionId: {},
|
||||
})).toBe("Review: https://erika.sudloh.com/admin/form/form-1/result/submission-1");
|
||||
});
|
||||
|
||||
describe("default templates", () => {
|
||||
test("sends a new-submission message when its template is blank", () => {
|
||||
expect(submissionWebhookMessage({
|
||||
@@ -61,6 +76,7 @@ describe("default templates", () => {
|
||||
isUpdate: false,
|
||||
userName: "Gunshiz",
|
||||
discordId: "123",
|
||||
submissionLink: "https://erika.sudloh.com/admin/form/form-1/result/submission-1",
|
||||
questions,
|
||||
answers,
|
||||
oldAnswersByQuestionId: {},
|
||||
@@ -73,6 +89,7 @@ describe("default templates", () => {
|
||||
isUpdate: true,
|
||||
userName: "Gunshiz",
|
||||
discordId: "123",
|
||||
submissionLink: "https://erika.sudloh.com/admin/form/form-1/result/submission-1",
|
||||
questions,
|
||||
answers,
|
||||
oldAnswersByQuestionId: { name: "Old name" },
|
||||
|
||||
@@ -14,6 +14,7 @@ type SubmissionWebhookMessageOptions = {
|
||||
isUpdate: boolean;
|
||||
userName: string | null | undefined;
|
||||
discordId: string;
|
||||
submissionLink: string;
|
||||
questions: SubmissionQuestion[];
|
||||
answers: NormalizedSubmissionAnswer[];
|
||||
oldAnswersByQuestionId: OldAnswersByQuestionId;
|
||||
@@ -24,6 +25,7 @@ export function submissionWebhookMessage({
|
||||
isUpdate,
|
||||
userName,
|
||||
discordId,
|
||||
submissionLink,
|
||||
questions,
|
||||
answers,
|
||||
oldAnswersByQuestionId,
|
||||
@@ -43,6 +45,9 @@ export function submissionWebhookMessage({
|
||||
if (key === "id") {
|
||||
return discordId;
|
||||
}
|
||||
if (key === "link") {
|
||||
return submissionLink;
|
||||
}
|
||||
if (key === "update") {
|
||||
return updatesText;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user