69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/tinode/chat/server/store/types"
|
|
)
|
|
|
|
type testRegistrationInviteStore struct {
|
|
invite *types.RegistrationInviteCode
|
|
created *types.RegistrationInviteCode
|
|
page *types.RegistrationInvitePage
|
|
batch *types.RegistrationInviteBatch
|
|
err error
|
|
useRecorded bool
|
|
syncedCode int64
|
|
}
|
|
|
|
func (s *testRegistrationInviteStore) Create(_ types.TenantID, code *types.RegistrationInviteCode) error {
|
|
s.created = code
|
|
return s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) CreateBatch(types.TenantID, *types.RegistrationInviteBatch, []types.RegistrationInviteCode) error {
|
|
return s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) GetByCode(types.TenantID, string) (*types.RegistrationInviteCode, error) {
|
|
return s.invite, s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) List(types.TenantID, types.RegistrationInviteListOptions) (*types.RegistrationInvitePage, error) {
|
|
return s.page, s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) GetBatch(types.TenantID, int64) (*types.RegistrationInviteBatch, error) {
|
|
return s.batch, s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) GetBatchByIdempotency(types.TenantID, string) (*types.RegistrationInviteBatch, error) {
|
|
return s.batch, s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) Revoke(types.TenantID, int64, time.Time) error { return s.err }
|
|
func (s *testRegistrationInviteStore) RevokeBatch(types.TenantID, int64, time.Time) (int, error) {
|
|
return 0, s.err
|
|
}
|
|
func (s *testRegistrationInviteStore) RecordUse(types.TenantID, string, types.Uid, string, time.Time) error {
|
|
s.useRecorded = true
|
|
return s.err
|
|
}
|
|
|
|
func (s *testRegistrationInviteStore) SyncUsage(_ types.TenantID, codeID int64) error {
|
|
s.syncedCode = codeID
|
|
return s.err
|
|
}
|
|
|
|
func setRegistrationSMSConfigForTest(enabled bool) {
|
|
registrationSMSConfigCache.Lock()
|
|
defer registrationSMSConfigCache.Unlock()
|
|
registrationSMSConfigCache.value = false
|
|
registrationSMSConfigCache.loaded = false
|
|
registrationSMSConfigCache.loadedAt = time.Time{}
|
|
registrationSMSConfigCache.loadValue = func() (bool, error) { return enabled, nil }
|
|
}
|
|
|
|
func resetRegistrationSMSConfigForTest() {
|
|
registrationSMSConfigCache.Lock()
|
|
defer registrationSMSConfigCache.Unlock()
|
|
registrationSMSConfigCache.value = false
|
|
registrationSMSConfigCache.loaded = false
|
|
registrationSMSConfigCache.loadedAt = time.Time{}
|
|
registrationSMSConfigCache.loadValue = nil
|
|
}
|