mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: expose Markdown fields in webhook payload (#14931)
Fixes: https://github.com/coder/coder/issues/14930
This commit is contained in:
@ -28,17 +28,15 @@ func TestWebhook(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const (
|
||||
titleTemplate = "this is the title ({{.Labels.foo}})"
|
||||
bodyTemplate = "this is the body ({{.Labels.baz}})"
|
||||
titlePlaintext = "this is the title"
|
||||
titleMarkdown = "this *is* _the_ title"
|
||||
bodyPlaintext = "this is the body"
|
||||
bodyMarkdown = "~this~ is the `body`"
|
||||
)
|
||||
|
||||
msgPayload := types.MessagePayload{
|
||||
Version: "1.0",
|
||||
NotificationName: "test",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"baz": "quux",
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -61,6 +59,11 @@ func TestWebhook(t *testing.T) {
|
||||
assert.Equal(t, msgID, payload.MsgID)
|
||||
assert.Equal(t, msgID.String(), r.Header.Get("X-Message-Id"))
|
||||
|
||||
assert.Equal(t, titlePlaintext, payload.Title)
|
||||
assert.Equal(t, titleMarkdown, payload.TitleMarkdown)
|
||||
assert.Equal(t, bodyPlaintext, payload.Body)
|
||||
assert.Equal(t, bodyMarkdown, payload.BodyMarkdown)
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err = w.Write([]byte(fmt.Sprintf("received %s", payload.MsgID)))
|
||||
assert.NoError(t, err)
|
||||
@ -138,7 +141,7 @@ func TestWebhook(t *testing.T) {
|
||||
Endpoint: *serpent.URLOf(endpoint),
|
||||
}
|
||||
handler := dispatch.NewWebhookHandler(cfg, logger.With(slog.F("test", tc.name)))
|
||||
deliveryFn, err := handler.Dispatcher(msgPayload, titleTemplate, bodyTemplate)
|
||||
deliveryFn, err := handler.Dispatcher(msgPayload, titleMarkdown, bodyMarkdown)
|
||||
require.NoError(t, err)
|
||||
|
||||
retryable, err := deliveryFn(ctx, msgID)
|
||||
|
Reference in New Issue
Block a user