package luckygift import ( "context" "testing" "hyapp/pkg/appcode" domain "hyapp/services/activity-service/internal/domain/luckygift" ) func TestGetConfigReturnsPoolDefault(t *testing.T) { repository := &fakeLuckyGiftRepository{} service := New(repository) config, err := service.GetConfig(appcode.WithContext(context.Background(), "hyapp"), "pool_95") if err != nil { t.Fatalf("GetConfig returned error: %v", err) } if repository.getConfigCalls != 1 { t.Fatalf("expected repository to be called once, got %d", repository.getConfigCalls) } if config.PoolID != "pool_95" || config.GiftID != "pool_95" { t.Fatalf("expected pool config scope, got pool=%q gift=%q", config.PoolID, config.GiftID) } } func TestUpsertConfigPreservesPoolScope(t *testing.T) { repository := &fakeLuckyGiftRepository{} service := New(repository) config := DefaultConfig("hyapp", "pool_98") config.Enabled = true if _, err := service.UpsertConfig(appcode.WithContext(context.Background(), "hyapp"), config); err != nil { t.Fatalf("UpsertConfig returned error: %v", err) } if repository.upserted.PoolID != "pool_98" || repository.upserted.GiftID != "pool_98" { t.Fatalf("expected pool scope, got pool=%q gift=%q", repository.upserted.PoolID, repository.upserted.GiftID) } } type fakeLuckyGiftRepository struct { getConfigCalls int upserted domain.Config } func (r *fakeLuckyGiftRepository) GetLuckyGiftConfig(context.Context, string) (domain.Config, bool, error) { r.getConfigCalls++ return domain.Config{}, false, nil } func (r *fakeLuckyGiftRepository) UpsertLuckyGiftConfig(_ context.Context, config domain.Config, _ int64) (domain.Config, error) { r.upserted = config return config, nil } func (r *fakeLuckyGiftRepository) ListLuckyGiftConfigs(context.Context) ([]domain.Config, error) { return nil, nil } func (r *fakeLuckyGiftRepository) CheckLuckyGift(context.Context, domain.CheckCommand) (domain.CheckResult, error) { return domain.CheckResult{}, nil } func (r *fakeLuckyGiftRepository) ExecuteLuckyGiftDraw(context.Context, domain.DrawCommand, int64) (domain.DrawResult, error) { return domain.DrawResult{}, nil } func (r *fakeLuckyGiftRepository) ListLuckyGiftDraws(context.Context, domain.DrawQuery) ([]domain.DrawResult, int64, error) { return nil, 0, nil } func (r *fakeLuckyGiftRepository) GetLuckyGiftDrawSummary(context.Context, domain.DrawQuery) (domain.DrawSummary, error) { return domain.DrawSummary{}, nil }