Skip to content

Commit c6a2454

Browse files
committed
Added JSONPayload tests.
1 parent 7cc8554 commit c6a2454

File tree

8 files changed

+93
-2
lines changed

8 files changed

+93
-2
lines changed

services/webhook/dingtalk_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,16 @@ func TestDingTalkPayload(t *testing.T) {
193193
assert.Equal(t, "http://localhost:3000/api/v1/repos/test/repo/releases/2", pl.(*DingtalkPayload).ActionCard.SingleURL)
194194
})
195195
}
196+
197+
func TestDingTalkJSONPayload(t *testing.T) {
198+
p := pushTestPayload()
199+
200+
pl, err := new(DingtalkPayload).Push(p)
201+
require.NoError(t, err)
202+
require.NotNil(t, pl)
203+
require.IsType(t, &DingtalkPayload{}, pl)
204+
205+
json, err := pl.JSONPayload()
206+
require.NoError(t, err)
207+
assert.NotEmpty(t, json)
208+
}

services/webhook/discord_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,16 @@ func TestDiscordPayload(t *testing.T) {
230230
assert.Equal(t, p.Sender.AvatarURL, pl.(*DiscordPayload).Embeds[0].Author.IconURL)
231231
})
232232
}
233+
234+
func TestDiscordJSONPayload(t *testing.T) {
235+
p := pushTestPayload()
236+
237+
pl, err := new(DiscordPayload).Push(p)
238+
require.NoError(t, err)
239+
require.NotNil(t, pl)
240+
require.IsType(t, &DiscordPayload{}, pl)
241+
242+
json, err := pl.JSONPayload()
243+
require.NoError(t, err)
244+
assert.NotEmpty(t, json)
245+
}

services/webhook/feishu_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,16 @@ func TestFeishuPayload(t *testing.T) {
157157
assert.Equal(t, "[test/repo] Release created: v1.0 by user1", pl.(*FeishuPayload).Content.Text)
158158
})
159159
}
160+
161+
func TestFeishuJSONPayload(t *testing.T) {
162+
p := pushTestPayload()
163+
164+
pl, err := new(FeishuPayload).Push(p)
165+
require.NoError(t, err)
166+
require.NotNil(t, pl)
167+
require.IsType(t, &FeishuPayload{}, pl)
168+
169+
json, err := pl.JSONPayload()
170+
require.NoError(t, err)
171+
assert.NotEmpty(t, json)
172+
}

services/webhook/matrix_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ func TestMatrixPayload(t *testing.T) {
170170
})
171171
}
172172

173+
func TestMatrixJSONPayload(t *testing.T) {
174+
p := pushTestPayload()
175+
176+
pl, err := new(MatrixPayloadUnsafe).Push(p)
177+
require.NoError(t, err)
178+
require.NotNil(t, pl)
179+
require.IsType(t, &MatrixPayloadUnsafe{}, pl)
180+
181+
json, err := pl.JSONPayload()
182+
require.NoError(t, err)
183+
assert.NotEmpty(t, json)
184+
}
185+
173186
func TestMatrixHookRequest(t *testing.T) {
174187
h := &models.HookTask{
175188
PayloadContent: `{

services/webhook/msteams_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,16 @@ func TestMSTeamsPayload(t *testing.T) {
359359
assert.Equal(t, "http://localhost:3000/api/v1/repos/test/repo/releases/2", pl.(*MSTeamsPayload).PotentialAction[0].Targets[0].URI)
360360
})
361361
}
362+
363+
func TestMSTeamsJSONPayload(t *testing.T) {
364+
p := pushTestPayload()
365+
366+
pl, err := new(MSTeamsPayload).Push(p)
367+
require.NoError(t, err)
368+
require.NotNil(t, pl)
369+
require.IsType(t, &MSTeamsPayload{}, pl)
370+
371+
json, err := pl.JSONPayload()
372+
require.NoError(t, err)
373+
assert.NotEmpty(t, json)
374+
}

services/webhook/slack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (s *SlackPayload) Delete(p *api.DeletePayload) (api.Payloader, error) {
119119
refName := git.RefEndName(p.Ref)
120120
repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName)
121121
text := fmt.Sprintf("[%s:%s] %s deleted by %s", repoLink, refName, p.RefType, p.Sender.UserName)
122-
122+
123123
return s.createPayload(text, nil), nil
124124
}
125125

@@ -128,7 +128,7 @@ func (s *SlackPayload) Fork(p *api.ForkPayload) (api.Payloader, error) {
128128
baseLink := SlackLinkFormatter(p.Forkee.HTMLURL, p.Forkee.FullName)
129129
forkLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.FullName)
130130
text := fmt.Sprintf("%s is forked to %s", baseLink, forkLink)
131-
131+
132132
return s.createPayload(text, nil), nil
133133
}
134134

services/webhook/slack_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,16 @@ func TestSlackPayload(t *testing.T) {
157157
assert.Equal(t, "[<http://localhost:3000/test/repo|test/repo>] Release created: <http://localhost:3000/test/repo/src/v1.0|v1.0> by <https://try.gitea.io/user1|user1>", pl.(*SlackPayload).Text)
158158
})
159159
}
160+
161+
func TestSlackJSONPayload(t *testing.T) {
162+
p := pushTestPayload()
163+
164+
pl, err := new(SlackPayload).Push(p)
165+
require.NoError(t, err)
166+
require.NotNil(t, pl)
167+
require.IsType(t, &SlackPayload{}, pl)
168+
169+
json, err := pl.JSONPayload()
170+
require.NoError(t, err)
171+
assert.NotEmpty(t, json)
172+
}

services/webhook/telegram_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,16 @@ func TestTelegramPayload(t *testing.T) {
157157
assert.Equal(t, `[<a href="http://localhost:3000/test/repo">test/repo</a>] Release created: <a href="http://localhost:3000/test/repo/src/v1.0">v1.0</a> by <a href="https://try.gitea.io/user1">user1</a>`, pl.(*TelegramPayload).Message)
158158
})
159159
}
160+
161+
func TestTelegramJSONPayload(t *testing.T) {
162+
p := pushTestPayload()
163+
164+
pl, err := new(TelegramPayload).Push(p)
165+
require.NoError(t, err)
166+
require.NotNil(t, pl)
167+
require.IsType(t, &TelegramPayload{}, pl)
168+
169+
json, err := pl.JSONPayload()
170+
require.NoError(t, err)
171+
assert.NotEmpty(t, json)
172+
}

0 commit comments

Comments
 (0)