1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-09-15 18:56:59 +00:00

fix: improve discord webhook api conformance

This commit corrects some cases in the discord webhook payload that do
not align with the discord documentation

(cherry picked from commit 6ea6f224b8)
This commit is contained in:
Kidsan 2024-10-07 22:47:52 +02:00 committed by forgejo-backport-action
parent 2c0c6f408e
commit e2ffe12e50
5 changed files with 76 additions and 13 deletions

View file

@ -120,6 +120,49 @@ func TestDiscordPayload(t *testing.T) {
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
j, err := json.Marshal(pl)
require.NoError(t, err)
unsetFields := struct {
Content *string `json:"content"`
TTS *bool `json:"tts"`
Wait *bool `json:"wait"`
Fields []any `json:"fields"`
Footer struct {
Text *string `json:"text"`
} `json:"footer"`
}{}
err = json.Unmarshal(j, &unsetFields)
require.NoError(t, err)
assert.Nil(t, unsetFields.Content)
assert.Nil(t, unsetFields.TTS)
assert.Nil(t, unsetFields.Wait)
assert.Nil(t, unsetFields.Fields)
assert.Nil(t, unsetFields.Footer.Text)
})
t.Run("Issue with long title", func(t *testing.T) {
p := issueTestPayloadWithLongTitle()
p.Action = api.HookIssueOpened
pl, err := dc.Issue(p)
require.NoError(t, err)
assert.Len(t, pl.Embeds, 1)
assert.Len(t, pl.Embeds[0].Title, 256)
})
t.Run("Issue with long body", func(t *testing.T) {
p := issueTestPayloadWithLongBody()
p.Action = api.HookIssueOpened
pl, err := dc.Issue(p)
require.NoError(t, err)
assert.Len(t, pl.Embeds, 1)
assert.Len(t, pl.Embeds[0].Description, 4096)
})
t.Run("IssueComment", func(t *testing.T) {