github.com/dhax/go-base@v0.0.0-20231004214136-8be7e5c1972b/auth/pwdless/mockAuthStore.go (about)

     1  package pwdless
     2  
     3  import "github.com/dhax/go-base/auth/jwt"
     4  
     5  // MockAuthStore mocks AuthStorer interface.
     6  type MockAuthStore struct {
     7  	GetAccountFn      func(id int) (*Account, error)
     8  	GetAccountInvoked bool
     9  
    10  	GetAccountByEmailFn      func(email string) (*Account, error)
    11  	GetAccountByEmailInvoked bool
    12  
    13  	UpdateAccountFn      func(a *Account) error
    14  	UpdateAccountInvoked bool
    15  
    16  	GetTokenFn      func(token string) (*jwt.Token, error)
    17  	GetTokenInvoked bool
    18  
    19  	CreateOrUpdateTokenFn      func(t *jwt.Token) error
    20  	CreateOrUpdateTokenInvoked bool
    21  
    22  	DeleteTokenFn      func(t *jwt.Token) error
    23  	DeleteTokenInvoked bool
    24  
    25  	PurgeExpiredTokenFn      func() error
    26  	PurgeExpiredTokenInvoked bool
    27  }
    28  
    29  // GetAccount mock returns an account by ID.
    30  func (s *MockAuthStore) GetAccount(id int) (*Account, error) {
    31  	s.GetAccountInvoked = true
    32  	return s.GetAccountFn(id)
    33  }
    34  
    35  // GetAccountByEmail mock returns an account by email.
    36  func (s *MockAuthStore) GetAccountByEmail(email string) (*Account, error) {
    37  	s.GetAccountByEmailInvoked = true
    38  	return s.GetAccountByEmailFn(email)
    39  }
    40  
    41  // UpdateAccount mock upates account data related to authentication.
    42  func (s *MockAuthStore) UpdateAccount(a *Account) error {
    43  	s.UpdateAccountInvoked = true
    44  	return s.UpdateAccountFn(a)
    45  }
    46  
    47  // GetToken mock returns an account and refresh token by token identifier.
    48  func (s *MockAuthStore) GetToken(token string) (*jwt.Token, error) {
    49  	s.GetTokenInvoked = true
    50  	return s.GetTokenFn(token)
    51  }
    52  
    53  // CreateOrUpdateToken mock creates or updates a refresh token.
    54  func (s *MockAuthStore) CreateOrUpdateToken(t *jwt.Token) error {
    55  	s.CreateOrUpdateTokenInvoked = true
    56  	return s.CreateOrUpdateTokenFn(t)
    57  }
    58  
    59  // DeleteToken mock deletes a refresh token.
    60  func (s *MockAuthStore) DeleteToken(t *jwt.Token) error {
    61  	s.DeleteTokenInvoked = true
    62  	return s.DeleteTokenFn(t)
    63  }
    64  
    65  // PurgeExpiredToken mock deletes expired refresh token.
    66  func (s *MockAuthStore) PurgeExpiredToken() error {
    67  	s.PurgeExpiredTokenInvoked = true
    68  	return s.PurgeExpiredTokenFn()
    69  }