Changeset 0.20.0 (#85)
This commit is contained in:
69
server/notifications/templates_test.go
Normal file
69
server/notifications/templates_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/models"
|
||||
)
|
||||
|
||||
func TestRenderHTML_Basic(t *testing.T) {
|
||||
n := &models.Notification{
|
||||
Title: "KB Ready",
|
||||
Body: "Your knowledge base has been processed.",
|
||||
Type: "kb.ready",
|
||||
}
|
||||
html := RenderHTML(n, "TestInstance")
|
||||
if !strings.Contains(html, "KB Ready") {
|
||||
t.Error("expected title in HTML output")
|
||||
}
|
||||
if !strings.Contains(html, "TestInstance") {
|
||||
t.Error("expected instance name in HTML output")
|
||||
}
|
||||
if !strings.Contains(html, "knowledge base") {
|
||||
t.Error("expected body in HTML output")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderHTML_DefaultInstanceName(t *testing.T) {
|
||||
n := &models.Notification{Title: "Test"}
|
||||
html := RenderHTML(n, "")
|
||||
if !strings.Contains(html, "Chat Switchboard") {
|
||||
t.Error("expected default instance name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderText_Basic(t *testing.T) {
|
||||
n := &models.Notification{
|
||||
Title: "Model Fallback",
|
||||
Body: "GPT-4 fell back to GPT-3.5.",
|
||||
Type: "role.fallback",
|
||||
}
|
||||
text := RenderText(n, "MyInstance")
|
||||
if !strings.Contains(text, "Model Fallback") {
|
||||
t.Error("expected title in text output")
|
||||
}
|
||||
if !strings.Contains(text, "GPT-4 fell back") {
|
||||
t.Error("expected body in text output")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubjectForNotification(t *testing.T) {
|
||||
tests := []struct {
|
||||
notifType string
|
||||
title string
|
||||
want string
|
||||
}{
|
||||
{"kb.ready", "KB Processed", "[Test] Knowledge Base: KB Processed"},
|
||||
{"role.fallback", "Fallback", "[Test] Model Alert: Fallback"},
|
||||
{"grant.changed", "Added to team", "[Test] Access Change: Added to team"},
|
||||
{"custom.type", "Hello", "[Test] Hello"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
n := &models.Notification{Type: tt.notifType, Title: tt.title}
|
||||
got := SubjectForNotification(n, "Test")
|
||||
if got != tt.want {
|
||||
t.Errorf("SubjectForNotification(%q, %q) = %q, want %q", tt.notifType, tt.title, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user