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: 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) {
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
}

View File

@ -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)
}

View File

@ -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")