package notify import ( "context" "testing" ntf "github.com/go-pkgz/notify" "github.com/stretchr/testify/assert" "github.com/umputun/remark42/backend/app/store" ) func TestTelegram_NewError(t *testing.T) { tb, err := NewTelegram(TelegramParams{}) assert.Error(t, err) assert.Nil(t, tb) } func TestTelegram_Send(t *testing.T) { tb := Telegram{ AdminChannelID: "remark_test", UserNotifications: true, Telegram: &ntf.Telegram{}, // broken sender due to unset API } assert.Equal(t, "telegram notifications destination with admin notifications to remark_test with user notifications enabled", tb.String()) c := store.Comment{Text: "some text", ParentID: "1", ID: "999", PostTitle: "[test title]", Locator: store.Locator{URL: "http://example.org/"}} c.User.Name = "from" cp := store.Comment{Text: `
some parent text with a link and special text:
& < > &
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
}
res = tb.buildMessage(Request{Comment: c})
assert.Equal(t, `
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut...`, res)
}
func TestTelegram_SendVerification(t *testing.T) {
tb := Telegram{}
// empty VerificationRequest should return no error and do nothing, as well as any other
assert.NoError(t, tb.SendVerification(context.Background(), VerificationRequest{}))
}