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