This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/notifications/templates_test.go
Jeffrey Smith 11fd8c1e57 step 1: rename module chat-switchboard → switchboard-core
- go.mod module name
- All 714 import references across 289 Go files
- VERSION: 0.1.0
- CI DB names: switchboard_core_{ci,dev,test}
- Docker image: gobha/switchboard-core
- Test fixtures: JWT issuer, repo names
- .env.example, docker-compose container name
- Compiles clean (go build exit 0)
2026-03-25 19:48:04 -04:00

70 lines
1.8 KiB
Go

package notifications
import (
"strings"
"testing"
"switchboard-core/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)
}
}
}