Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package campaigns
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestLatestVersionsByCampaignIDsSQL_batchesDistinctOn(t *testing.T) {
|
|
if !strings.Contains(latestVersionsByCampaignIDsSQL, "DISTINCT ON (campaign_id)") {
|
|
t.Fatal("expected DISTINCT ON so each campaign gets one latest version")
|
|
}
|
|
if !strings.Contains(latestVersionsByCampaignIDsSQL, "ANY($1)") {
|
|
t.Fatal("expected ANY($1) batch filter over campaign IDs")
|
|
}
|
|
if !strings.Contains(latestVersionsByCampaignIDsSQL, "ORDER BY campaign_id, version DESC") {
|
|
t.Fatal("expected ORDER BY campaign_id, version DESC for DISTINCT ON")
|
|
}
|
|
}
|
|
|
|
func TestApplyVersionFields(t *testing.T) {
|
|
c := Campaign{ID: uuid.New()}
|
|
v := Version{
|
|
ID: uuid.New(),
|
|
Version: 3,
|
|
Subject: "Hello",
|
|
HTMLBody: "<p>Hi</p>",
|
|
PlainBody: "Hi",
|
|
}
|
|
applyVersionFields(&c, v)
|
|
if c.Subject != "Hello" || c.HTMLBody != "<p>Hi</p>" || c.PlainBody != "Hi" {
|
|
t.Fatalf("subject/body not applied: %+v", c)
|
|
}
|
|
if c.LatestVersion == nil || c.LatestVersion.Version != 3 {
|
|
t.Fatalf("LatestVersion not applied: %+v", c.LatestVersion)
|
|
}
|
|
}
|
|
|
|
func TestAttachLatestVersionsEmpty(t *testing.T) {
|
|
s := &Service{}
|
|
if err := s.attachLatestVersions(context.TODO(), nil); err != nil {
|
|
t.Fatalf("empty page should no-op: %v", err)
|
|
}
|
|
if err := s.attachLatestVersions(context.TODO(), []Campaign{}); err != nil {
|
|
t.Fatalf("empty slice should no-op: %v", err)
|
|
}
|
|
}
|