notifications_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. setting.StaticRootPath = "../../../public/"
  17. setting.Smtp.Enabled = true
  18. setting.Smtp.TemplatesPattern = "emails/*.html"
  19. setting.Smtp.FromAddress = "from@address.com"
  20. setting.Smtp.FromName = "Grafana Admin"
  21. ns := &NotificationService{}
  22. ns.Bus = bus.New()
  23. err := ns.Init()
  24. So(err, ShouldBeNil)
  25. Convey("When sending reset email password", func() {
  26. err := ns.sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
  27. So(err, ShouldBeNil)
  28. sentMsg := <-ns.mailQueue
  29. So(sentMsg.Body, ShouldContainSubstring, "body")
  30. So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password - asd@asd.com")
  31. So(sentMsg.Body, ShouldNotContainSubstring, "Subject")
  32. })
  33. })
  34. }