2026-09-19 14:48:42 +02:00
|
|
|
package persistence
|
|
|
|
|
|
2026-09-19 16:45:24 +02:00
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/example/cms/internal/domain"
|
|
|
|
|
)
|
2026-09-19 14:48:42 +02:00
|
|
|
|
|
|
|
|
func TestModelsUseMigrationTableNames(t *testing.T) {
|
|
|
|
|
tests := map[string]string{
|
2026-09-19 16:45:24 +02:00
|
|
|
"content": (ContentModel{}).TableName(),
|
|
|
|
|
"content_history": (ContentHistoryModel{}).TableName(),
|
|
|
|
|
"categories": (CategoryModel{}).TableName(),
|
|
|
|
|
"badges": (BadgeModel{}).TableName(),
|
2026-09-19 14:48:42 +02:00
|
|
|
}
|
|
|
|
|
for expected, actual := range tests {
|
|
|
|
|
if actual != expected {
|
|
|
|
|
t.Errorf("table name = %q, want %q", actual, expected)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-19 16:45:24 +02:00
|
|
|
|
|
|
|
|
func TestContentMappingRoundTrip(t *testing.T) {
|
|
|
|
|
d := domain.Content{ID: 2, Slug: "hello-world", Title: "Hello", Body: "body", Status: "draft", Badges: []string{"go"}, CreatedAt: time.Now()}
|
|
|
|
|
got := ContentToDomain(ContentFromDomain(d))
|
|
|
|
|
if got.Slug != d.Slug || got.Title != d.Title || got.Status != d.Status {
|
|
|
|
|
t.Fatalf("round trip mismatch: %+v", got)
|
|
|
|
|
}
|
|
|
|
|
}
|