51 lines
1011 B
Go
51 lines
1011 B
Go
package service
|
|
|
|
import (
|
|
"3588AdminBackend/internal/config"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestTemplateService(t *testing.T) {
|
|
// Ensure templates dir exists relative to test execution (which is internal/service)
|
|
_ = os.MkdirAll("templates", 0755)
|
|
|
|
// Create a dummy template for test
|
|
content := `{
|
|
"name": "test-template",
|
|
"schema": {},
|
|
"body": {}
|
|
}`
|
|
_ = os.WriteFile("templates/test-template.json", []byte(content), 0644)
|
|
defer os.RemoveAll("templates")
|
|
|
|
cfg := &config.Config{}
|
|
svc := NewTemplateService(cfg)
|
|
|
|
list, err := svc.ListTemplates()
|
|
if err != nil {
|
|
t.Fatalf("failed to list templates: %v", err)
|
|
}
|
|
|
|
found := false
|
|
for _, tpl := range list {
|
|
if tpl.Name == "test-template" {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
t.Error("expected test-template to be found")
|
|
}
|
|
|
|
tpl, err := svc.GetTemplate("test-template")
|
|
if err != nil {
|
|
t.Fatalf("failed to get template: %v", err)
|
|
}
|
|
|
|
if tpl.Name != "test-template" {
|
|
t.Errorf("expected test-template, got %s", tpl.Name)
|
|
}
|
|
}
|