From 12928512264e6144c20169bcde51fed7c704eece Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 19 Dec 2024 13:32:39 +0300 Subject: [PATCH] rename the function to ReplaceSeparatorFunc --- internal/handlers/handlerservice.go | 4 ++-- internal/handlers/ussd/menuhandler.go | 10 +++++----- internal/handlers/ussd/menuhandler_test.go | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index 417fe18..015098e 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -65,11 +65,11 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) { } 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) } - 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 { return nil, err } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index f506793..986f8f0 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -78,10 +78,10 @@ type Handlers struct { accountService remote.AccountServiceInterface prefixDb storage.PrefixDb 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 { 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, prefixDb: prefixDb, profile: &models.Profile{Max: 6}, - ReplaceSeparator: replaceSeparator, + ReplaceSeparatorFunc: replaceSeparatorFunc, } return h, nil } @@ -1685,7 +1685,7 @@ func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) return res, err } - formattedData := h.ReplaceSeparator(string(voucherData)) + formattedData := h.ReplaceSeparatorFunc(string(voucherData)) 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 - 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) } diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index 3c32ee0..c01678d 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -91,15 +91,15 @@ func TestNewHandlers(t *testing.T) { if handlers.userdataStore == nil { t.Fatal("expected userdataStore to be set in handlers") } - if handlers.ReplaceSeparator == nil { - t.Fatal("expected ReplaceSeparator to be set in handlers") + if handlers.ReplaceSeparatorFunc == nil { + t.Fatal("expected ReplaceSeparatorFunc to be set in handlers") } - // Test ReplaceSeparator functionality + // Test ReplaceSeparatorFunc functionality input := "1:Menu item" expectedOutput := "1: Menu item" - if handlers.ReplaceSeparator(input) != expectedOutput { - t.Fatalf("ReplaceSeparator function did not return expected output: got %v, want %v", handlers.ReplaceSeparator(input), expectedOutput) + if handlers.ReplaceSeparatorFunc(input) != expectedOutput { + t.Fatalf("ReplaceSeparatorFunc function did not return expected output: got %v, want %v", handlers.ReplaceSeparatorFunc(input), expectedOutput) } }) @@ -2009,8 +2009,8 @@ func TestGetVoucherList(t *testing.T) { // Initialize Handlers h := &Handlers{ - prefixDb: spdb, - ReplaceSeparator: mockReplaceSeparator, + prefixDb: spdb, + ReplaceSeparatorFunc: mockReplaceSeparator, } mockSyms := []byte("1:SRF\n2:MILO")