From 4c4164bb405b89f9fd0c3cf757a2509f304578eb Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 20 Jun 2016 07:49:08 +0200 Subject: [PATCH] test(alerting): adds test email creater --- .../send_email_integration_test.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pkg/services/notifications/send_email_integration_test.go diff --git a/pkg/services/notifications/send_email_integration_test.go b/pkg/services/notifications/send_email_integration_test.go new file mode 100644 index 00000000000..74e9cb5a68d --- /dev/null +++ b/pkg/services/notifications/send_email_integration_test.go @@ -0,0 +1,55 @@ +package notifications + +import ( + "io/ioutil" + "testing" + + "github.com/grafana/grafana/pkg/bus" + m "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/setting" + . "github.com/smartystreets/goconvey/convey" +) + +func TestEmailIntegrationTest(t *testing.T) { + SkipConvey("Given the notifications service", t, func() { + bus.ClearBusHandlers() + + setting.StaticRootPath = "../../../public/" + setting.Smtp.Enabled = true + setting.Smtp.TemplatesPattern = "emails/*.html" + setting.Smtp.FromAddress = "from@address.com" + + err := Init() + So(err, ShouldBeNil) + + var sentMsg *Message + addToMailQueue = func(msg *Message) { + sentMsg = msg + ioutil.WriteFile("../../../tmp/test_email.html", []byte(msg.Body), 0777) + } + + Convey("When sending reset email password", func() { + cmd := &m.SendEmailCommand{ + + Data: map[string]interface{}{ + "Name": "Name", + "State": "Critical", + "Description": "Description", + "DashboardLink": "http://localhost:3000/dashboard/db/alerting", + "AlertPageUrl": "http://localhost:3000/alerting", + "DashboardImage": "http://localhost:3000/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=3&width=1000&height=500", + + "TriggeredAlerts": []testTriggeredAlert{ + {Name: "desktop", State: "Critical", ActualValue: 13}, + {Name: "mobile", State: "Warn", ActualValue: 5}, + }, + }, + To: []string{"asd@asd.com "}, + Template: "alert_notification.html", + } + + err := sendEmailCommandHandler(cmd) + So(err, ShouldBeNil) + }) + }) +}