From 908fb91ba8167c55e7ac1466ae5a22f86b43d92d Mon Sep 17 00:00:00 2001 From: Abhishek Sah Date: Mon, 10 Aug 2026 10:23:46 +0530 Subject: [PATCH] chore(deleter): extend deleter billing mocks for the delete checks Adds GetBalance and List to the credit service mock, List and Cancel to the subscription service mock, ListPayableOnProvider to the invoice service mock, and a new plan service mock. The interface methods land with the next PRs in the stack; the mocks compile standalone. --- core/deleter/mocks/credit_service.go | 118 +++++++++++++++++++++ core/deleter/mocks/invoice_service.go | 60 ++++++++++- core/deleter/mocks/plan_service.go | 94 ++++++++++++++++ core/deleter/mocks/subscription_service.go | 118 +++++++++++++++++++++ 4 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 core/deleter/mocks/plan_service.go diff --git a/core/deleter/mocks/credit_service.go b/core/deleter/mocks/credit_service.go index bef1a735b7..2923863096 100644 --- a/core/deleter/mocks/credit_service.go +++ b/core/deleter/mocks/credit_service.go @@ -5,6 +5,8 @@ package mocks import ( context "context" + credit "github.com/raystack/frontier/billing/credit" + mock "github.com/stretchr/testify/mock" ) @@ -68,6 +70,122 @@ func (_c *CreditService_DeleteByAccountID_Call) RunAndReturn(run func(context.Co return _c } +// GetBalance provides a mock function with given fields: ctx, accountID +func (_m *CreditService) GetBalance(ctx context.Context, accountID string) (int64, error) { + ret := _m.Called(ctx, accountID) + + if len(ret) == 0 { + panic("no return value specified for GetBalance") + } + + var r0 int64 + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (int64, error)); ok { + return rf(ctx, accountID) + } + if rf, ok := ret.Get(0).(func(context.Context, string) int64); ok { + r0 = rf(ctx, accountID) + } else { + r0 = ret.Get(0).(int64) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, accountID) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreditService_GetBalance_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBalance' +type CreditService_GetBalance_Call struct { + *mock.Call +} + +// GetBalance is a helper method to define mock.On call +// - ctx context.Context +// - accountID string +func (_e *CreditService_Expecter) GetBalance(ctx interface{}, accountID interface{}) *CreditService_GetBalance_Call { + return &CreditService_GetBalance_Call{Call: _e.mock.On("GetBalance", ctx, accountID)} +} + +func (_c *CreditService_GetBalance_Call) Run(run func(ctx context.Context, accountID string)) *CreditService_GetBalance_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *CreditService_GetBalance_Call) Return(_a0 int64, _a1 error) *CreditService_GetBalance_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *CreditService_GetBalance_Call) RunAndReturn(run func(context.Context, string) (int64, error)) *CreditService_GetBalance_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *CreditService) List(ctx context.Context, flt credit.Filter) ([]credit.Transaction, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []credit.Transaction + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, credit.Filter) ([]credit.Transaction, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, credit.Filter) []credit.Transaction); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]credit.Transaction) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, credit.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreditService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type CreditService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt credit.Filter +func (_e *CreditService_Expecter) List(ctx interface{}, flt interface{}) *CreditService_List_Call { + return &CreditService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *CreditService_List_Call) Run(run func(ctx context.Context, flt credit.Filter)) *CreditService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(credit.Filter)) + }) + return _c +} + +func (_c *CreditService_List_Call) Return(_a0 []credit.Transaction, _a1 error) *CreditService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *CreditService_List_Call) RunAndReturn(run func(context.Context, credit.Filter) ([]credit.Transaction, error)) *CreditService_List_Call { + _c.Call.Return(run) + return _c +} + // NewCreditService creates a new instance of CreditService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewCreditService(t interface { diff --git a/core/deleter/mocks/invoice_service.go b/core/deleter/mocks/invoice_service.go index c48580e932..e2a8d08f8b 100644 --- a/core/deleter/mocks/invoice_service.go +++ b/core/deleter/mocks/invoice_service.go @@ -8,7 +8,6 @@ import ( customer "github.com/raystack/frontier/billing/customer" invoice "github.com/raystack/frontier/billing/invoice" - mock "github.com/stretchr/testify/mock" ) @@ -131,6 +130,65 @@ func (_c *InvoiceService_List_Call) RunAndReturn(run func(context.Context, invoi return _c } +// ListPayableOnProvider provides a mock function with given fields: ctx, customr +func (_m *InvoiceService) ListPayableOnProvider(ctx context.Context, customr customer.Customer) ([]invoice.Invoice, error) { + ret := _m.Called(ctx, customr) + + if len(ret) == 0 { + panic("no return value specified for ListPayableOnProvider") + } + + var r0 []invoice.Invoice + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, customer.Customer) ([]invoice.Invoice, error)); ok { + return rf(ctx, customr) + } + if rf, ok := ret.Get(0).(func(context.Context, customer.Customer) []invoice.Invoice); ok { + r0 = rf(ctx, customr) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]invoice.Invoice) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, customer.Customer) error); ok { + r1 = rf(ctx, customr) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// InvoiceService_ListPayableOnProvider_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPayableOnProvider' +type InvoiceService_ListPayableOnProvider_Call struct { + *mock.Call +} + +// ListPayableOnProvider is a helper method to define mock.On call +// - ctx context.Context +// - customr customer.Customer +func (_e *InvoiceService_Expecter) ListPayableOnProvider(ctx interface{}, customr interface{}) *InvoiceService_ListPayableOnProvider_Call { + return &InvoiceService_ListPayableOnProvider_Call{Call: _e.mock.On("ListPayableOnProvider", ctx, customr)} +} + +func (_c *InvoiceService_ListPayableOnProvider_Call) Run(run func(ctx context.Context, customr customer.Customer)) *InvoiceService_ListPayableOnProvider_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(customer.Customer)) + }) + return _c +} + +func (_c *InvoiceService_ListPayableOnProvider_Call) Return(_a0 []invoice.Invoice, _a1 error) *InvoiceService_ListPayableOnProvider_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *InvoiceService_ListPayableOnProvider_Call) RunAndReturn(run func(context.Context, customer.Customer) ([]invoice.Invoice, error)) *InvoiceService_ListPayableOnProvider_Call { + _c.Call.Return(run) + return _c +} + // NewInvoiceService creates a new instance of InvoiceService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewInvoiceService(t interface { diff --git a/core/deleter/mocks/plan_service.go b/core/deleter/mocks/plan_service.go new file mode 100644 index 0000000000..9137c52e36 --- /dev/null +++ b/core/deleter/mocks/plan_service.go @@ -0,0 +1,94 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + plan "github.com/raystack/frontier/billing/plan" + mock "github.com/stretchr/testify/mock" +) + +// PlanService is an autogenerated mock type for the PlanService type +type PlanService struct { + mock.Mock +} + +type PlanService_Expecter struct { + mock *mock.Mock +} + +func (_m *PlanService) EXPECT() *PlanService_Expecter { + return &PlanService_Expecter{mock: &_m.Mock} +} + +// GetByID provides a mock function with given fields: ctx, id +func (_m *PlanService) GetByID(ctx context.Context, id string) (plan.Plan, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetByID") + } + + var r0 plan.Plan + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (plan.Plan, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, string) plan.Plan); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(plan.Plan) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PlanService_GetByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByID' +type PlanService_GetByID_Call struct { + *mock.Call +} + +// GetByID is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *PlanService_Expecter) GetByID(ctx interface{}, id interface{}) *PlanService_GetByID_Call { + return &PlanService_GetByID_Call{Call: _e.mock.On("GetByID", ctx, id)} +} + +func (_c *PlanService_GetByID_Call) Run(run func(ctx context.Context, id string)) *PlanService_GetByID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *PlanService_GetByID_Call) Return(_a0 plan.Plan, _a1 error) *PlanService_GetByID_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *PlanService_GetByID_Call) RunAndReturn(run func(context.Context, string) (plan.Plan, error)) *PlanService_GetByID_Call { + _c.Call.Return(run) + return _c +} + +// NewPlanService creates a new instance of PlanService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewPlanService(t interface { + mock.TestingT + Cleanup(func()) +}) *PlanService { + mock := &PlanService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/subscription_service.go b/core/deleter/mocks/subscription_service.go index 874edb3252..8fbb5ea3dc 100644 --- a/core/deleter/mocks/subscription_service.go +++ b/core/deleter/mocks/subscription_service.go @@ -7,6 +7,7 @@ import ( customer "github.com/raystack/frontier/billing/customer" + subscription "github.com/raystack/frontier/billing/subscription" mock "github.com/stretchr/testify/mock" ) @@ -23,6 +24,64 @@ func (_m *SubscriptionService) EXPECT() *SubscriptionService_Expecter { return &SubscriptionService_Expecter{mock: &_m.Mock} } +// Cancel provides a mock function with given fields: ctx, id, immediate +func (_m *SubscriptionService) Cancel(ctx context.Context, id string, immediate bool) (subscription.Subscription, error) { + ret := _m.Called(ctx, id, immediate) + + if len(ret) == 0 { + panic("no return value specified for Cancel") + } + + var r0 subscription.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string, bool) (subscription.Subscription, error)); ok { + return rf(ctx, id, immediate) + } + if rf, ok := ret.Get(0).(func(context.Context, string, bool) subscription.Subscription); ok { + r0 = rf(ctx, id, immediate) + } else { + r0 = ret.Get(0).(subscription.Subscription) + } + + if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok { + r1 = rf(ctx, id, immediate) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SubscriptionService_Cancel_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Cancel' +type SubscriptionService_Cancel_Call struct { + *mock.Call +} + +// Cancel is a helper method to define mock.On call +// - ctx context.Context +// - id string +// - immediate bool +func (_e *SubscriptionService_Expecter) Cancel(ctx interface{}, id interface{}, immediate interface{}) *SubscriptionService_Cancel_Call { + return &SubscriptionService_Cancel_Call{Call: _e.mock.On("Cancel", ctx, id, immediate)} +} + +func (_c *SubscriptionService_Cancel_Call) Run(run func(ctx context.Context, id string, immediate bool)) *SubscriptionService_Cancel_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(bool)) + }) + return _c +} + +func (_c *SubscriptionService_Cancel_Call) Return(_a0 subscription.Subscription, _a1 error) *SubscriptionService_Cancel_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SubscriptionService_Cancel_Call) RunAndReturn(run func(context.Context, string, bool) (subscription.Subscription, error)) *SubscriptionService_Cancel_Call { + _c.Call.Return(run) + return _c +} + // DeleteByCustomer provides a mock function with given fields: ctx, customr func (_m *SubscriptionService) DeleteByCustomer(ctx context.Context, customr customer.Customer) error { ret := _m.Called(ctx, customr) @@ -70,6 +129,65 @@ func (_c *SubscriptionService_DeleteByCustomer_Call) RunAndReturn(run func(conte return _c } +// List provides a mock function with given fields: ctx, filter +func (_m *SubscriptionService) List(ctx context.Context, filter subscription.Filter) ([]subscription.Subscription, error) { + ret := _m.Called(ctx, filter) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []subscription.Subscription + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, subscription.Filter) ([]subscription.Subscription, error)); ok { + return rf(ctx, filter) + } + if rf, ok := ret.Get(0).(func(context.Context, subscription.Filter) []subscription.Subscription); ok { + r0 = rf(ctx, filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]subscription.Subscription) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, subscription.Filter) error); ok { + r1 = rf(ctx, filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SubscriptionService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type SubscriptionService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - filter subscription.Filter +func (_e *SubscriptionService_Expecter) List(ctx interface{}, filter interface{}) *SubscriptionService_List_Call { + return &SubscriptionService_List_Call{Call: _e.mock.On("List", ctx, filter)} +} + +func (_c *SubscriptionService_List_Call) Run(run func(ctx context.Context, filter subscription.Filter)) *SubscriptionService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(subscription.Filter)) + }) + return _c +} + +func (_c *SubscriptionService_List_Call) Return(_a0 []subscription.Subscription, _a1 error) *SubscriptionService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SubscriptionService_List_Call) RunAndReturn(run func(context.Context, subscription.Filter) ([]subscription.Subscription, error)) *SubscriptionService_List_Call { + _c.Call.Return(run) + return _c +} + // NewSubscriptionService creates a new instance of SubscriptionService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewSubscriptionService(t interface {