Files

60 lines
2.0 KiB
Go

package notify
import "testing"
import "codit/internal/models"
func TestGraphEndpoints(t *testing.T) {
var authority string
var graph string
authority, graph = graphEndpoints("commercial")
if authority != "login.microsoftonline.com" || graph != "graph.microsoft.com" {
t.Fatalf("commercial endpoints wrong: %s / %s", authority, graph)
}
authority, graph = graphEndpoints("gcc_high")
if authority != "login.microsoftonline.us" || graph != "graph.microsoft.us" {
t.Fatalf("gcc_high endpoints wrong: %s / %s", authority, graph)
}
authority, graph = graphEndpoints("china")
if authority != "login.chinacloudapi.cn" || graph != "microsoftgraph.chinacloudapi.cn" {
t.Fatalf("china endpoints wrong: %s / %s", authority, graph)
}
// Unknown / empty falls back to commercial.
authority, graph = graphEndpoints("")
if authority != "login.microsoftonline.com" || graph != "graph.microsoft.com" {
t.Fatalf("default endpoints wrong: %s / %s", authority, graph)
}
}
func TestBuildGraphSendMail(t *testing.T) {
var msg graphSendMail
msg = buildGraphSendMail(
models.Event{Title: "api.example.com is down", Body: "connection refused"},
[]string{"a@x.com", "b@y.com"},
)
if len(msg.Message.ToRecipients) != 2 {
t.Fatalf("expected 2 recipients, got %d", len(msg.Message.ToRecipients))
}
if msg.Message.ToRecipients[0].EmailAddress.Address != "a@x.com" {
t.Fatalf("unexpected recipient: %+v", msg.Message.ToRecipients[0])
}
if msg.Message.Subject != "api.example.com is down" {
t.Fatalf("unexpected subject: %q", msg.Message.Subject)
}
if msg.Message.Body.ContentType != "Text" || msg.Message.Body.Content != "connection refused" {
t.Fatalf("unexpected body: %+v", msg.Message.Body)
}
if msg.SaveToSentItems {
t.Fatalf("saveToSentItems should be false")
}
}
func TestBuildGraphSendMailFlattensSubjectNewlines(t *testing.T) {
var msg graphSendMail
msg = buildGraphSendMail(models.Event{Title: "line1\nline2", Body: "b"}, []string{"a@x.com"})
if msg.Message.Subject != "line1 line2" {
t.Fatalf("subject newline not flattened: %q", msg.Message.Subject)
}
}