notifications_test.go 1023 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. bus.ClearBusHandlers()
  12. setting.StaticRootPath = "../../../public/"
  13. setting.Smtp.Enabled = true
  14. setting.Smtp.TemplatesPattern = "emails/*.html"
  15. setting.Smtp.FromAddress = "from@address.com"
  16. err := Init()
  17. So(err, ShouldBeNil)
  18. var sentMsg *Message
  19. addToMailQueue = func(msg *Message) {
  20. sentMsg = msg
  21. }
  22. Convey("When sending reset email password", func() {
  23. err := sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
  24. So(err, ShouldBeNil)
  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. }