forked from gotify/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessagehandler_test.go
More file actions
31 lines (23 loc) · 1002 Bytes
/
Copy pathmessagehandler_test.go
File metadata and controls
31 lines (23 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package plugin
import (
"testing"
"github.com/gotify/server/v2/plugin/compat"
"github.com/stretchr/testify/assert"
)
func TestRedirectToChannel_SendMessage_rejectsMissingApplication(t *testing.T) {
messages := make(chan MessageWithUserID, 1)
handler := redirectToChannel{ApplicationID: 0, UserID: 1, Messages: messages}
err := handler.SendMessage(compat.Message{Message: "orphan"})
assert.Error(t, err)
assert.Empty(t, messages, "no message should be queued when the internal application is missing")
}
func TestRedirectToChannel_SendMessage_forwardsWithApplication(t *testing.T) {
messages := make(chan MessageWithUserID, 1)
handler := redirectToChannel{ApplicationID: 7, UserID: 3, Messages: messages}
assert.NoError(t, handler.SendMessage(compat.Message{Message: "hi", Title: "t"}))
got := <-messages
assert.Equal(t, uint(7), got.Message.ApplicationID)
assert.Equal(t, uint(3), got.UserID)
assert.Equal(t, "hi", got.Message.Message)
assert.Equal(t, "t", got.Message.Title)
}