notifications_test.go 943 B

12345678910111213141516171819202122232425262728293031323334353637
  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.FromAddress = "from@address.com"
  14. err := Init()
  15. So(err, ShouldBeNil)
  16. var sentMail *m.SendEmailCommand
  17. dispatchMail = func(cmd *m.SendEmailCommand) error {
  18. sentMail = cmd
  19. return nil
  20. }
  21. Convey("When sending reset email password", func() {
  22. sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
  23. So(sentMail.Body, ShouldContainSubstring, "body")
  24. So(sentMail.Subject, ShouldEqual, "Reset your Grafana password")
  25. So(sentMail.Body, ShouldNotContainSubstring, "Subject")
  26. })
  27. })
  28. }