Compare commits

..

1 Commits

Author SHA1 Message Date
lash
41e9de845e Merge remote-tracking branch 'origin/master' into wip-pin-reset 2024-09-16 15:07:03 +01:00
61 changed files with 78 additions and 131 deletions

View File

@@ -84,7 +84,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
if err != nil { if err != nil {
return nil, err return nil, err
} }
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@@ -116,10 +116,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@@ -54,7 +54,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
if err != nil { if err != nil {
return nil, err return nil, err
} }
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@@ -86,10 +86,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@@ -44,7 +44,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
if err != nil { if err != nil {
return nil, err return nil, err
} }
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@@ -76,10 +76,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@@ -39,7 +39,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
return nil, err return nil, err
} }
ussdHandlers = ussdHandlers.WithPersister(pe) ussdHandlers = ussdHandlers.WithPersister(pe)
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
@@ -74,7 +74,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
return ussdHandlers, nil return ussdHandlers, nil
} }

View File

@@ -121,15 +121,15 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource
// SetLanguage sets the language across the menu // SetLanguage sets the language across the menu
func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result
var err error
sym, _ = h.st.Where() inputStr := string(input)
switch inputStr {
switch sym { case "0":
case "set_default": res.FlagSet = []uint32{state.FLAG_LANG}
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "eng" res.Content = "eng"
case "set_swa": case "1":
res.FlagSet = append(res.FlagSet, state.FLAG_LANG) res.FlagSet = []uint32{state.FLAG_LANG}
res.Content = "swa" res.Content = "swa"
default: default:
} }
@@ -630,22 +630,6 @@ func (h *Handlers) Quit(ctx context.Context, sym string, input []byte) (resource
return res, nil return res, nil
} }
// QuitWithHelp displays helpline information then exits the menu
func (h *Handlers) QuitWithHelp(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
code := codeFromCtx(ctx)
l := gotext.NewLocale(translationDir, code)
l.AddDomain("default")
res.Content = l.Get("For more help,please call: 0757628885")
res.FlagReset = append(res.FlagReset, flag_account_authorized)
return res, nil
}
// VerifyYob verifies the length of the given input // VerifyYob verifies the length of the given input
func (h *Handlers) VerifyYob(ctx context.Context, sym string, input []byte) (resource.Result, error) { func (h *Handlers) VerifyYob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result

View File

@@ -539,55 +539,63 @@ func TestSetLanguage(t *testing.T) {
// Define test cases // Define test cases
tests := []struct { tests := []struct {
name string name string
execPath []string input []byte
expectedFlags []uint32
expectedResult resource.Result expectedResult resource.Result
flagManagerResponse uint32
flagManagerError error
}{ }{
{ {
name: "Set Default Language (English)", name: "English language",
execPath: []string{"set_default"}, input: []byte("0"),
expectedFlags: []uint32{state.FLAG_LANG, 123},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{state.FLAG_LANG, 8}, FlagSet: []uint32{state.FLAG_LANG, 8},
Content: "eng", Content: "eng",
}, },
flagManagerResponse: 123,
flagManagerError: nil,
}, },
{ {
name: "Set Swahili Language", name: "Swahili language",
execPath: []string{"set_swa"}, input: []byte("1"),
expectedFlags: []uint32{state.FLAG_LANG, 123},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{state.FLAG_LANG, 8}, FlagSet: []uint32{state.FLAG_LANG, 8},
Content: "swa", Content: "swa",
}, },
flagManagerResponse: 123,
flagManagerError: nil,
}, },
{ {
name: "Unhandled path", name: "Unhandled Input",
execPath: []string{""}, input: []byte("3"),
expectedFlags: []uint32{123},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{8}, FlagSet: []uint32{8},
}, },
flagManagerResponse: 123,
flagManagerError: nil,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
mockState := state.NewState(16)
// Set the ExecPath
mockState.ExecPath = tt.execPath
// Create the Handlers instance with the mock flag manager // Create the Handlers instance with the mock flag manager
h := &Handlers{ h := &Handlers{
flagManager: fm.parser, flagManager: fm.parser,
st: mockState,
} }
// Call the method // Call the method
res, err := h.SetLanguage(context.Background(), "set_language", nil) res, err := h.SetLanguage(context.Background(), "set_language", tt.input)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
// Assert that the Result FlagSet has the required flags after language switch // Assert that the Result FlagSet has the required flags after language switch
assert.Equal(t, res, tt.expectedResult, "Result should match expected result") assert.Equal(t, res, tt.expectedResult, "Flags should be equal to account created")
}) })
} }

View File

@@ -1 +1 @@
Rudi Rudi

View File

@@ -1 +1 @@
Balances: Balances:

View File

@@ -1 +1 @@
Salio: Salio

View File

@@ -1 +0,0 @@
Select language:

View File

@@ -1,10 +0,0 @@
LOAD reset_account_authorized 0
LOAD reset_incorrect 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH pin_entry flag_account_authorized 0
MOUT english 0
MOUT kiswahili 1
HALT
INCMP set_default 0
INCMP set_swa 1
INCMP . *

View File

@@ -1 +1 @@
Badili lugha Badili lugha

View File

@@ -1 +0,0 @@
Chagua lugha:

View File

@@ -1 +1 @@
Change PIN Change PIN

View File

@@ -1 +1 @@
Badili PIN Badili PIN

View File

@@ -1 +1 @@
Check statement Check statement

View File

@@ -1 +1,2 @@
Your community balance is: 0.00SRF Your community balance is: 0.00SRF

View File

@@ -1 +1 @@
Community balance Community balance

View File

@@ -1 +1 @@
Edit name Edit name

View File

@@ -1 +1 @@
Weka jina Weka jina

View File

@@ -1 +1 @@
Edit offerings Edit offerings

View File

@@ -1 +1 @@
Enter family name: Enter family name:

View File

@@ -1 +1 @@
Enter your location: Enter your location:

View File

@@ -1 +1 @@
Weka majina yako ya kwanza: Weka majina yako ya kwanza:

View File

@@ -1 +1 @@
Female Female

View File

@@ -1 +1 @@
Guard my PIN Guard my PIN

View File

@@ -1 +1 @@
Linda PIN yangu Linda PIN yangu

View File

@@ -1,2 +0,0 @@
LOAD quit_with_help 0
HALT

View File

@@ -1,2 +1,2 @@
The year of birth you entered is invalid. The year of birth you entered is invalid.
Please try again. Please try again.

View File

@@ -1 +1 @@
Incorrect pin Incorrect pin

View File

@@ -1 +0,0 @@
Your language change request was successful.

View File

@@ -1,5 +0,0 @@
MOUT back 0
MOUT quit 9
HALT
INCMP ^ 0
INCMP quit 9

View File

@@ -1 +0,0 @@
Ombi lako la kubadilisha lugha limefanikiwa.

View File

@@ -6,7 +6,3 @@ msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s."
msgid "Thank you for using Sarafu. Goodbye!" msgid "Thank you for using Sarafu. Goodbye!"
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
msgid "For more help,please call: 0757628885"
msgstr "Kwa usaidizi zaidi,piga: 0757628885"

View File

@@ -10,6 +10,6 @@ HALT
INCMP send 1 INCMP send 1
INCMP quit 2 INCMP quit 2
INCMP my_account 3 INCMP my_account 3
INCMP help 4 INCMP quit 4
INCMP quit 9 INCMP quit 9
INCMP . * INCMP . *

View File

@@ -9,7 +9,6 @@ MOUT back 0
HALT HALT
INCMP _ 0 INCMP _ 0
INCMP edit_profile 1 INCMP edit_profile 1
INCMP change_language 2
INCMP balances 3 INCMP balances 3
INCMP pin_management 5 INCMP pin_management 5
INCMP address 6 INCMP address 6

View File

@@ -1 +1 @@
Anwani yangu Anwani yangu

View File

@@ -1 +1 @@
Salio lako ni: 0.00 SRF Salio lako ni: 0.00 SRF

View File

@@ -1 +1 @@
no no

View File

@@ -1 +1 @@
la la

View File

@@ -1 +1 @@
Tafadhali weka PIN yako Tafadhali weka PIN yako

View File

@@ -1 +1 @@
PIN Management PIN Management

View File

@@ -1 +1 @@
Profile Profile

View File

@@ -1 +1 @@
Wasifu wangu Wasifu wangu

View File

@@ -1 +0,0 @@
Quit

View File

@@ -1 +0,0 @@
Ondoka

View File

@@ -1 +1 @@
Badili PIN ya mwenzio Badili PIN ya mwenzio

View File

@@ -1,6 +1,6 @@
MOUT english 0 MOUT english 0
MOUT kiswahili 1 MOUT kiswahili 1
HALT HALT
INCMP set_default 0 INCMP terms 0
INCMP set_swa 1 INCMP terms 1
INCMP . * INCMP . *

View File

@@ -1 +1 @@
Enter recipient's phone number: Enter recipient's phone number:

View File

@@ -1,3 +0,0 @@
LOAD set_language 6
CATCH terms flag_account_created 0
MOVE language_changed

View File

@@ -1,3 +0,0 @@
LOAD set_language 6
CATCH terms flag_account_created 0
MOVE language_changed

View File

@@ -1,3 +1,5 @@
LOAD select_language 0
RELOAD select_language
MOUT yes 0 MOUT yes 0
MOUT no 1 MOUT no 1
HALT HALT

View File

@@ -1,2 +1,2 @@
{{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}} {{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}}
Please enter your PIN to confirm: Please enter your PIN to confirm:

View File

@@ -1 +1 @@
Unspecified Unspecified

View File

@@ -1 +1 @@
Profile updated successfully Profile updated successfully

View File

@@ -1 +1 @@
Akaunti imeupdatiwa Akaunti imeupdatiwa

View File

@@ -1,2 +1,2 @@
My profile: My profile:
{{.get_profile_info}} {{.get_profile_info}}

View File

@@ -1,2 +1 @@
Wasifu wangu: Wasifu wangu
{{.get_profile_info}}

View File

@@ -1 +1 @@
Angalia Wasifu Angalia Wasifu

View File

@@ -1 +1 @@
yes yes

View File

@@ -1 +1 @@
ndio ndio