mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-12-06 01:53:42 +01:00
27 lines
876 B
Go
27 lines
876 B
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/oapi-codegen/nullable"
|
|
)
|
|
|
|
func TestEffectiveTemplateIDFallsBackToCampaign(t *testing.T) {
|
|
campaignTemplate, own := uuid.New(), uuid.New()
|
|
campaign := &Campaign{TemplateID: nullable.NewNullableWithValue(campaignTemplate)}
|
|
|
|
legacy := &CampaignRecipient{}
|
|
legacy.TemplateID.SetNull()
|
|
if got, err := legacy.EffectiveTemplateID(campaign); err != nil || got != campaignTemplate {
|
|
t.Fatalf("null template: got %s %v, want campaign template", got, err)
|
|
}
|
|
stamped := &CampaignRecipient{TemplateID: nullable.NewNullableWithValue(own)}
|
|
if got, err := stamped.EffectiveTemplateID(campaign); err != nil || got != own {
|
|
t.Fatalf("stamped template: got %s %v, want own", got, err)
|
|
}
|
|
if _, err := legacy.EffectiveTemplateID(&Campaign{}); err == nil {
|
|
t.Fatal("no template anywhere should error")
|
|
}
|
|
}
|