send_email_integration_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package notifications
  2. import (
  3. "io/ioutil"
  4. "testing"
  5. "github.com/grafana/grafana/pkg/bus"
  6. m "github.com/grafana/grafana/pkg/models"
  7. "github.com/grafana/grafana/pkg/setting"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestEmailIntegrationTest(t *testing.T) {
  11. SkipConvey("Given the notifications service", t, func() {
  12. bus.ClearBusHandlers()
  13. setting.StaticRootPath = "../../../public/"
  14. setting.Smtp.Enabled = true
  15. setting.Smtp.TemplatesPattern = "emails/*.html"
  16. setting.Smtp.FromAddress = "from@address.com"
  17. err := Init()
  18. So(err, ShouldBeNil)
  19. var sentMsg *Message
  20. addToMailQueue = func(msg *Message) {
  21. sentMsg = msg
  22. ioutil.WriteFile("../../../tmp/test_email.html", []byte(msg.Body), 0777)
  23. }
  24. Convey("When sending reset email password", func() {
  25. cmd := &m.SendEmailCommand{
  26. Data: map[string]interface{}{
  27. "Name": "Name",
  28. "State": "Critical",
  29. "Description": "Description",
  30. "DashboardLink": "http://localhost:3000/dashboard/db/alerting",
  31. "AlertPageUrl": "http://localhost:3000/alerting",
  32. "DashboardImage": "http://localhost:3000/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=3&width=1000&height=500",
  33. "TriggeredAlerts": []testTriggeredAlert{
  34. {Name: "desktop", State: "Critical", ActualValue: 13},
  35. {Name: "mobile", State: "Warn", ActualValue: 5},
  36. },
  37. },
  38. To: []string{"asd@asd.com "},
  39. Template: "alert_notification.html",
  40. }
  41. err := sendEmailCommandHandler(cmd)
  42. So(err, ShouldBeNil)
  43. })
  44. })
  45. }