diff --git a/core/deleter/mocks/customer_service.go b/core/deleter/mocks/customer_service.go new file mode 100644 index 000000000..dbd0afbe1 --- /dev/null +++ b/core/deleter/mocks/customer_service.go @@ -0,0 +1,144 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + customer "github.com/raystack/frontier/billing/customer" + + mock "github.com/stretchr/testify/mock" +) + +// CustomerService is an autogenerated mock type for the CustomerService type +type CustomerService struct { + mock.Mock +} + +type CustomerService_Expecter struct { + mock *mock.Mock +} + +func (_m *CustomerService) EXPECT() *CustomerService_Expecter { + return &CustomerService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, id +func (_m *CustomerService) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CustomerService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type CustomerService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *CustomerService_Expecter) Delete(ctx interface{}, id interface{}) *CustomerService_Delete_Call { + return &CustomerService_Delete_Call{Call: _e.mock.On("Delete", ctx, id)} +} + +func (_c *CustomerService_Delete_Call) Run(run func(ctx context.Context, id string)) *CustomerService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *CustomerService_Delete_Call) Return(_a0 error) *CustomerService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *CustomerService_Delete_Call) RunAndReturn(run func(context.Context, string) error) *CustomerService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, filter +func (_m *CustomerService) List(ctx context.Context, filter customer.Filter) ([]customer.Customer, error) { + ret := _m.Called(ctx, filter) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []customer.Customer + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, customer.Filter) ([]customer.Customer, error)); ok { + return rf(ctx, filter) + } + if rf, ok := ret.Get(0).(func(context.Context, customer.Filter) []customer.Customer); ok { + r0 = rf(ctx, filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]customer.Customer) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, customer.Filter) error); ok { + r1 = rf(ctx, filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CustomerService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type CustomerService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - filter customer.Filter +func (_e *CustomerService_Expecter) List(ctx interface{}, filter interface{}) *CustomerService_List_Call { + return &CustomerService_List_Call{Call: _e.mock.On("List", ctx, filter)} +} + +func (_c *CustomerService_List_Call) Run(run func(ctx context.Context, filter customer.Filter)) *CustomerService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(customer.Filter)) + }) + return _c +} + +func (_c *CustomerService_List_Call) Return(_a0 []customer.Customer, _a1 error) *CustomerService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *CustomerService_List_Call) RunAndReturn(run func(context.Context, customer.Filter) ([]customer.Customer, error)) *CustomerService_List_Call { + _c.Call.Return(run) + return _c +} + +// NewCustomerService creates a new instance of CustomerService. 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 NewCustomerService(t interface { + mock.TestingT + Cleanup(func()) +}) *CustomerService { + mock := &CustomerService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/group_service.go b/core/deleter/mocks/group_service.go new file mode 100644 index 000000000..e86a8892a --- /dev/null +++ b/core/deleter/mocks/group_service.go @@ -0,0 +1,192 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + group "github.com/raystack/frontier/core/group" + + mock "github.com/stretchr/testify/mock" +) + +// GroupService is an autogenerated mock type for the GroupService type +type GroupService struct { + mock.Mock +} + +type GroupService_Expecter struct { + mock *mock.Mock +} + +func (_m *GroupService) EXPECT() *GroupService_Expecter { + return &GroupService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, id +func (_m *GroupService) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GroupService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type GroupService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *GroupService_Expecter) Delete(ctx interface{}, id interface{}) *GroupService_Delete_Call { + return &GroupService_Delete_Call{Call: _e.mock.On("Delete", ctx, id)} +} + +func (_c *GroupService_Delete_Call) Run(run func(ctx context.Context, id string)) *GroupService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *GroupService_Delete_Call) Return(_a0 error) *GroupService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *GroupService_Delete_Call) RunAndReturn(run func(context.Context, string) error) *GroupService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *GroupService) List(ctx context.Context, flt group.Filter) ([]group.Group, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []group.Group + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, group.Filter) ([]group.Group, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, group.Filter) []group.Group); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]group.Group) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, group.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GroupService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type GroupService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt group.Filter +func (_e *GroupService_Expecter) List(ctx interface{}, flt interface{}) *GroupService_List_Call { + return &GroupService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *GroupService_List_Call) Run(run func(ctx context.Context, flt group.Filter)) *GroupService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(group.Filter)) + }) + return _c +} + +func (_c *GroupService_List_Call) Return(_a0 []group.Group, _a1 error) *GroupService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *GroupService_List_Call) RunAndReturn(run func(context.Context, group.Filter) ([]group.Group, error)) *GroupService_List_Call { + _c.Call.Return(run) + return _c +} + +// RemoveUsers provides a mock function with given fields: ctx, groupID, userIDs +func (_m *GroupService) RemoveUsers(ctx context.Context, groupID string, userIDs []string) error { + ret := _m.Called(ctx, groupID, userIDs) + + if len(ret) == 0 { + panic("no return value specified for RemoveUsers") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, []string) error); ok { + r0 = rf(ctx, groupID, userIDs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// GroupService_RemoveUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveUsers' +type GroupService_RemoveUsers_Call struct { + *mock.Call +} + +// RemoveUsers is a helper method to define mock.On call +// - ctx context.Context +// - groupID string +// - userIDs []string +func (_e *GroupService_Expecter) RemoveUsers(ctx interface{}, groupID interface{}, userIDs interface{}) *GroupService_RemoveUsers_Call { + return &GroupService_RemoveUsers_Call{Call: _e.mock.On("RemoveUsers", ctx, groupID, userIDs)} +} + +func (_c *GroupService_RemoveUsers_Call) Run(run func(ctx context.Context, groupID string, userIDs []string)) *GroupService_RemoveUsers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]string)) + }) + return _c +} + +func (_c *GroupService_RemoveUsers_Call) Return(_a0 error) *GroupService_RemoveUsers_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *GroupService_RemoveUsers_Call) RunAndReturn(run func(context.Context, string, []string) error) *GroupService_RemoveUsers_Call { + _c.Call.Return(run) + return _c +} + +// NewGroupService creates a new instance of GroupService. 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 NewGroupService(t interface { + mock.TestingT + Cleanup(func()) +}) *GroupService { + mock := &GroupService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/invitation_service.go b/core/deleter/mocks/invitation_service.go new file mode 100644 index 000000000..d2fd29685 --- /dev/null +++ b/core/deleter/mocks/invitation_service.go @@ -0,0 +1,146 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + invitation "github.com/raystack/frontier/core/invitation" + + mock "github.com/stretchr/testify/mock" + + uuid "github.com/google/uuid" +) + +// InvitationService is an autogenerated mock type for the InvitationService type +type InvitationService struct { + mock.Mock +} + +type InvitationService_Expecter struct { + mock *mock.Mock +} + +func (_m *InvitationService) EXPECT() *InvitationService_Expecter { + return &InvitationService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, id +func (_m *InvitationService) Delete(ctx context.Context, id uuid.UUID) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// InvitationService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type InvitationService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *InvitationService_Expecter) Delete(ctx interface{}, id interface{}) *InvitationService_Delete_Call { + return &InvitationService_Delete_Call{Call: _e.mock.On("Delete", ctx, id)} +} + +func (_c *InvitationService_Delete_Call) Run(run func(ctx context.Context, id uuid.UUID)) *InvitationService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(uuid.UUID)) + }) + return _c +} + +func (_c *InvitationService_Delete_Call) Return(_a0 error) *InvitationService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *InvitationService_Delete_Call) RunAndReturn(run func(context.Context, uuid.UUID) error) *InvitationService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *InvitationService) List(ctx context.Context, flt invitation.Filter) ([]invitation.Invitation, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []invitation.Invitation + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, invitation.Filter) ([]invitation.Invitation, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, invitation.Filter) []invitation.Invitation); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]invitation.Invitation) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, invitation.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// InvitationService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type InvitationService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt invitation.Filter +func (_e *InvitationService_Expecter) List(ctx interface{}, flt interface{}) *InvitationService_List_Call { + return &InvitationService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *InvitationService_List_Call) Run(run func(ctx context.Context, flt invitation.Filter)) *InvitationService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(invitation.Filter)) + }) + return _c +} + +func (_c *InvitationService_List_Call) Return(_a0 []invitation.Invitation, _a1 error) *InvitationService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *InvitationService_List_Call) RunAndReturn(run func(context.Context, invitation.Filter) ([]invitation.Invitation, error)) *InvitationService_List_Call { + _c.Call.Return(run) + return _c +} + +// NewInvitationService creates a new instance of InvitationService. 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 NewInvitationService(t interface { + mock.TestingT + Cleanup(func()) +}) *InvitationService { + mock := &InvitationService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/invoice_service.go b/core/deleter/mocks/invoice_service.go new file mode 100644 index 000000000..c48580e93 --- /dev/null +++ b/core/deleter/mocks/invoice_service.go @@ -0,0 +1,146 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + customer "github.com/raystack/frontier/billing/customer" + + invoice "github.com/raystack/frontier/billing/invoice" + + mock "github.com/stretchr/testify/mock" +) + +// InvoiceService is an autogenerated mock type for the InvoiceService type +type InvoiceService struct { + mock.Mock +} + +type InvoiceService_Expecter struct { + mock *mock.Mock +} + +func (_m *InvoiceService) EXPECT() *InvoiceService_Expecter { + return &InvoiceService_Expecter{mock: &_m.Mock} +} + +// DeleteByCustomer provides a mock function with given fields: ctx, customr +func (_m *InvoiceService) DeleteByCustomer(ctx context.Context, customr customer.Customer) error { + ret := _m.Called(ctx, customr) + + if len(ret) == 0 { + panic("no return value specified for DeleteByCustomer") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, customer.Customer) error); ok { + r0 = rf(ctx, customr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// InvoiceService_DeleteByCustomer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteByCustomer' +type InvoiceService_DeleteByCustomer_Call struct { + *mock.Call +} + +// DeleteByCustomer is a helper method to define mock.On call +// - ctx context.Context +// - customr customer.Customer +func (_e *InvoiceService_Expecter) DeleteByCustomer(ctx interface{}, customr interface{}) *InvoiceService_DeleteByCustomer_Call { + return &InvoiceService_DeleteByCustomer_Call{Call: _e.mock.On("DeleteByCustomer", ctx, customr)} +} + +func (_c *InvoiceService_DeleteByCustomer_Call) Run(run func(ctx context.Context, customr customer.Customer)) *InvoiceService_DeleteByCustomer_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(customer.Customer)) + }) + return _c +} + +func (_c *InvoiceService_DeleteByCustomer_Call) Return(_a0 error) *InvoiceService_DeleteByCustomer_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *InvoiceService_DeleteByCustomer_Call) RunAndReturn(run func(context.Context, customer.Customer) error) *InvoiceService_DeleteByCustomer_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *InvoiceService) List(ctx context.Context, flt invoice.Filter) ([]invoice.Invoice, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []invoice.Invoice + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, invoice.Filter) ([]invoice.Invoice, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, invoice.Filter) []invoice.Invoice); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]invoice.Invoice) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, invoice.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// InvoiceService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type InvoiceService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt invoice.Filter +func (_e *InvoiceService_Expecter) List(ctx interface{}, flt interface{}) *InvoiceService_List_Call { + return &InvoiceService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *InvoiceService_List_Call) Run(run func(ctx context.Context, flt invoice.Filter)) *InvoiceService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(invoice.Filter)) + }) + return _c +} + +func (_c *InvoiceService_List_Call) Return(_a0 []invoice.Invoice, _a1 error) *InvoiceService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *InvoiceService_List_Call) RunAndReturn(run func(context.Context, invoice.Filter) ([]invoice.Invoice, error)) *InvoiceService_List_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 { + mock.TestingT + Cleanup(func()) +}) *InvoiceService { + mock := &InvoiceService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/organization_service.go b/core/deleter/mocks/organization_service.go new file mode 100644 index 000000000..e597d36a7 --- /dev/null +++ b/core/deleter/mocks/organization_service.go @@ -0,0 +1,252 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + authenticate "github.com/raystack/frontier/core/authenticate" + + mock "github.com/stretchr/testify/mock" + + organization "github.com/raystack/frontier/core/organization" +) + +// OrganizationService is an autogenerated mock type for the OrganizationService type +type OrganizationService struct { + mock.Mock +} + +type OrganizationService_Expecter struct { + mock *mock.Mock +} + +func (_m *OrganizationService) EXPECT() *OrganizationService_Expecter { + return &OrganizationService_Expecter{mock: &_m.Mock} +} + +// DeleteModel provides a mock function with given fields: ctx, id +func (_m *OrganizationService) DeleteModel(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteModel") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// OrganizationService_DeleteModel_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteModel' +type OrganizationService_DeleteModel_Call struct { + *mock.Call +} + +// DeleteModel is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *OrganizationService_Expecter) DeleteModel(ctx interface{}, id interface{}) *OrganizationService_DeleteModel_Call { + return &OrganizationService_DeleteModel_Call{Call: _e.mock.On("DeleteModel", ctx, id)} +} + +func (_c *OrganizationService_DeleteModel_Call) Run(run func(ctx context.Context, id string)) *OrganizationService_DeleteModel_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *OrganizationService_DeleteModel_Call) Return(_a0 error) *OrganizationService_DeleteModel_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OrganizationService_DeleteModel_Call) RunAndReturn(run func(context.Context, string) error) *OrganizationService_DeleteModel_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function with given fields: ctx, id +func (_m *OrganizationService) Get(ctx context.Context, id string) (organization.Organization, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 organization.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (organization.Organization, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, string) organization.Organization); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(organization.Organization) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// OrganizationService_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type OrganizationService_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *OrganizationService_Expecter) Get(ctx interface{}, id interface{}) *OrganizationService_Get_Call { + return &OrganizationService_Get_Call{Call: _e.mock.On("Get", ctx, id)} +} + +func (_c *OrganizationService_Get_Call) Run(run func(ctx context.Context, id string)) *OrganizationService_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *OrganizationService_Get_Call) Return(_a0 organization.Organization, _a1 error) *OrganizationService_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *OrganizationService_Get_Call) RunAndReturn(run func(context.Context, string) (organization.Organization, error)) *OrganizationService_Get_Call { + _c.Call.Return(run) + return _c +} + +// ListByUser provides a mock function with given fields: ctx, principal, f +func (_m *OrganizationService) ListByUser(ctx context.Context, principal authenticate.Principal, f organization.Filter) ([]organization.Organization, error) { + ret := _m.Called(ctx, principal, f) + + if len(ret) == 0 { + panic("no return value specified for ListByUser") + } + + var r0 []organization.Organization + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, authenticate.Principal, organization.Filter) ([]organization.Organization, error)); ok { + return rf(ctx, principal, f) + } + if rf, ok := ret.Get(0).(func(context.Context, authenticate.Principal, organization.Filter) []organization.Organization); ok { + r0 = rf(ctx, principal, f) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]organization.Organization) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, authenticate.Principal, organization.Filter) error); ok { + r1 = rf(ctx, principal, f) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// OrganizationService_ListByUser_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListByUser' +type OrganizationService_ListByUser_Call struct { + *mock.Call +} + +// ListByUser is a helper method to define mock.On call +// - ctx context.Context +// - principal authenticate.Principal +// - f organization.Filter +func (_e *OrganizationService_Expecter) ListByUser(ctx interface{}, principal interface{}, f interface{}) *OrganizationService_ListByUser_Call { + return &OrganizationService_ListByUser_Call{Call: _e.mock.On("ListByUser", ctx, principal, f)} +} + +func (_c *OrganizationService_ListByUser_Call) Run(run func(ctx context.Context, principal authenticate.Principal, f organization.Filter)) *OrganizationService_ListByUser_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(authenticate.Principal), args[2].(organization.Filter)) + }) + return _c +} + +func (_c *OrganizationService_ListByUser_Call) Return(_a0 []organization.Organization, _a1 error) *OrganizationService_ListByUser_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *OrganizationService_ListByUser_Call) RunAndReturn(run func(context.Context, authenticate.Principal, organization.Filter) ([]organization.Organization, error)) *OrganizationService_ListByUser_Call { + _c.Call.Return(run) + return _c +} + +// RemoveUsers provides a mock function with given fields: ctx, orgID, userIDs +func (_m *OrganizationService) RemoveUsers(ctx context.Context, orgID string, userIDs []string) error { + ret := _m.Called(ctx, orgID, userIDs) + + if len(ret) == 0 { + panic("no return value specified for RemoveUsers") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, []string) error); ok { + r0 = rf(ctx, orgID, userIDs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// OrganizationService_RemoveUsers_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveUsers' +type OrganizationService_RemoveUsers_Call struct { + *mock.Call +} + +// RemoveUsers is a helper method to define mock.On call +// - ctx context.Context +// - orgID string +// - userIDs []string +func (_e *OrganizationService_Expecter) RemoveUsers(ctx interface{}, orgID interface{}, userIDs interface{}) *OrganizationService_RemoveUsers_Call { + return &OrganizationService_RemoveUsers_Call{Call: _e.mock.On("RemoveUsers", ctx, orgID, userIDs)} +} + +func (_c *OrganizationService_RemoveUsers_Call) Run(run func(ctx context.Context, orgID string, userIDs []string)) *OrganizationService_RemoveUsers_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]string)) + }) + return _c +} + +func (_c *OrganizationService_RemoveUsers_Call) Return(_a0 error) *OrganizationService_RemoveUsers_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *OrganizationService_RemoveUsers_Call) RunAndReturn(run func(context.Context, string, []string) error) *OrganizationService_RemoveUsers_Call { + _c.Call.Return(run) + return _c +} + +// NewOrganizationService creates a new instance of OrganizationService. 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 NewOrganizationService(t interface { + mock.TestingT + Cleanup(func()) +}) *OrganizationService { + mock := &OrganizationService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/policy_service.go b/core/deleter/mocks/policy_service.go new file mode 100644 index 000000000..6604f0080 --- /dev/null +++ b/core/deleter/mocks/policy_service.go @@ -0,0 +1,144 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + policy "github.com/raystack/frontier/core/policy" +) + +// PolicyService is an autogenerated mock type for the PolicyService type +type PolicyService struct { + mock.Mock +} + +type PolicyService_Expecter struct { + mock *mock.Mock +} + +func (_m *PolicyService) EXPECT() *PolicyService_Expecter { + return &PolicyService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, id +func (_m *PolicyService) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// PolicyService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type PolicyService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *PolicyService_Expecter) Delete(ctx interface{}, id interface{}) *PolicyService_Delete_Call { + return &PolicyService_Delete_Call{Call: _e.mock.On("Delete", ctx, id)} +} + +func (_c *PolicyService_Delete_Call) Run(run func(ctx context.Context, id string)) *PolicyService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *PolicyService_Delete_Call) Return(_a0 error) *PolicyService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *PolicyService_Delete_Call) RunAndReturn(run func(context.Context, string) error) *PolicyService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *PolicyService) List(ctx context.Context, flt policy.Filter) ([]policy.Policy, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []policy.Policy + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, policy.Filter) ([]policy.Policy, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, policy.Filter) []policy.Policy); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]policy.Policy) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, policy.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// PolicyService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type PolicyService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt policy.Filter +func (_e *PolicyService_Expecter) List(ctx interface{}, flt interface{}) *PolicyService_List_Call { + return &PolicyService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *PolicyService_List_Call) Run(run func(ctx context.Context, flt policy.Filter)) *PolicyService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(policy.Filter)) + }) + return _c +} + +func (_c *PolicyService_List_Call) Return(_a0 []policy.Policy, _a1 error) *PolicyService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *PolicyService_List_Call) RunAndReturn(run func(context.Context, policy.Filter) ([]policy.Policy, error)) *PolicyService_List_Call { + _c.Call.Return(run) + return _c +} + +// NewPolicyService creates a new instance of PolicyService. 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 NewPolicyService(t interface { + mock.TestingT + Cleanup(func()) +}) *PolicyService { + mock := &PolicyService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/project_service.go b/core/deleter/mocks/project_service.go new file mode 100644 index 000000000..34342c164 --- /dev/null +++ b/core/deleter/mocks/project_service.go @@ -0,0 +1,144 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + project "github.com/raystack/frontier/core/project" +) + +// ProjectService is an autogenerated mock type for the ProjectService type +type ProjectService struct { + mock.Mock +} + +type ProjectService_Expecter struct { + mock *mock.Mock +} + +func (_m *ProjectService) EXPECT() *ProjectService_Expecter { + return &ProjectService_Expecter{mock: &_m.Mock} +} + +// DeleteModel provides a mock function with given fields: ctx, id +func (_m *ProjectService) DeleteModel(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeleteModel") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ProjectService_DeleteModel_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteModel' +type ProjectService_DeleteModel_Call struct { + *mock.Call +} + +// DeleteModel is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *ProjectService_Expecter) DeleteModel(ctx interface{}, id interface{}) *ProjectService_DeleteModel_Call { + return &ProjectService_DeleteModel_Call{Call: _e.mock.On("DeleteModel", ctx, id)} +} + +func (_c *ProjectService_DeleteModel_Call) Run(run func(ctx context.Context, id string)) *ProjectService_DeleteModel_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *ProjectService_DeleteModel_Call) Return(_a0 error) *ProjectService_DeleteModel_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ProjectService_DeleteModel_Call) RunAndReturn(run func(context.Context, string) error) *ProjectService_DeleteModel_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *ProjectService) List(ctx context.Context, flt project.Filter) ([]project.Project, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []project.Project + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, project.Filter) ([]project.Project, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, project.Filter) []project.Project); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]project.Project) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, project.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ProjectService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type ProjectService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt project.Filter +func (_e *ProjectService_Expecter) List(ctx interface{}, flt interface{}) *ProjectService_List_Call { + return &ProjectService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *ProjectService_List_Call) Run(run func(ctx context.Context, flt project.Filter)) *ProjectService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(project.Filter)) + }) + return _c +} + +func (_c *ProjectService_List_Call) Return(_a0 []project.Project, _a1 error) *ProjectService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ProjectService_List_Call) RunAndReturn(run func(context.Context, project.Filter) ([]project.Project, error)) *ProjectService_List_Call { + _c.Call.Return(run) + return _c +} + +// NewProjectService creates a new instance of ProjectService. 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 NewProjectService(t interface { + mock.TestingT + Cleanup(func()) +}) *ProjectService { + mock := &ProjectService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/resource_service.go b/core/deleter/mocks/resource_service.go new file mode 100644 index 000000000..f68bad8b0 --- /dev/null +++ b/core/deleter/mocks/resource_service.go @@ -0,0 +1,202 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + resource "github.com/raystack/frontier/core/resource" +) + +// ResourceService is an autogenerated mock type for the ResourceService type +type ResourceService struct { + mock.Mock +} + +type ResourceService_Expecter struct { + mock *mock.Mock +} + +func (_m *ResourceService) EXPECT() *ResourceService_Expecter { + return &ResourceService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, namespaceID, id +func (_m *ResourceService) Delete(ctx context.Context, namespaceID string, id string) error { + ret := _m.Called(ctx, namespaceID, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok { + r0 = rf(ctx, namespaceID, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ResourceService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type ResourceService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - namespaceID string +// - id string +func (_e *ResourceService_Expecter) Delete(ctx interface{}, namespaceID interface{}, id interface{}) *ResourceService_Delete_Call { + return &ResourceService_Delete_Call{Call: _e.mock.On("Delete", ctx, namespaceID, id)} +} + +func (_c *ResourceService_Delete_Call) Run(run func(ctx context.Context, namespaceID string, id string)) *ResourceService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *ResourceService_Delete_Call) Return(_a0 error) *ResourceService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ResourceService_Delete_Call) RunAndReturn(run func(context.Context, string, string) error) *ResourceService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function with given fields: ctx, id +func (_m *ResourceService) Get(ctx context.Context, id string) (resource.Resource, error) { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 resource.Resource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, string) (resource.Resource, error)); ok { + return rf(ctx, id) + } + if rf, ok := ret.Get(0).(func(context.Context, string) resource.Resource); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Get(0).(resource.Resource) + } + + if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = rf(ctx, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ResourceService_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type ResourceService_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *ResourceService_Expecter) Get(ctx interface{}, id interface{}) *ResourceService_Get_Call { + return &ResourceService_Get_Call{Call: _e.mock.On("Get", ctx, id)} +} + +func (_c *ResourceService_Get_Call) Run(run func(ctx context.Context, id string)) *ResourceService_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *ResourceService_Get_Call) Return(_a0 resource.Resource, _a1 error) *ResourceService_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ResourceService_Get_Call) RunAndReturn(run func(context.Context, string) (resource.Resource, error)) *ResourceService_Get_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *ResourceService) List(ctx context.Context, flt resource.Filter) ([]resource.Resource, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []resource.Resource + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, resource.Filter) ([]resource.Resource, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, resource.Filter) []resource.Resource); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]resource.Resource) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, resource.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ResourceService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type ResourceService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt resource.Filter +func (_e *ResourceService_Expecter) List(ctx interface{}, flt interface{}) *ResourceService_List_Call { + return &ResourceService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *ResourceService_List_Call) Run(run func(ctx context.Context, flt resource.Filter)) *ResourceService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(resource.Filter)) + }) + return _c +} + +func (_c *ResourceService_List_Call) Return(_a0 []resource.Resource, _a1 error) *ResourceService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ResourceService_List_Call) RunAndReturn(run func(context.Context, resource.Filter) ([]resource.Resource, error)) *ResourceService_List_Call { + _c.Call.Return(run) + return _c +} + +// NewResourceService creates a new instance of ResourceService. 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 NewResourceService(t interface { + mock.TestingT + Cleanup(func()) +}) *ResourceService { + mock := &ResourceService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/role_service.go b/core/deleter/mocks/role_service.go new file mode 100644 index 000000000..8a24e5e82 --- /dev/null +++ b/core/deleter/mocks/role_service.go @@ -0,0 +1,144 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" + + role "github.com/raystack/frontier/core/role" +) + +// RoleService is an autogenerated mock type for the RoleService type +type RoleService struct { + mock.Mock +} + +type RoleService_Expecter struct { + mock *mock.Mock +} + +func (_m *RoleService) EXPECT() *RoleService_Expecter { + return &RoleService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, id +func (_m *RoleService) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// RoleService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type RoleService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *RoleService_Expecter) Delete(ctx interface{}, id interface{}) *RoleService_Delete_Call { + return &RoleService_Delete_Call{Call: _e.mock.On("Delete", ctx, id)} +} + +func (_c *RoleService_Delete_Call) Run(run func(ctx context.Context, id string)) *RoleService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *RoleService_Delete_Call) Return(_a0 error) *RoleService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *RoleService_Delete_Call) RunAndReturn(run func(context.Context, string) error) *RoleService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: ctx, flt +func (_m *RoleService) List(ctx context.Context, flt role.Filter) ([]role.Role, error) { + ret := _m.Called(ctx, flt) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []role.Role + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, role.Filter) ([]role.Role, error)); ok { + return rf(ctx, flt) + } + if rf, ok := ret.Get(0).(func(context.Context, role.Filter) []role.Role); ok { + r0 = rf(ctx, flt) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]role.Role) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, role.Filter) error); ok { + r1 = rf(ctx, flt) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// RoleService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type RoleService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - flt role.Filter +func (_e *RoleService_Expecter) List(ctx interface{}, flt interface{}) *RoleService_List_Call { + return &RoleService_List_Call{Call: _e.mock.On("List", ctx, flt)} +} + +func (_c *RoleService_List_Call) Run(run func(ctx context.Context, flt role.Filter)) *RoleService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(role.Filter)) + }) + return _c +} + +func (_c *RoleService_List_Call) Return(_a0 []role.Role, _a1 error) *RoleService_List_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *RoleService_List_Call) RunAndReturn(run func(context.Context, role.Filter) ([]role.Role, error)) *RoleService_List_Call { + _c.Call.Return(run) + return _c +} + +// NewRoleService creates a new instance of RoleService. 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 NewRoleService(t interface { + mock.TestingT + Cleanup(func()) +}) *RoleService { + mock := &RoleService{} + 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 new file mode 100644 index 000000000..874edb325 --- /dev/null +++ b/core/deleter/mocks/subscription_service.go @@ -0,0 +1,85 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + customer "github.com/raystack/frontier/billing/customer" + + mock "github.com/stretchr/testify/mock" +) + +// SubscriptionService is an autogenerated mock type for the SubscriptionService type +type SubscriptionService struct { + mock.Mock +} + +type SubscriptionService_Expecter struct { + mock *mock.Mock +} + +func (_m *SubscriptionService) EXPECT() *SubscriptionService_Expecter { + return &SubscriptionService_Expecter{mock: &_m.Mock} +} + +// 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) + + if len(ret) == 0 { + panic("no return value specified for DeleteByCustomer") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, customer.Customer) error); ok { + r0 = rf(ctx, customr) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SubscriptionService_DeleteByCustomer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteByCustomer' +type SubscriptionService_DeleteByCustomer_Call struct { + *mock.Call +} + +// DeleteByCustomer is a helper method to define mock.On call +// - ctx context.Context +// - customr customer.Customer +func (_e *SubscriptionService_Expecter) DeleteByCustomer(ctx interface{}, customr interface{}) *SubscriptionService_DeleteByCustomer_Call { + return &SubscriptionService_DeleteByCustomer_Call{Call: _e.mock.On("DeleteByCustomer", ctx, customr)} +} + +func (_c *SubscriptionService_DeleteByCustomer_Call) Run(run func(ctx context.Context, customr customer.Customer)) *SubscriptionService_DeleteByCustomer_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(customer.Customer)) + }) + return _c +} + +func (_c *SubscriptionService_DeleteByCustomer_Call) Return(_a0 error) *SubscriptionService_DeleteByCustomer_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *SubscriptionService_DeleteByCustomer_Call) RunAndReturn(run func(context.Context, customer.Customer) error) *SubscriptionService_DeleteByCustomer_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 { + mock.TestingT + Cleanup(func()) +}) *SubscriptionService { + mock := &SubscriptionService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/mocks/user_service.go b/core/deleter/mocks/user_service.go new file mode 100644 index 000000000..06a9b6bc4 --- /dev/null +++ b/core/deleter/mocks/user_service.go @@ -0,0 +1,83 @@ +// Code generated by mockery v2.53.5. DO NOT EDIT. + +package mocks + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// UserService is an autogenerated mock type for the UserService type +type UserService struct { + mock.Mock +} + +type UserService_Expecter struct { + mock *mock.Mock +} + +func (_m *UserService) EXPECT() *UserService_Expecter { + return &UserService_Expecter{mock: &_m.Mock} +} + +// Delete provides a mock function with given fields: ctx, id +func (_m *UserService) Delete(ctx context.Context, id string) error { + ret := _m.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(ctx, id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UserService_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type UserService_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - id string +func (_e *UserService_Expecter) Delete(ctx interface{}, id interface{}) *UserService_Delete_Call { + return &UserService_Delete_Call{Call: _e.mock.On("Delete", ctx, id)} +} + +func (_c *UserService_Delete_Call) Run(run func(ctx context.Context, id string)) *UserService_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *UserService_Delete_Call) Return(_a0 error) *UserService_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *UserService_Delete_Call) RunAndReturn(run func(context.Context, string) error) *UserService_Delete_Call { + _c.Call.Return(run) + return _c +} + +// NewUserService creates a new instance of UserService. 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 NewUserService(t interface { + mock.TestingT + Cleanup(func()) +}) *UserService { + mock := &UserService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/core/deleter/service.go b/core/deleter/service.go index b4d4564df..7d40108eb 100644 --- a/core/deleter/service.go +++ b/core/deleter/service.go @@ -127,7 +127,20 @@ func NewCascadeDeleter(orgService OrganizationService, projService ProjectServic } func (d Service) DeleteProject(ctx context.Context, id string) error { - // delete all related resources first + // delete all project-level policies (and their rolebinding relations) + policies, err := d.policyService.List(ctx, policy.Filter{ + ProjectID: id, + }) + if err != nil { + return err + } + for _, p := range policies { + if err = d.policyService.Delete(ctx, p.ID); err != nil { + return fmt.Errorf("failed to delete project while deleting a policy[%s]: %w", p.ID, err) + } + } + + // delete all related resources resources, err := d.resService.List(ctx, resource.Filter{ ProjectID: id, }) diff --git a/core/deleter/service_test.go b/core/deleter/service_test.go new file mode 100644 index 000000000..e206c7019 --- /dev/null +++ b/core/deleter/service_test.go @@ -0,0 +1,219 @@ +package deleter_test + +import ( + "context" + "errors" + "testing" + + "github.com/google/uuid" + "github.com/raystack/frontier/billing/customer" + "github.com/raystack/frontier/billing/invoice" + "github.com/raystack/frontier/core/deleter" + "github.com/raystack/frontier/core/deleter/mocks" + "github.com/raystack/frontier/core/group" + "github.com/raystack/frontier/core/invitation" + "github.com/raystack/frontier/core/policy" + "github.com/raystack/frontier/core/project" + "github.com/raystack/frontier/core/resource" + "github.com/raystack/frontier/core/role" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func newMocks(t *testing.T) ( + *mocks.OrganizationService, + *mocks.ProjectService, + *mocks.ResourceService, + *mocks.GroupService, + *mocks.PolicyService, + *mocks.RoleService, + *mocks.InvitationService, + *mocks.UserService, + *mocks.CustomerService, + *mocks.SubscriptionService, + *mocks.InvoiceService, +) { + t.Helper() + return mocks.NewOrganizationService(t), + mocks.NewProjectService(t), + mocks.NewResourceService(t), + mocks.NewGroupService(t), + mocks.NewPolicyService(t), + mocks.NewRoleService(t), + mocks.NewInvitationService(t), + mocks.NewUserService(t), + mocks.NewCustomerService(t), + mocks.NewSubscriptionService(t), + mocks.NewInvoiceService(t) +} + +func TestDeleteProject(t *testing.T) { + t.Run("deletes policies, resources, then project model", func(t *testing.T) { + orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + + polSvc.EXPECT().List(mock.Anything, policy.Filter{ProjectID: "proj-1"}). + Return([]policy.Policy{{ID: "pol-1"}, {ID: "pol-2"}}, nil) + polSvc.EXPECT().Delete(mock.Anything, "pol-1").Return(nil) + polSvc.EXPECT().Delete(mock.Anything, "pol-2").Return(nil) + + resSvc.EXPECT().List(mock.Anything, resource.Filter{ProjectID: "proj-1"}). + Return([]resource.Resource{{ID: "res-1", NamespaceID: "ns-1", Name: "r1"}}, nil) + resSvc.EXPECT().Delete(mock.Anything, "ns-1", "res-1").Return(nil) + + projSvc.EXPECT().DeleteModel(mock.Anything, "proj-1").Return(nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteProject(context.Background(), "proj-1") + assert.NoError(t, err) + }) + + t.Run("returns error when policy list fails", func(t *testing.T) { + _, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + orgSvc := mocks.NewOrganizationService(t) + + polSvc.EXPECT().List(mock.Anything, policy.Filter{ProjectID: "proj-1"}). + Return(nil, errors.New("db error")) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteProject(context.Background(), "proj-1") + assert.ErrorContains(t, err, "db error") + }) + + t.Run("returns error when policy delete fails", func(t *testing.T) { + _, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + orgSvc := mocks.NewOrganizationService(t) + + polSvc.EXPECT().List(mock.Anything, policy.Filter{ProjectID: "proj-1"}). + Return([]policy.Policy{{ID: "pol-fail"}}, nil) + polSvc.EXPECT().Delete(mock.Anything, "pol-fail").Return(errors.New("delete error")) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteProject(context.Background(), "proj-1") + assert.ErrorContains(t, err, "pol-fail") + }) + + t.Run("no policies — still deletes resources and project", func(t *testing.T) { + orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + + polSvc.EXPECT().List(mock.Anything, policy.Filter{ProjectID: "proj-1"}). + Return([]policy.Policy{}, nil) + resSvc.EXPECT().List(mock.Anything, resource.Filter{ProjectID: "proj-1"}). + Return([]resource.Resource{}, nil) + projSvc.EXPECT().DeleteModel(mock.Anything, "proj-1").Return(nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteProject(context.Background(), "proj-1") + assert.NoError(t, err) + }) +} + +func TestDeleteOrganization(t *testing.T) { + t.Run("full cascade delete", func(t *testing.T) { + orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + + // canDelete: no customers + custSvc.EXPECT().List(mock.Anything, customer.Filter{OrgID: "org-1"}). + Return([]customer.Customer{}, nil) + + // policies + polSvc.EXPECT().List(mock.Anything, policy.Filter{OrgID: "org-1"}). + Return([]policy.Policy{{ID: "org-pol-1"}}, nil) + polSvc.EXPECT().Delete(mock.Anything, "org-pol-1").Return(nil) + + // projects (each triggers DeleteProject) + projSvc.EXPECT().List(mock.Anything, project.Filter{OrgID: "org-1"}). + Return([]project.Project{{ID: "proj-1", Name: "p1"}}, nil) + // DeleteProject for proj-1 + polSvc.EXPECT().List(mock.Anything, policy.Filter{ProjectID: "proj-1"}). + Return([]policy.Policy{}, nil) + resSvc.EXPECT().List(mock.Anything, resource.Filter{ProjectID: "proj-1"}). + Return([]resource.Resource{}, nil) + projSvc.EXPECT().DeleteModel(mock.Anything, "proj-1").Return(nil) + + // groups + grpSvc.EXPECT().List(mock.Anything, group.Filter{OrganizationID: "org-1"}). + Return([]group.Group{{ID: "grp-1", Name: "g1"}}, nil) + grpSvc.EXPECT().Delete(mock.Anything, "grp-1").Return(nil) + + // roles + roleSvc.EXPECT().List(mock.Anything, role.Filter{OrgID: "org-1"}). + Return([]role.Role{{ID: "role-1", Name: "r1"}}, nil) + roleSvc.EXPECT().Delete(mock.Anything, "role-1").Return(nil) + + // invitations + invID := uuid.New() + invSvc.EXPECT().List(mock.Anything, invitation.Filter{OrgID: "org-1"}). + Return([]invitation.Invitation{{ID: invID}}, nil) + invSvc.EXPECT().Delete(mock.Anything, invID).Return(nil) + + // billing (no customers from canDelete, but DeleteCustomers is called separately) + custSvc.EXPECT().List(mock.Anything, customer.Filter{OrgID: "org-1"}). + Return([]customer.Customer{}, nil) + + // finally delete org model + orgSvc.EXPECT().DeleteModel(mock.Anything, "org-1").Return(nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteOrganization(context.Background(), "org-1") + assert.NoError(t, err) + }) + + t.Run("blocked when billed customer has invoices", func(t *testing.T) { + _, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + orgSvc := mocks.NewOrganizationService(t) + + custSvc.EXPECT().List(mock.Anything, customer.Filter{OrgID: "org-1"}). + Return([]customer.Customer{{ID: "cust-1", ProviderID: "stripe-1"}}, nil) + invocSvc.EXPECT().List(mock.Anything, invoice.Filter{CustomerID: "cust-1"}). + Return([]invoice.Invoice{{ID: "inv-1"}}, nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteOrganization(context.Background(), "org-1") + assert.ErrorIs(t, err, deleter.ErrDeleteNotAllowed) + }) +} + +func TestDeleteCustomers(t *testing.T) { + t.Run("deletes subscriptions invoices and customer", func(t *testing.T) { + orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + + c := customer.Customer{ID: "cust-1", ProviderID: "stripe-1"} + custSvc.EXPECT().List(mock.Anything, customer.Filter{OrgID: "org-1"}). + Return([]customer.Customer{c}, nil) + subSvc.EXPECT().DeleteByCustomer(mock.Anything, c).Return(nil) + invocSvc.EXPECT().DeleteByCustomer(mock.Anything, c).Return(nil) + custSvc.EXPECT().Delete(mock.Anything, "cust-1").Return(nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteCustomers(context.Background(), "org-1") + assert.NoError(t, err) + }) + + t.Run("skips subscription and invoice delete when no provider", func(t *testing.T) { + orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + + c := customer.Customer{ID: "cust-no-provider", ProviderID: ""} + custSvc.EXPECT().List(mock.Anything, customer.Filter{OrgID: "org-1"}). + Return([]customer.Customer{c}, nil) + // no sub or invoice delete expected + custSvc.EXPECT().Delete(mock.Anything, "cust-no-provider").Return(nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteCustomers(context.Background(), "org-1") + assert.NoError(t, err) + }) +} + +func TestDeleteUser(t *testing.T) { + t.Run("removes user from all orgs then deletes", func(t *testing.T) { + orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc := newMocks(t) + + orgSvc.EXPECT().ListByUser(mock.Anything, mock.Anything, mock.Anything). + Return(nil, nil) + usrSvc.EXPECT().Delete(mock.Anything, "user-1").Return(nil) + + svc := deleter.NewCascadeDeleter(orgSvc, projSvc, resSvc, grpSvc, polSvc, roleSvc, invSvc, usrSvc, custSvc, subSvc, invocSvc) + err := svc.DeleteUser(context.Background(), "user-1") + assert.NoError(t, err) + }) +}