rename the function to ReplaceSeparatorFunc

This commit is contained in:
Alfred Kamanda 2024-12-19 13:32:39 +03:00
parent 97fcdda12f
commit 1292851226
Signed by untrusted user: Alfred-mk
GPG Key ID: 7EA3D01708908703
3 changed files with 14 additions and 14 deletions

View File

@ -65,11 +65,11 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) {
} }
func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*ussd.Handlers, error) { func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceInterface) (*ussd.Handlers, error) {
replaceSeparator := func(input string) string { replaceSeparatorFunc := func(input string) string {
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator) return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
} }
ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparator) ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -78,10 +78,10 @@ type Handlers struct {
accountService remote.AccountServiceInterface accountService remote.AccountServiceInterface
prefixDb storage.PrefixDb prefixDb storage.PrefixDb
profile *models.Profile profile *models.Profile
ReplaceSeparator func(string) string ReplaceSeparatorFunc func(string) string
} }
func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountServiceInterface, replaceSeparator func(string) string) (*Handlers, error) { func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *utils.AdminStore, accountService remote.AccountServiceInterface, replaceSeparatorFunc func(string) string) (*Handlers, error) {
if userdataStore == nil { if userdataStore == nil {
return nil, fmt.Errorf("cannot create handler with nil userdata store") return nil, fmt.Errorf("cannot create handler with nil userdata store")
} }
@ -100,7 +100,7 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, adminstore *util
accountService: accountService, accountService: accountService,
prefixDb: prefixDb, prefixDb: prefixDb,
profile: &models.Profile{Max: 6}, profile: &models.Profile{Max: 6},
ReplaceSeparator: replaceSeparator, ReplaceSeparatorFunc: replaceSeparatorFunc,
} }
return h, nil return h, nil
} }
@ -1685,7 +1685,7 @@ func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte)
return res, err return res, err
} }
formattedData := h.ReplaceSeparator(string(voucherData)) formattedData := h.ReplaceSeparatorFunc(string(voucherData))
res.Content = string(formattedData) res.Content = string(formattedData)
@ -1906,7 +1906,7 @@ func (h *Handlers) GetTransactionsList(ctx context.Context, sym string, input []
} }
// Use the ReplaceSeparator function for the menu separator // Use the ReplaceSeparator function for the menu separator
transactionLine := fmt.Sprintf("%d%s%s %s %s %s", i+1, h.ReplaceSeparator(":"), status, value, sym, date) transactionLine := fmt.Sprintf("%d%s%s %s %s %s", i+1, h.ReplaceSeparatorFunc(":"), status, value, sym, date)
formattedTransactions = append(formattedTransactions, transactionLine) formattedTransactions = append(formattedTransactions, transactionLine)
} }

View File

@ -91,15 +91,15 @@ func TestNewHandlers(t *testing.T) {
if handlers.userdataStore == nil { if handlers.userdataStore == nil {
t.Fatal("expected userdataStore to be set in handlers") t.Fatal("expected userdataStore to be set in handlers")
} }
if handlers.ReplaceSeparator == nil { if handlers.ReplaceSeparatorFunc == nil {
t.Fatal("expected ReplaceSeparator to be set in handlers") t.Fatal("expected ReplaceSeparatorFunc to be set in handlers")
} }
// Test ReplaceSeparator functionality // Test ReplaceSeparatorFunc functionality
input := "1:Menu item" input := "1:Menu item"
expectedOutput := "1: Menu item" expectedOutput := "1: Menu item"
if handlers.ReplaceSeparator(input) != expectedOutput { if handlers.ReplaceSeparatorFunc(input) != expectedOutput {
t.Fatalf("ReplaceSeparator function did not return expected output: got %v, want %v", handlers.ReplaceSeparator(input), expectedOutput) t.Fatalf("ReplaceSeparatorFunc function did not return expected output: got %v, want %v", handlers.ReplaceSeparatorFunc(input), expectedOutput)
} }
}) })
@ -2010,7 +2010,7 @@ func TestGetVoucherList(t *testing.T) {
// Initialize Handlers // Initialize Handlers
h := &Handlers{ h := &Handlers{
prefixDb: spdb, prefixDb: spdb,
ReplaceSeparator: mockReplaceSeparator, ReplaceSeparatorFunc: mockReplaceSeparator,
} }
mockSyms := []byte("1:SRF\n2:MILO") mockSyms := []byte("1:SRF\n2:MILO")