Path: blob/main/components/gitpod-db/go/dbtest/stripe_customer.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package dbtest56import (7"fmt"8"testing"9"time"1011db "github.com/gitpod-io/gitpod/components/gitpod-db/go"12"github.com/google/uuid"13"github.com/stretchr/testify/require"14"gorm.io/gorm"15)1617func NewStripeCustomer(t *testing.T, customer db.StripeCustomer) db.StripeCustomer {18t.Helper()1920result := db.StripeCustomer{21StripeCustomerID: fmt.Sprintf("cus_%s", uuid.New().String()),22AttributionID: db.NewTeamAttributionID(uuid.New().String()),23CreationTime: db.NewVarCharTime(time.Now()),24}2526if customer.StripeCustomerID != "" {27result.StripeCustomerID = customer.StripeCustomerID28}2930if customer.AttributionID != "" {31result.AttributionID = customer.AttributionID32}33if customer.CreationTime.IsSet() {34result.CreationTime = customer.CreationTime35}3637return result38}3940func CreateStripeCustomers(t *testing.T, conn *gorm.DB, customers ...db.StripeCustomer) []db.StripeCustomer {41t.Helper()4243var records []db.StripeCustomer44var ids []string45for _, c := range customers {46record := NewStripeCustomer(t, c)47records = append(records, record)48ids = append(ids, record.StripeCustomerID)49}5051require.NoError(t, conn.CreateInBatches(&records, 1000).Error)5253t.Cleanup(func() {54require.NoError(t, conn.Where(ids).Delete(&db.StripeCustomer{}).Error)55})5657return records58}596061