auth_cache_invalidation_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. //go:build unit
  2. package service
  3. import (
  4. "context"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestUsageService_InvalidateUsageCaches(t *testing.T) {
  9. invalidator := &authCacheInvalidatorStub{}
  10. svc := &UsageService{authCacheInvalidator: invalidator}
  11. svc.invalidateUsageCaches(context.Background(), 7, false)
  12. require.Empty(t, invalidator.userIDs)
  13. svc.invalidateUsageCaches(context.Background(), 7, true)
  14. require.Equal(t, []int64{7}, invalidator.userIDs)
  15. }
  16. func TestRedeemService_InvalidateRedeemCaches_AuthCache(t *testing.T) {
  17. invalidator := &authCacheInvalidatorStub{}
  18. svc := &RedeemService{authCacheInvalidator: invalidator}
  19. svc.invalidateRedeemCaches(context.Background(), 11, &RedeemCode{Type: RedeemTypeBalance})
  20. svc.invalidateRedeemCaches(context.Background(), 11, &RedeemCode{Type: RedeemTypeConcurrency})
  21. groupID := int64(3)
  22. svc.invalidateRedeemCaches(context.Background(), 11, &RedeemCode{Type: RedeemTypeSubscription, GroupID: &groupID})
  23. require.Equal(t, []int64{11, 11, 11}, invalidator.userIDs)
  24. }