Merge pull request 'change-language' (#58) from change-language into master
Reviewed-on: #58
This commit is contained in:
commit
4098ac8a19
@ -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("select_language", ussdHandlers.SetLanguage)
|
rs.AddLocalFunc("set_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,6 +116,10 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -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("select_language", ussdHandlers.SetLanguage)
|
rs.AddLocalFunc("set_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,6 +86,10 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -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("select_language", ussdHandlers.SetLanguage)
|
rs.AddLocalFunc("set_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,6 +76,10 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -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("select_language", ussdHandlers.SetLanguage)
|
rs.AddLocalFunc("set_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)
|
||||||
|
@ -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
|
|
||||||
|
|
||||||
inputStr := string(input)
|
sym, _ = h.st.Where()
|
||||||
switch inputStr {
|
|
||||||
case "0":
|
switch sym {
|
||||||
res.FlagSet = []uint32{state.FLAG_LANG}
|
case "set_default":
|
||||||
|
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
|
||||||
res.Content = "eng"
|
res.Content = "eng"
|
||||||
case "1":
|
case "set_swa":
|
||||||
res.FlagSet = []uint32{state.FLAG_LANG}
|
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
|
||||||
res.Content = "swa"
|
res.Content = "swa"
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -539,63 +539,55 @@ func TestSetLanguage(t *testing.T) {
|
|||||||
// Define test cases
|
// Define test cases
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input []byte
|
execPath []string
|
||||||
expectedFlags []uint32
|
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
flagManagerResponse uint32
|
|
||||||
flagManagerError error
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "English language",
|
name: "Set Default Language (English)",
|
||||||
input: []byte("0"),
|
execPath: []string{"set_default"},
|
||||||
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: "Swahili language",
|
name: "Set Swahili Language",
|
||||||
input: []byte("1"),
|
execPath: []string{"set_swa"},
|
||||||
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 Input",
|
name: "Unhandled path",
|
||||||
input: []byte("3"),
|
execPath: []string{""},
|
||||||
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", tt.input)
|
res, err := h.SetLanguage(context.Background(), "set_language", nil)
|
||||||
|
|
||||||
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, "Flags should be equal to account created")
|
assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Salio
|
Salio:
|
1
services/registration/change_language
Normal file
1
services/registration/change_language
Normal file
@ -0,0 +1 @@
|
|||||||
|
Select language:
|
10
services/registration/change_language.vis
Normal file
10
services/registration/change_language.vis
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
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 . *
|
1
services/registration/change_language_swa
Normal file
1
services/registration/change_language_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Chagua lugha:
|
@ -1,2 +1 @@
|
|||||||
Your community balance is: 0.00SRF
|
Your community balance is: 0.00SRF
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Community balance
|
Community balance
|
@ -1 +1 @@
|
|||||||
Incorrect pin
|
Incorrect pin
|
1
services/registration/language_changed
Normal file
1
services/registration/language_changed
Normal file
@ -0,0 +1 @@
|
|||||||
|
Your language change request was successful.
|
5
services/registration/language_changed.vis
Normal file
5
services/registration/language_changed.vis
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
MOUT back 0
|
||||||
|
MOUT quit 9
|
||||||
|
HALT
|
||||||
|
INCMP ^ 0
|
||||||
|
INCMP quit 9
|
1
services/registration/language_changed_swa
Normal file
1
services/registration/language_changed_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Ombi lako la kubadilisha lugha limefanikiwa.
|
@ -9,6 +9,7 @@ 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
|
||||||
|
@ -1 +1 @@
|
|||||||
Wasifu wangu
|
Wasifu wangu
|
1
services/registration/quit_menu
Normal file
1
services/registration/quit_menu
Normal file
@ -0,0 +1 @@
|
|||||||
|
Quit
|
1
services/registration/quit_menu_swa
Normal file
1
services/registration/quit_menu_swa
Normal file
@ -0,0 +1 @@
|
|||||||
|
Ondoka
|
@ -1,6 +1,6 @@
|
|||||||
MOUT english 0
|
MOUT english 0
|
||||||
MOUT kiswahili 1
|
MOUT kiswahili 1
|
||||||
HALT
|
HALT
|
||||||
INCMP terms 0
|
INCMP set_default 0
|
||||||
INCMP terms 1
|
INCMP set_swa 1
|
||||||
INCMP . *
|
INCMP . *
|
||||||
|
3
services/registration/set_default.vis
Normal file
3
services/registration/set_default.vis
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
LOAD set_language 6
|
||||||
|
CATCH terms flag_account_created 0
|
||||||
|
MOVE language_changed
|
3
services/registration/set_swa.vis
Normal file
3
services/registration/set_swa.vis
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
LOAD set_language 6
|
||||||
|
CATCH terms flag_account_created 0
|
||||||
|
MOVE language_changed
|
@ -1,5 +1,3 @@
|
|||||||
LOAD select_language 0
|
|
||||||
RELOAD select_language
|
|
||||||
MOUT yes 0
|
MOUT yes 0
|
||||||
MOUT no 1
|
MOUT no 1
|
||||||
HALT
|
HALT
|
||||||
|
@ -1 +1 @@
|
|||||||
Akaunti imeupdatiwa
|
Akaunti imeupdatiwa
|
@ -1 +1,2 @@
|
|||||||
Wasifu wangu
|
Wasifu wangu:
|
||||||
|
{{.get_profile_info}}
|
Loading…
Reference in New Issue
Block a user