2015-06-05 04:08:19 -05:00
|
|
|
package notifications
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-27 06:01:32 -05:00
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2015-06-05 04:08:19 -05:00
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
2016-06-17 08:30:17 -05:00
|
|
|
type testTriggeredAlert struct {
|
|
|
|
ActualValue float64
|
|
|
|
Name string
|
|
|
|
State string
|
|
|
|
}
|
|
|
|
|
2015-06-05 04:08:19 -05:00
|
|
|
func TestNotifications(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("Given the notifications service", t, func() {
|
|
|
|
setting.StaticRootPath = "../../../public/"
|
2015-06-08 11:25:04 -05:00
|
|
|
setting.Smtp.Enabled = true
|
|
|
|
setting.Smtp.TemplatesPattern = "emails/*.html"
|
2015-06-05 04:08:19 -05:00
|
|
|
setting.Smtp.FromAddress = "from@address.com"
|
2017-02-14 15:04:21 -06:00
|
|
|
setting.Smtp.FromName = "Grafana Admin"
|
2015-06-05 04:08:19 -05:00
|
|
|
|
2018-04-27 06:01:32 -05:00
|
|
|
ns := &NotificationService{}
|
|
|
|
ns.Bus = bus.New()
|
2015-06-05 04:08:19 -05:00
|
|
|
|
2018-04-27 06:01:32 -05:00
|
|
|
err := ns.Init()
|
|
|
|
So(err, ShouldBeNil)
|
2015-06-05 04:08:19 -05:00
|
|
|
|
|
|
|
Convey("When sending reset email password", func() {
|
2018-04-27 06:01:32 -05:00
|
|
|
err := ns.sendResetPasswordEmail(&m.SendResetPasswordEmailCommand{User: &m.User{Email: "asd@asd.com"}})
|
2015-06-08 11:25:04 -05:00
|
|
|
So(err, ShouldBeNil)
|
2018-04-27 06:01:32 -05:00
|
|
|
|
|
|
|
sentMsg := <-ns.mailQueue
|
2015-06-08 09:51:25 -05:00
|
|
|
So(sentMsg.Body, ShouldContainSubstring, "body")
|
2015-06-13 23:08:18 -05:00
|
|
|
So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password - asd@asd.com")
|
2015-06-08 09:51:25 -05:00
|
|
|
So(sentMsg.Body, ShouldNotContainSubstring, "Subject")
|
2015-06-05 04:08:19 -05:00
|
|
|
})
|
2016-06-17 08:30:17 -05:00
|
|
|
})
|
2015-06-05 04:08:19 -05:00
|
|
|
}
|