notifications_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package notifications
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/bus"
  5. m "github.com/grafana/grafana/pkg/models"
  6. "github.com/grafana/grafana/pkg/setting"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. type testTriggeredAlert struct {
  10. ActualValue float64
  11. Name string
  12. State string
  13. }
  14. func TestNotifications(t *testing.T) {
  15. Convey("Given the notifications service", t, func() {
  16. bus.ClearBusHandlers()
  17. setting.StaticRootPath = "../../../public/"
  18. setting.Smtp.Enabled = true
  19. setting.Smtp.TemplatesPattern = "emails/*.html"
  20. setting.Smtp.FromAddress = "from@address.com"
  21. err := Init()
  22. So(err, ShouldBeNil)
  23. var sentMsg *Message
  24. addToMailQueue = func(msg *Message) {
  25. sentMsg = msg
  26. }
  27. Convey("When sending reset email password", func() {
  28. err := sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
  29. So(err, ShouldBeNil)
  30. So(sentMsg.Body, ShouldContainSubstring, "body")
  31. So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password - asd@asd.com")
  32. So(sentMsg.Body, ShouldNotContainSubstring, "Subject")
  33. })
  34. })
  35. }