package subscriptions

import (
	"strconv"
	"testing"
	"time"

	"code.secondbit.org/uuid.hg"
)

const (
	subscriptionChangeStripeCustomer = 1 << iota
	subscriptionChangeAmount
	subscriptionChangePeriod
	subscriptionChangeBeginCharging
	subscriptionChangeLastCharged
	subscriptionChangeLastNotified
	subscriptionChangeInLockout
)

var testSubscriptionStores = []subscriptionStore{
	NewMemstore(),
}

func compareSubscriptions(sub1, sub2 Subscription) (bool, string, interface{}, interface{}) {
	if !sub1.ID.Equal(sub2.ID) {
		return false, "ID", sub1.ID, sub2.ID
	}
	if !sub1.UserID.Equal(sub2.UserID) {
		return false, "UserID", sub1.UserID, sub2.UserID
	}
	if sub1.StripeCustomer != sub2.StripeCustomer {
		return false, "StripeCustomer", sub1.StripeCustomer, sub2.StripeCustomer
	}
	if sub1.Amount != sub2.Amount {
		return false, "Amount", sub1.Amount, sub2.Amount
	}
	if sub1.Period != sub2.Period {
		return false, "Period", sub1.Period, sub2.Period
	}
	if !sub1.Created.Equal(sub2.Created) {
		return false, "Created", sub1.Created, sub2.Created
	}
	if !sub1.BeginCharging.Equal(sub2.BeginCharging) {
		return false, "BeginCharging", sub1.BeginCharging, sub2.BeginCharging
	}
	if !sub1.LastCharged.Equal(sub2.LastCharged) {
		return false, "LastCharged", sub1.LastCharged, sub2.LastCharged
	}
	if !sub1.LastNotified.Equal(sub2.LastNotified) {
		return false, "LastNotified", sub1.LastNotified, sub2.LastNotified
	}
	if sub1.InLockout != sub2.InLockout {
		return false, "InLockout", sub1.InLockout, sub2.InLockout
	}
	return true, "", nil, nil
}

func subscriptionMapContains(subscriptionMap map[string]Subscription, subscriptions ...Subscription) (bool, []Subscription) {
	var missing []Subscription
	for _, sub := range subscriptions {
		if _, ok := subscriptionMap[sub.ID.String()]; !ok {
			missing = append(missing, sub)
		}
	}
	if len(missing) > 0 {
		return false, missing
	}
	return true, missing
}

func TestCreateSubscription(t *testing.T) {
	for _, store := range testSubscriptionStores {
		err := store.reset()
		if err != nil {
			t.Fatalf("Error resetting %T: %+v\n", store, err)
		}
		customerID := uuid.NewID()
		sub := Subscription{
			ID:             uuid.NewID(),
			UserID:         customerID,
			StripeCustomer: "stripeCustomer1",
			Amount:         200,
			Period:         MonthlyPeriod,
			Created:        time.Now(),
			BeginCharging:  time.Now().Add(time.Hour),
		}
		err = store.createSubscription(sub)
		if err != nil {
			t.Errorf("Error creating subscription in %T: %+v\n", store, err)
		}
		retrieved, err := store.getSubscriptions([]uuid.ID{sub.ID})
		if err != nil {
			t.Errorf("Error retrieving subscription from %T: %+v\n", store, err)
		}
		if _, returned := retrieved[sub.ID.String()]; !returned {
			t.Errorf("Error retrieving subscription from %T: %s wasn't in the results.", store, sub.ID)
		}
		ok, field, expected, result := compareSubscriptions(sub, retrieved[sub.ID.String()])
		if !ok {
			t.Errorf("Expected %s to be %v, got %v from %T\n", field, expected, result, store)
		}
		err = store.createSubscription(sub)
		if err != ErrSubscriptionAlreadyExists {
			t.Errorf("Unexpected error creating subscription in %T (wanted %+v): %+v\n", store, ErrSubscriptionAlreadyExists, err)
		}
		sub.ID = uuid.NewID()
		err = store.createSubscription(sub)
		if err != ErrStripeCustomerAlreadyExists {
			t.Errorf("Unexpected error creating subscription in %T (wanted %+v): %+v\n", store, ErrStripeCustomerAlreadyExists, err)
		}
		sub.StripeCustomer = "stripeCustomer2"
		err = store.createSubscription(sub)
		if err != nil {
			t.Errorf("Error creating subscription in %T: %+v\n", store, err)
		}
	}
}

func TestUpdateSubscription(t *testing.T) {
	variations := 1 << 7
	sub := Subscription{
		ID:             uuid.NewID(),
		UserID:         uuid.NewID(),
		StripeCustomer: "default",
		Amount:         -1,
		Period:         MonthlyPeriod,
		Created:        time.Now().Add(time.Hour * -24),
		BeginCharging:  time.Now().Add(time.Hour * -24),
		LastCharged:    time.Now().Add(time.Hour * -24),
		LastNotified:   time.Now().Add(time.Hour * -24),
		InLockout:      true,
	}
	sub2 := Subscription{
		ID:             uuid.NewID(),
		UserID:         uuid.NewID(),
		StripeCustomer: "stripeCustomer2",
		Amount:         -2,
		Period:         MonthlyPeriod,
		Created:        time.Now(),
		BeginCharging:  time.Now(),
		LastCharged:    time.Now(),
		LastNotified:   time.Now(),
		InLockout:      false,
	}

	for i := 1; i < variations; i++ {
		var stripeCustomer string
		var amount int
		var inLockout bool
		var per period
		var beginCharging, lastCharged, lastNotified time.Time

		change := SubscriptionChange{}
		empty := change.IsEmpty()
		if !empty {
			t.Errorf("Expected empty to be %t, was %t\n", true, empty)
		}
		expectation := sub
		result := sub
		strI := strconv.Itoa(i)

		if i&subscriptionChangeStripeCustomer != 0 {
			stripeCustomer = "stripeCustomer-" + strI
			change.StripeCustomer = &stripeCustomer
			expectation.StripeCustomer = stripeCustomer
		}

		if i&subscriptionChangeAmount != 0 {
			amount = i
			change.Amount = &amount
			expectation.Amount = amount
		}

		if i&subscriptionChangePeriod != 0 {
			per = period("period-" + strI)
			change.Period = &per
			expectation.Period = per
		}

		if i&subscriptionChangeBeginCharging != 0 {
			beginCharging = time.Now().Add(time.Hour * time.Duration(i))
			change.BeginCharging = &beginCharging
			expectation.BeginCharging = beginCharging
		}

		if i&subscriptionChangeLastCharged != 0 {
			lastCharged = time.Now().Add(time.Hour * time.Duration(i))
			change.LastCharged = &lastCharged
			expectation.LastCharged = lastCharged
		}

		if i&subscriptionChangeLastNotified != 0 {
			lastNotified = time.Now().Add(time.Hour * time.Duration(i))
			change.LastNotified = &lastNotified
			expectation.LastNotified = lastNotified
		}

		if i&subscriptionChangeInLockout != 0 {
			inLockout = i%2 == 0
			change.InLockout = &inLockout
			expectation.InLockout = inLockout
		}

		empty = change.IsEmpty()
		if empty {
			t.Errorf("Expected empty to be %t, was %t\n", false, empty)
		}

		result.ApplyChange(change)
		match, field, expected, got := compareSubscriptions(expectation, result)
		if !match {
			t.Errorf("Expected field `%s` to be `%v`, got `%v`\n", field, expected, got)
		}
		for _, store := range testSubscriptionStores {
			err := store.reset()
			if err != nil {
				t.Fatalf("Error resetting %T: %+v\n", store, err)
			}
			err = store.createSubscription(sub)
			if err != nil {
				t.Fatalf("Error saving subscription in %T: %s\n", store, err)
			}
			err = store.updateSubscription(sub.ID, change)
			if err != nil {
				t.Errorf("Error updating subscription in %T: %s\n", store, err)
			}
			retrieved, err := store.getSubscriptions([]uuid.ID{sub.ID})
			if err != nil {
				t.Errorf("Error getting subscription from %T: %s\n", store, err)
			}
			ok, missing := subscriptionMapContains(retrieved, sub)
			if !ok {
				t.Errorf("Expected to retrieve %s from %T, but missing was %+v\n", sub.ID.String(), store, missing)
			}
			match, field, expected, got = compareSubscriptions(expectation, retrieved[sub.ID.String()])
			if !match {
				t.Errorf("Expected field `%s` to be `%v`, got `%v` from %T\n", field, expected, got, store)
			}
		}
	}
	for _, store := range testSubscriptionStores {
		err := store.reset()
		if err != nil {
			t.Fatalf("Error resetting %T: %+v\n", store, err)
		}
		err = store.createSubscription(sub)
		if err != nil {
			t.Fatalf("Error saving subscription in %T: %+v\n", store, err)
		}
		err = store.createSubscription(sub2)
		if err != nil {
			t.Fatalf("Error saving subscription in %T: %+v\n", store, err)
		}
		change := SubscriptionChange{}
		err = store.updateSubscription(sub.ID, change)
		if err != ErrSubscriptionChangeEmpty {
			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionChangeEmpty, err, store)
		}
		stripeCustomer := sub2.StripeCustomer
		change.StripeCustomer = &stripeCustomer
		err = store.updateSubscription(uuid.NewID(), change)
		if err != ErrSubscriptionNotFound {
			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionNotFound, err, store)
		}
		err = store.updateSubscription(sub.ID, change)
		if err != ErrStripeCustomerAlreadyExists {
			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrStripeCustomerAlreadyExists, err, store)
		}
	}
}

func TestDeleteSubscription(t *testing.T) {
	for _, store := range testSubscriptionStores {
		err := store.reset()
		if err != nil {
			t.Fatalf("Error resetting %T: %+v\n", store, err)
		}
		sub1 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer1",
		}
		sub2 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer2",
		}
		err = store.createSubscription(sub1)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub2)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.deleteSubscription(sub1.ID)
		if err != nil {
			t.Fatalf("Error deleting %+v in %T: %+v\n", sub1, store, err)
		}
		retrieved, err := store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID})
		if err != nil {
			t.Errorf("Error retrieving subscriptions from %T: %+v\n", store, err)
		}
		ok, missing := subscriptionMapContains(retrieved, sub1)
		if ok {
			t.Errorf("Expected not to retrieve %s from %T, but missing was %+v\n", sub1.ID.String(), store, missing)
		}
		ok, missing = subscriptionMapContains(retrieved, sub2)
		if !ok {
			t.Errorf("Expected to retrieve %s from %T, but missing was %+v\n", sub2.ID.String(), store, missing)
		}
		_, err = store.getSubscriptionByUser(sub1.UserID)
		if err != ErrSubscriptionNotFound {
			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionNotFound, err, store)
		}
		err = store.deleteSubscription(sub1.ID)
		if err != ErrSubscriptionNotFound {
			t.Errorf("Expected err to be %+v, but got %+v from %T\n", ErrSubscriptionNotFound, err, store)
		}
	}
}

func TestListSubscriptionsLastChargedBefore(t *testing.T) {
	for _, store := range testSubscriptionStores {
		err := store.reset()
		if err != nil {
			t.Fatalf("Error resetting %T: %+v\n", store, err)
		}
		sub1 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer1",
			Amount:         200,
			Period:         MonthlyPeriod,
			Created:        time.Now().Add(time.Hour * -24 * 32),
			BeginCharging:  time.Now().Add(time.Hour * -24),
			LastCharged:    time.Now().Add(time.Hour * -24),
		}
		sub2 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer2",
			Amount:         300,
			Period:         MonthlyPeriod,
			Created:        time.Now().Add(time.Hour * -24 * 61),
			BeginCharging:  time.Now().Add(time.Hour * -24 * 31),
			LastCharged:    time.Now().Add(time.Hour * -24 * 31),
		}
		sub3 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer3",
			Amount:         100,
			Period:         MonthlyPeriod,
			Created:        time.Now().Add(time.Hour * -1),
			BeginCharging:  time.Now().Add(time.Hour * 31),
			LastCharged:    time.Time{},
		}
		err = store.createSubscription(sub1)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub2)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub3)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		t.Logf("sub1: %+v\n", sub1)
		t.Logf("sub2: %+v\n", sub2)
		t.Logf("sub3: %+v\n", sub3)
		// subscriptions last charged before right now
		// should be sub1, sub2, and sub3
		results, err := store.listSubscriptionsLastChargedBefore(time.Now())
		if err != nil {
			t.Errorf("Unexpected error listing subscriptions in %T: %+v\n", store, err)
		}
		if len(results) != 3 {
			t.Errorf("Expected three results from %T, got %+v\n", store, results)
		}
		ok, field, expected, result := compareSubscriptions(sub3, results[0])
		if !ok {
			t.Errorf("Expected %s in pos 0 to be %+v, got %+v from %T", field, expected, result, store)
		}
		ok, field, expected, result = compareSubscriptions(sub2, results[1])
		if !ok {
			t.Errorf("Expected %s in pos 1 to be %+v, got %+v from %T", field, expected, result, store)
		}
		ok, field, expected, result = compareSubscriptions(sub1, results[2])
		if !ok {
			t.Errorf("Expected %s in pos 2 to be %+v, got %+v from %T", field, expected, result, store)
		}
		// subscriptions last charged before a week ago
		// should be sub2, sub3
		results, err = store.listSubscriptionsLastChargedBefore(time.Now().Add(time.Hour * -24 * 7))
		if err != nil {
			t.Errorf("Unexpected error listing subscriptions in %T: %+v\n", store, err)
		}
		if len(results) != 2 {
			t.Errorf("Expected two results from %T, got %+v\n", store, results)
		}
		ok, field, expected, result = compareSubscriptions(sub3, results[0])
		if !ok {
			t.Errorf("Expected %s in pos 0 to be %+v, got %+v from %T", field, expected, result, store)
		}
		ok, field, expected, result = compareSubscriptions(sub2, results[1])
		if !ok {
			t.Errorf("Expected %s in pos 1 to be %+v, got %+v from %T", field, expected, result, store)
		}
		// subscriptions last charged before 32 days ago
		// should be sub3
		results, err = store.listSubscriptionsLastChargedBefore(time.Now().Add(time.Hour * -24 * 32))
		if err != nil {
			t.Errorf("Unexpected error listing subscriptions in %T: %+v\n", store, err)
		}
		if len(results) != 1 {
			t.Errorf("Expected one result from %T, got %+v\n", store, results)
		}
		ok, field, expected, result = compareSubscriptions(sub3, results[0])
		if !ok {
			t.Errorf("Expected %s in pos 0 to be %+v, got %+v from %T", field, expected, result, store)
		}
	}
}

func TestGetSubscriptions(t *testing.T) {
	for _, store := range testSubscriptionStores {
		err := store.reset()
		if err != nil {
			t.Fatalf("Error resetting %T: %+v\n", store, err)
		}
		sub1 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer1",
			Amount:         200,
			Period:         MonthlyPeriod,
			Created:        time.Now(),
			BeginCharging:  time.Now().Add(time.Hour),
		}
		sub2 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer2",
			Amount:         300,
			Period:         MonthlyPeriod,
			Created:        time.Now().Add(time.Hour * -720),
			BeginCharging:  time.Now().Add(time.Hour*-720 + time.Hour*2),
			LastCharged:    time.Now(),
		}
		sub3 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer3",
			Amount:         100,
			Period:         MonthlyPeriod,
			Created:        time.Now().Add(time.Hour * -1440),
			BeginCharging:  time.Now().Add(time.Hour * -1440),
			LastNotified:   time.Now().Add(time.Hour * -720),
			InLockout:      true,
		}
		err = store.createSubscription(sub1)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub2)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub3)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		retrieved, err := store.getSubscriptions([]uuid.ID{})
		if err != ErrNoSubscriptionID {
			t.Errorf("Error retrieving no subscriptions from %T. Expected %+v, got %+v\n", store, ErrNoSubscriptionID, err)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID})
		if err != nil {
			t.Errorf("Error retrieving %s from %T: %+v\n", sub1.ID, store, err)
		}
		ok, missing := subscriptionMapContains(retrieved, sub1)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID})
		if err != nil {
			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub1.ID, sub2.ID, store, err)
		}
		ok, missing = subscriptionMapContains(retrieved, sub1, sub2)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub3.ID})
		if err != nil {
			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub1.ID, sub3.ID, store, err)
		}
		ok, missing = subscriptionMapContains(retrieved, sub1, sub3)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID, sub3.ID})
		if err != nil {
			t.Errorf("Error retrieving %s, %s, and %s from %T: %+v\n", sub1.ID, sub2.ID, sub3.ID, store, err)
		}
		ok, missing = subscriptionMapContains(retrieved, sub1, sub2, sub3)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub2.ID})
		if err != nil {
			t.Errorf("Error retrieving %s from %T: %+v\n", sub2.ID, store, err)
		}
		ok, missing = subscriptionMapContains(retrieved, sub2)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub2.ID, sub3.ID})
		if err != nil {
			t.Errorf("Error retrieving %s and %s from %T: %+v\n", sub2.ID, sub3.ID, store, err)
		}
		ok, missing = subscriptionMapContains(retrieved, sub2, sub3)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub3.ID})
		if err != nil {
			t.Errorf("Error retrieving %s from %T: %+v\n", sub3.ID, store, err)
		}
		ok, missing = subscriptionMapContains(retrieved, sub3)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{uuid.NewID()})
		if err != nil {
			t.Errorf("Error retrieving non-existent ID from %T: %+v\n", store, err)
		}
		if len(retrieved) != 0 {
			t.Errorf("Expected no results, %T returned %+v\n", store, retrieved)
		}
		retrieved, err = store.getSubscriptions([]uuid.ID{sub1.ID, sub2.ID, uuid.NewID(), sub3.ID})
		if err != nil {
			t.Errorf("Error retrieving non-existent ID from %T: %+v\n", store, err)
		}
		if len(retrieved) != 3 {
			t.Errorf("Expected 3 results, %T returned %+v\n", store, retrieved)
		}
		ok, missing = subscriptionMapContains(retrieved, sub1, sub2, sub3)
		if !ok {
			t.Logf("Results: %+v\n", retrieved)
			t.Errorf("Expected %+v to be in the results, was not for %T.\n", missing, store)
		}
	}
}

func TestGetSubscriptionByUser(t *testing.T) {
	for _, store := range testSubscriptionStores {
		err := store.reset()
		if err != nil {
			t.Fatalf("Error resetting %T: %+v\n", store, err)
		}
		sub1 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer1",
		}
		sub2 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer2",
		}
		sub3 := Subscription{
			ID:             uuid.NewID(),
			UserID:         uuid.NewID(),
			StripeCustomer: "stripeCustomer3",
		}
		err = store.createSubscription(sub1)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub2)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		err = store.createSubscription(sub3)
		if err != nil {
			t.Fatalf("Error creating %+v in %T: %+v\n", sub1, store, err)
		}
		retrieved, err := store.getSubscriptionByUser(sub1.UserID)
		if err != nil {
			t.Errorf("Error retrieving subscription %+v from %T: %+v\n", sub1, store, err)
		}
		ok, field, expected, result := compareSubscriptions(sub1, retrieved)
		if !ok {
			t.Errorf("Expected %s to be %+v, but was %+v in %T\n", field, expected, result, store)
		}
		retrieved, err = store.getSubscriptionByUser(sub2.UserID)
		if err != nil {
			t.Errorf("Error retrieving subscription %+v from %T: %+v\n", sub2, store, err)
		}
		ok, field, expected, result = compareSubscriptions(sub2, retrieved)
		if !ok {
			t.Errorf("Expected %s to be %+v, but was %+v in %T\n", field, expected, result, store)
		}
		retrieved, err = store.getSubscriptionByUser(sub3.UserID)
		if err != nil {
			t.Errorf("Error retrieving subscription %+v from %T: %+v\n", sub3, store, err)
		}
		ok, field, expected, result = compareSubscriptions(sub3, retrieved)
		if !ok {
			t.Errorf("Expected %s to be %+v, but was %+v in %T\n", field, expected, result, store)
		}
		retrieved, err = store.getSubscriptionByUser(uuid.NewID())
		if err != ErrSubscriptionNotFound {
			t.Errorf("Expected err to be %+v, got %+v from %T\n", ErrSubscriptionNotFound, err, store)
		}
	}
}
