From 0062811cb636410b8d64f1535662eaad88300758 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 22 Dec 2025 17:48:07 -0500 Subject: [PATCH] Modified mock package --- internal/store/mock/store.go | 106 ----------------------------------- 1 file changed, 106 deletions(-) diff --git a/internal/store/mock/store.go b/internal/store/mock/store.go index d1c571c..f03fce5 100644 --- a/internal/store/mock/store.go +++ b/internal/store/mock/store.go @@ -5,116 +5,10 @@ import ( "errors" "sync" - "git.kundeng.us/phoenix/textsender-models/tx0/contact" "git.kundeng.us/phoenix/textsender-models/tx0/message" "github.com/google/uuid" ) -type Key struct { - PhoneNumber string - UserId uuid.UUID -} - -type MockContactStore struct { - Contacts map[uuid.UUID]*contact.Contact - ContactsByKey map[Key]*contact.Contact - mu sync.RWMutex - Error error // Optional: simulate errors -} - -func NewMockContactStore() *MockContactStore { - return &MockContactStore{ - Contacts: make(map[uuid.UUID]*contact.Contact), - ContactsByKey: make(map[Key]*contact.Contact), - } -} - -func (m *MockContactStore) CreateContact(ctx context.Context, con *contact.Contact) error { - m.mu.Lock() - defer m.mu.Unlock() - - if m.Error != nil { - return m.Error - } - - if con.Id == uuid.Nil { - con.Id = uuid.New() - } - - key := Key{PhoneNumber: con.PhoneNumber, UserId: con.UserId} - if _, exists := m.ContactsByKey[key]; exists { - return errors.New("Contact with phone number already exists") - } - - m.Contacts[con.Id] = con - m.ContactsByKey[key] = con - return nil -} - -func (m *MockContactStore) GetContactByID(ctx context.Context, id uuid.UUID) (*contact.Contact, error) { - m.mu.Lock() - defer m.mu.Unlock() - - if m.Error != nil { - return nil, m.Error - } - - if m.Error != nil { - return nil, m.Error - } - - con, exists := m.Contacts[id] - if !exists { - return nil, errors.New("Contact not found") - } - - return con, nil -} - -func (m *MockContactStore) GetContactByPhone(ctx context.Context, phoneNumber string, userId uuid.UUID) (*contact.Contact, error) { - m.mu.Lock() - defer m.mu.Unlock() - - if m.Error != nil { - return nil, m.Error - } - - con, exists := m.ContactsByKey[Key{PhoneNumber: phoneNumber, UserId: userId}] - if !exists { - return nil, errors.New("Contact not found") - } - - return con, nil -} - -func (m *MockContactStore) GetAllContacts(ctx context.Context) ([]*contact.Contact, error) { - m.mu.Lock() - defer m.mu.Unlock() - - if m.Error != nil { - return nil, m.Error - } - - cons := make([]*contact.Contact, 0, len(m.Contacts)) - for _, con := range m.Contacts { - cons = append(cons, con) - } - - return cons, nil -} - -func (m *MockContactStore) ContactExists(ctx context.Context, phoneNumber string, userId uuid.UUID) (bool, error) { - m.mu.Lock() - defer m.mu.Unlock() - - if m.Error != nil { - return false, m.Error - } - - _, exists := m.ContactsByKey[Key{PhoneNumber: phoneNumber, UserId: userId}] - - return exists, nil -} type MessageKey struct { Content string