diff --git a/mocks/biz/SettingRepo.go b/mocks/biz/SettingRepo.go index 1ced4c34..8c71783b 100644 --- a/mocks/biz/SettingRepo.go +++ b/mocks/biz/SettingRepo.go @@ -9,8 +9,6 @@ import ( mock "github.com/stretchr/testify/mock" - otp "github.com/pquerna/otp" - request "github.com/tnb-labs/panel/internal/http/request" ) @@ -73,118 +71,6 @@ func (_c *SettingRepo_Delete_Call) RunAndReturn(run func(biz.SettingKey) error) return _c } -// GenerateAPIKey provides a mock function with no fields -func (_m *SettingRepo) GenerateAPIKey() (string, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GenerateAPIKey") - } - - var r0 string - var r1 error - if rf, ok := ret.Get(0).(func() (string, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// SettingRepo_GenerateAPIKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateAPIKey' -type SettingRepo_GenerateAPIKey_Call struct { - *mock.Call -} - -// GenerateAPIKey is a helper method to define mock.On call -func (_e *SettingRepo_Expecter) GenerateAPIKey() *SettingRepo_GenerateAPIKey_Call { - return &SettingRepo_GenerateAPIKey_Call{Call: _e.mock.On("GenerateAPIKey")} -} - -func (_c *SettingRepo_GenerateAPIKey_Call) Run(run func()) *SettingRepo_GenerateAPIKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *SettingRepo_GenerateAPIKey_Call) Return(_a0 string, _a1 error) *SettingRepo_GenerateAPIKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *SettingRepo_GenerateAPIKey_Call) RunAndReturn(run func() (string, error)) *SettingRepo_GenerateAPIKey_Call { - _c.Call.Return(run) - return _c -} - -// GenerateTwoFAKey provides a mock function with no fields -func (_m *SettingRepo) GenerateTwoFAKey() (*otp.Key, error) { - ret := _m.Called() - - if len(ret) == 0 { - panic("no return value specified for GenerateTwoFAKey") - } - - var r0 *otp.Key - var r1 error - if rf, ok := ret.Get(0).(func() (*otp.Key, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() *otp.Key); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*otp.Key) - } - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// SettingRepo_GenerateTwoFAKey_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateTwoFAKey' -type SettingRepo_GenerateTwoFAKey_Call struct { - *mock.Call -} - -// GenerateTwoFAKey is a helper method to define mock.On call -func (_e *SettingRepo_Expecter) GenerateTwoFAKey() *SettingRepo_GenerateTwoFAKey_Call { - return &SettingRepo_GenerateTwoFAKey_Call{Call: _e.mock.On("GenerateTwoFAKey")} -} - -func (_c *SettingRepo_GenerateTwoFAKey_Call) Run(run func()) *SettingRepo_GenerateTwoFAKey_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *SettingRepo_GenerateTwoFAKey_Call) Return(_a0 *otp.Key, _a1 error) *SettingRepo_GenerateTwoFAKey_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *SettingRepo_GenerateTwoFAKey_Call) RunAndReturn(run func() (*otp.Key, error)) *SettingRepo_GenerateTwoFAKey_Call { - _c.Call.Return(run) - return _c -} - // Get provides a mock function with given fields: key, defaultValue func (_m *SettingRepo) Get(key biz.SettingKey, defaultValue ...string) (string, error) { _va := make([]interface{}, len(defaultValue)) diff --git a/mocks/biz/UserRepo.go b/mocks/biz/UserRepo.go index 0b8e044b..b4eef6f8 100644 --- a/mocks/biz/UserRepo.go +++ b/mocks/biz/UserRepo.go @@ -3,8 +3,11 @@ package biz import ( - mock "github.com/stretchr/testify/mock" + image "image" + biz "github.com/tnb-labs/panel/internal/biz" + + mock "github.com/stretchr/testify/mock" ) // UserRepo is an autogenerated mock type for the UserRepo type @@ -138,6 +141,124 @@ func (_c *UserRepo_Create_Call) RunAndReturn(run func(string, string) (*biz.User return _c } +// Delete provides a mock function with given fields: id +func (_m *UserRepo) Delete(id uint) error { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint) error); ok { + r0 = rf(id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UserRepo_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type UserRepo_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - id uint +func (_e *UserRepo_Expecter) Delete(id interface{}) *UserRepo_Delete_Call { + return &UserRepo_Delete_Call{Call: _e.mock.On("Delete", id)} +} + +func (_c *UserRepo_Delete_Call) Run(run func(id uint)) *UserRepo_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint)) + }) + return _c +} + +func (_c *UserRepo_Delete_Call) Return(_a0 error) *UserRepo_Delete_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *UserRepo_Delete_Call) RunAndReturn(run func(uint) error) *UserRepo_Delete_Call { + _c.Call.Return(run) + return _c +} + +// GenerateTwoFA provides a mock function with given fields: id +func (_m *UserRepo) GenerateTwoFA(id uint) (image.Image, string, string, error) { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for GenerateTwoFA") + } + + var r0 image.Image + var r1 string + var r2 string + var r3 error + if rf, ok := ret.Get(0).(func(uint) (image.Image, string, string, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(uint) image.Image); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(image.Image) + } + } + + if rf, ok := ret.Get(1).(func(uint) string); ok { + r1 = rf(id) + } else { + r1 = ret.Get(1).(string) + } + + if rf, ok := ret.Get(2).(func(uint) string); ok { + r2 = rf(id) + } else { + r2 = ret.Get(2).(string) + } + + if rf, ok := ret.Get(3).(func(uint) error); ok { + r3 = rf(id) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// UserRepo_GenerateTwoFA_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GenerateTwoFA' +type UserRepo_GenerateTwoFA_Call struct { + *mock.Call +} + +// GenerateTwoFA is a helper method to define mock.On call +// - id uint +func (_e *UserRepo_Expecter) GenerateTwoFA(id interface{}) *UserRepo_GenerateTwoFA_Call { + return &UserRepo_GenerateTwoFA_Call{Call: _e.mock.On("GenerateTwoFA", id)} +} + +func (_c *UserRepo_GenerateTwoFA_Call) Run(run func(id uint)) *UserRepo_GenerateTwoFA_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint)) + }) + return _c +} + +func (_c *UserRepo_GenerateTwoFA_Call) Return(_a0 image.Image, _a1 string, _a2 string, _a3 error) *UserRepo_GenerateTwoFA_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *UserRepo_GenerateTwoFA_Call) RunAndReturn(run func(uint) (image.Image, string, string, error)) *UserRepo_GenerateTwoFA_Call { + _c.Call.Return(run) + return _c +} + // Get provides a mock function with given fields: id func (_m *UserRepo) Get(id uint) (*biz.User, error) { ret := _m.Called(id) @@ -196,17 +317,139 @@ func (_c *UserRepo_Get_Call) RunAndReturn(run func(uint) (*biz.User, error)) *Us return _c } -// Save provides a mock function with given fields: user -func (_m *UserRepo) Save(user *biz.User) error { - ret := _m.Called(user) +// IsTwoFA provides a mock function with given fields: username +func (_m *UserRepo) IsTwoFA(username string) (bool, error) { + ret := _m.Called(username) if len(ret) == 0 { - panic("no return value specified for Save") + panic("no return value specified for IsTwoFA") + } + + var r0 bool + var r1 error + if rf, ok := ret.Get(0).(func(string) (bool, error)); ok { + return rf(username) + } + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(username) + } else { + r0 = ret.Get(0).(bool) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(username) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UserRepo_IsTwoFA_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsTwoFA' +type UserRepo_IsTwoFA_Call struct { + *mock.Call +} + +// IsTwoFA is a helper method to define mock.On call +// - username string +func (_e *UserRepo_Expecter) IsTwoFA(username interface{}) *UserRepo_IsTwoFA_Call { + return &UserRepo_IsTwoFA_Call{Call: _e.mock.On("IsTwoFA", username)} +} + +func (_c *UserRepo_IsTwoFA_Call) Run(run func(username string)) *UserRepo_IsTwoFA_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *UserRepo_IsTwoFA_Call) Return(_a0 bool, _a1 error) *UserRepo_IsTwoFA_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *UserRepo_IsTwoFA_Call) RunAndReturn(run func(string) (bool, error)) *UserRepo_IsTwoFA_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function with given fields: page, limit +func (_m *UserRepo) List(page uint, limit uint) ([]*biz.User, int64, error) { + ret := _m.Called(page, limit) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 []*biz.User + var r1 int64 + var r2 error + if rf, ok := ret.Get(0).(func(uint, uint) ([]*biz.User, int64, error)); ok { + return rf(page, limit) + } + if rf, ok := ret.Get(0).(func(uint, uint) []*biz.User); ok { + r0 = rf(page, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*biz.User) + } + } + + if rf, ok := ret.Get(1).(func(uint, uint) int64); ok { + r1 = rf(page, limit) + } else { + r1 = ret.Get(1).(int64) + } + + if rf, ok := ret.Get(2).(func(uint, uint) error); ok { + r2 = rf(page, limit) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// UserRepo_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type UserRepo_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - page uint +// - limit uint +func (_e *UserRepo_Expecter) List(page interface{}, limit interface{}) *UserRepo_List_Call { + return &UserRepo_List_Call{Call: _e.mock.On("List", page, limit)} +} + +func (_c *UserRepo_List_Call) Run(run func(page uint, limit uint)) *UserRepo_List_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint), args[1].(uint)) + }) + return _c +} + +func (_c *UserRepo_List_Call) Return(_a0 []*biz.User, _a1 int64, _a2 error) *UserRepo_List_Call { + _c.Call.Return(_a0, _a1, _a2) + return _c +} + +func (_c *UserRepo_List_Call) RunAndReturn(run func(uint, uint) ([]*biz.User, int64, error)) *UserRepo_List_Call { + _c.Call.Return(run) + return _c +} + +// UpdatePassword provides a mock function with given fields: id, password +func (_m *UserRepo) UpdatePassword(id uint, password string) error { + ret := _m.Called(id, password) + + if len(ret) == 0 { + panic("no return value specified for UpdatePassword") } var r0 error - if rf, ok := ret.Get(0).(func(*biz.User) error); ok { - r0 = rf(user) + if rf, ok := ret.Get(0).(func(uint, string) error); ok { + r0 = rf(id, password) } else { r0 = ret.Error(0) } @@ -214,30 +457,79 @@ func (_m *UserRepo) Save(user *biz.User) error { return r0 } -// UserRepo_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' -type UserRepo_Save_Call struct { +// UserRepo_UpdatePassword_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdatePassword' +type UserRepo_UpdatePassword_Call struct { *mock.Call } -// Save is a helper method to define mock.On call -// - user *biz.User -func (_e *UserRepo_Expecter) Save(user interface{}) *UserRepo_Save_Call { - return &UserRepo_Save_Call{Call: _e.mock.On("Save", user)} +// UpdatePassword is a helper method to define mock.On call +// - id uint +// - password string +func (_e *UserRepo_Expecter) UpdatePassword(id interface{}, password interface{}) *UserRepo_UpdatePassword_Call { + return &UserRepo_UpdatePassword_Call{Call: _e.mock.On("UpdatePassword", id, password)} } -func (_c *UserRepo_Save_Call) Run(run func(user *biz.User)) *UserRepo_Save_Call { +func (_c *UserRepo_UpdatePassword_Call) Run(run func(id uint, password string)) *UserRepo_UpdatePassword_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*biz.User)) + run(args[0].(uint), args[1].(string)) }) return _c } -func (_c *UserRepo_Save_Call) Return(_a0 error) *UserRepo_Save_Call { +func (_c *UserRepo_UpdatePassword_Call) Return(_a0 error) *UserRepo_UpdatePassword_Call { _c.Call.Return(_a0) return _c } -func (_c *UserRepo_Save_Call) RunAndReturn(run func(*biz.User) error) *UserRepo_Save_Call { +func (_c *UserRepo_UpdatePassword_Call) RunAndReturn(run func(uint, string) error) *UserRepo_UpdatePassword_Call { + _c.Call.Return(run) + return _c +} + +// UpdateTwoFA provides a mock function with given fields: id, code, secret +func (_m *UserRepo) UpdateTwoFA(id uint, code string, secret string) error { + ret := _m.Called(id, code, secret) + + if len(ret) == 0 { + panic("no return value specified for UpdateTwoFA") + } + + var r0 error + if rf, ok := ret.Get(0).(func(uint, string, string) error); ok { + r0 = rf(id, code, secret) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UserRepo_UpdateTwoFA_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateTwoFA' +type UserRepo_UpdateTwoFA_Call struct { + *mock.Call +} + +// UpdateTwoFA is a helper method to define mock.On call +// - id uint +// - code string +// - secret string +func (_e *UserRepo_Expecter) UpdateTwoFA(id interface{}, code interface{}, secret interface{}) *UserRepo_UpdateTwoFA_Call { + return &UserRepo_UpdateTwoFA_Call{Call: _e.mock.On("UpdateTwoFA", id, code, secret)} +} + +func (_c *UserRepo_UpdateTwoFA_Call) Run(run func(id uint, code string, secret string)) *UserRepo_UpdateTwoFA_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint), args[1].(string), args[2].(string)) + }) + return _c +} + +func (_c *UserRepo_UpdateTwoFA_Call) Return(_a0 error) *UserRepo_UpdateTwoFA_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *UserRepo_UpdateTwoFA_Call) RunAndReturn(run func(uint, string, string) error) *UserRepo_UpdateTwoFA_Call { _c.Call.Return(run) return _c } diff --git a/mocks/biz/UserTokenRepo.go b/mocks/biz/UserTokenRepo.go new file mode 100644 index 00000000..275a7e53 --- /dev/null +++ b/mocks/biz/UserTokenRepo.go @@ -0,0 +1,198 @@ +// Code generated by mockery. DO NOT EDIT. + +package biz + +import ( + mock "github.com/stretchr/testify/mock" + biz "github.com/tnb-labs/panel/internal/biz" +) + +// UserTokenRepo is an autogenerated mock type for the UserTokenRepo type +type UserTokenRepo struct { + mock.Mock +} + +type UserTokenRepo_Expecter struct { + mock *mock.Mock +} + +func (_m *UserTokenRepo) EXPECT() *UserTokenRepo_Expecter { + return &UserTokenRepo_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: userID, ips +func (_m *UserTokenRepo) Create(userID uint, ips []string) (*biz.UserToken, error) { + ret := _m.Called(userID, ips) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *biz.UserToken + var r1 error + if rf, ok := ret.Get(0).(func(uint, []string) (*biz.UserToken, error)); ok { + return rf(userID, ips) + } + if rf, ok := ret.Get(0).(func(uint, []string) *biz.UserToken); ok { + r0 = rf(userID, ips) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*biz.UserToken) + } + } + + if rf, ok := ret.Get(1).(func(uint, []string) error); ok { + r1 = rf(userID, ips) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UserTokenRepo_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type UserTokenRepo_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - userID uint +// - ips []string +func (_e *UserTokenRepo_Expecter) Create(userID interface{}, ips interface{}) *UserTokenRepo_Create_Call { + return &UserTokenRepo_Create_Call{Call: _e.mock.On("Create", userID, ips)} +} + +func (_c *UserTokenRepo_Create_Call) Run(run func(userID uint, ips []string)) *UserTokenRepo_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint), args[1].([]string)) + }) + return _c +} + +func (_c *UserTokenRepo_Create_Call) Return(_a0 *biz.UserToken, _a1 error) *UserTokenRepo_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *UserTokenRepo_Create_Call) RunAndReturn(run func(uint, []string) (*biz.UserToken, error)) *UserTokenRepo_Create_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function with given fields: id +func (_m *UserTokenRepo) Get(id uint) (*biz.UserToken, error) { + ret := _m.Called(id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 *biz.UserToken + var r1 error + if rf, ok := ret.Get(0).(func(uint) (*biz.UserToken, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(uint) *biz.UserToken); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*biz.UserToken) + } + } + + if rf, ok := ret.Get(1).(func(uint) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UserTokenRepo_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type UserTokenRepo_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - id uint +func (_e *UserTokenRepo_Expecter) Get(id interface{}) *UserTokenRepo_Get_Call { + return &UserTokenRepo_Get_Call{Call: _e.mock.On("Get", id)} +} + +func (_c *UserTokenRepo_Get_Call) Run(run func(id uint)) *UserTokenRepo_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(uint)) + }) + return _c +} + +func (_c *UserTokenRepo_Get_Call) Return(_a0 *biz.UserToken, _a1 error) *UserTokenRepo_Get_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *UserTokenRepo_Get_Call) RunAndReturn(run func(uint) (*biz.UserToken, error)) *UserTokenRepo_Get_Call { + _c.Call.Return(run) + return _c +} + +// Save provides a mock function with given fields: user +func (_m *UserTokenRepo) Save(user *biz.UserToken) error { + ret := _m.Called(user) + + if len(ret) == 0 { + panic("no return value specified for Save") + } + + var r0 error + if rf, ok := ret.Get(0).(func(*biz.UserToken) error); ok { + r0 = rf(user) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UserTokenRepo_Save_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Save' +type UserTokenRepo_Save_Call struct { + *mock.Call +} + +// Save is a helper method to define mock.On call +// - user *biz.UserToken +func (_e *UserTokenRepo_Expecter) Save(user interface{}) *UserTokenRepo_Save_Call { + return &UserTokenRepo_Save_Call{Call: _e.mock.On("Save", user)} +} + +func (_c *UserTokenRepo_Save_Call) Run(run func(user *biz.UserToken)) *UserTokenRepo_Save_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*biz.UserToken)) + }) + return _c +} + +func (_c *UserTokenRepo_Save_Call) Return(_a0 error) *UserTokenRepo_Save_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *UserTokenRepo_Save_Call) RunAndReturn(run func(*biz.UserToken) error) *UserTokenRepo_Save_Call { + _c.Call.Return(run) + return _c +} + +// NewUserTokenRepo creates a new instance of UserTokenRepo. 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 NewUserTokenRepo(t interface { + mock.TestingT + Cleanup(func()) +}) *UserTokenRepo { + mock := &UserTokenRepo{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}