add-space-after-colon #211

Merged
lash merged 20 commits from add-space-after-colon into master 2024-12-19 11:35:14 +01:00
3 changed files with 14 additions and 14 deletions
Showing only changes of commit 1292851226 - Show all commits

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)
}
})
@ -2010,7 +2010,7 @@ func TestGetVoucherList(t *testing.T) {
// Initialize Handlers
h := &Handlers{
prefixDb: spdb,
ReplaceSeparator: mockReplaceSeparator,
ReplaceSeparatorFunc: mockReplaceSeparator,
}
mockSyms := []byte("1:SRF\n2:MILO")