notifications_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. func TestNotifications(t *testing.T) {
  10. Convey("Given the notifications service", t, func() {
  11. setting.StaticRootPath = "../../../public/"
  12. ns := &NotificationService{}
  13. ns.Bus = bus.New()
  14. ns.Cfg = setting.NewCfg()
  15. ns.Cfg.Smtp.Enabled = true
  16. ns.Cfg.Smtp.TemplatesPattern = "emails/*.html"
  17. ns.Cfg.Smtp.FromAddress = "from@address.com"
  18. ns.Cfg.Smtp.FromName = "Grafana Admin"
  19. err := ns.Init()
  20. So(err, ShouldBeNil)
  21. Convey("When sending reset email password", func() {
  22. err := ns.sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
  23. So(err, ShouldBeNil)
  24. sentMsg := <-ns.mailQueue
  25. So(sentMsg.Body, ShouldContainSubstring, "body")
  26. So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password - asd@asd.com")
  27. So(sentMsg.Body, ShouldNotContainSubstring, "Subject")
  28. })
  29. })
  30. }