Compare commits
No commits in common. "27c7d4f35ba64e94f49e476ea2619a199dcef925" and "eefdc1c0f26b73bb37740a7d1962172b604bedfc" have entirely different histories.
27c7d4f35b
...
eefdc1c0f2
@ -84,7 +84,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
||||
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("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
||||
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
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
||||
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("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
||||
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
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
||||
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("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
||||
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
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
|
||||
return nil, err
|
||||
}
|
||||
ussdHandlers = ussdHandlers.WithPersister(pe)
|
||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage)
|
||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
||||
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
|
||||
func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
var err error
|
||||
|
||||
sym, _ = h.st.Where()
|
||||
|
||||
switch sym {
|
||||
case "set_default":
|
||||
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
|
||||
inputStr := string(input)
|
||||
switch inputStr {
|
||||
case "0":
|
||||
res.FlagSet = []uint32{state.FLAG_LANG}
|
||||
res.Content = "eng"
|
||||
case "set_swa":
|
||||
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
|
||||
case "1":
|
||||
res.FlagSet = []uint32{state.FLAG_LANG}
|
||||
res.Content = "swa"
|
||||
default:
|
||||
}
|
||||
|
@ -539,55 +539,63 @@ func TestSetLanguage(t *testing.T) {
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
name string
|
||||
execPath []string
|
||||
input []byte
|
||||
expectedFlags []uint32
|
||||
expectedResult resource.Result
|
||||
flagManagerResponse uint32
|
||||
flagManagerError error
|
||||
}{
|
||||
{
|
||||
name: "Set Default Language (English)",
|
||||
execPath: []string{"set_default"},
|
||||
name: "English language",
|
||||
input: []byte("0"),
|
||||
expectedFlags: []uint32{state.FLAG_LANG, 123},
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{state.FLAG_LANG, 8},
|
||||
Content: "eng",
|
||||
},
|
||||
flagManagerResponse: 123,
|
||||
flagManagerError: nil,
|
||||
},
|
||||
{
|
||||
name: "Set Swahili Language",
|
||||
execPath: []string{"set_swa"},
|
||||
name: "Swahili language",
|
||||
input: []byte("1"),
|
||||
expectedFlags: []uint32{state.FLAG_LANG, 123},
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{state.FLAG_LANG, 8},
|
||||
Content: "swa",
|
||||
},
|
||||
flagManagerResponse: 123,
|
||||
flagManagerError: nil,
|
||||
},
|
||||
{
|
||||
name: "Unhandled path",
|
||||
execPath: []string{""},
|
||||
name: "Unhandled Input",
|
||||
input: []byte("3"),
|
||||
expectedFlags: []uint32{123},
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{8},
|
||||
},
|
||||
flagManagerResponse: 123,
|
||||
flagManagerError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
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
|
||||
h := &Handlers{
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
// 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 {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// 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")
|
||||
|
||||
})
|
||||
}
|
||||
@ -1688,148 +1696,3 @@ func TestGetProfile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyNewPin(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
||||
mockDataStore := new(mocks.MockUserDataStore)
|
||||
mockCreateAccountService := new(mocks.MockAccountService)
|
||||
h := &Handlers{
|
||||
userdataStore: mockDataStore,
|
||||
flagManager: fm.parser,
|
||||
accountService: mockCreateAccountService,
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test with valid pin",
|
||||
input: []byte("1234"),
|
||||
expectedResult: resource.Result{
|
||||
FlagSet: []uint32{flag_valid_pin},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with invalid pin",
|
||||
input: []byte("123"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_valid_pin},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with invalid pin",
|
||||
input: []byte("12345"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_valid_pin},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
//Call the function under test
|
||||
res, _ := h.VerifyNewPin(ctx, "verify_new_pin", tt.input)
|
||||
|
||||
// Assert that expectations were met
|
||||
mockDataStore.AssertExpectations(t)
|
||||
|
||||
//Assert that the result set to content is what was expected
|
||||
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSaveTemporaryPIn(t *testing.T) {
|
||||
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
// Create a new instance of UserDataStore
|
||||
mockStore := new(mocks.MockUserDataStore)
|
||||
|
||||
// Define test data
|
||||
sessionId := "session123"
|
||||
PIN := "1234"
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
|
||||
// Set up the expected behavior of the mock
|
||||
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(PIN)).Return(nil)
|
||||
|
||||
// Create the Handlers instance with the mock store
|
||||
h := &Handlers{
|
||||
userdataStore: mockStore,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
res, err := h.SaveTemporaryPin(ctx, "save_temporary_pin", []byte(PIN))
|
||||
|
||||
// Assert results
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, resource.Result{}, res)
|
||||
|
||||
// Assert all expectations were met
|
||||
mockStore.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestConfirmPin(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
||||
mockDataStore := new(mocks.MockUserDataStore)
|
||||
mockCreateAccountService := new(mocks.MockAccountService)
|
||||
h := &Handlers{
|
||||
userdataStore: mockDataStore,
|
||||
flagManager: fm.parser,
|
||||
accountService: mockCreateAccountService,
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
temporarypin []byte
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test with correct pin confirmation",
|
||||
input: []byte("1234"),
|
||||
temporarypin: []byte("1234"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_pin_mismatch},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Set up the expected behavior of the mock
|
||||
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_PIN, []byte(tt.temporarypin)).Return(nil)
|
||||
|
||||
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_TEMPORARY_PIN).Return(tt.temporarypin, nil)
|
||||
|
||||
//Call the function under test
|
||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
|
||||
|
||||
// Assert that expectations were met
|
||||
mockDataStore.AssertExpectations(t)
|
||||
|
||||
//Assert that the result set to content is what was expected
|
||||
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
Ongeza mlinzi
|
@ -1 +0,0 @@
|
||||
Weka namba ya simu ya mlinzi unayetaka kuongeza:
|
@ -1 +1 @@
|
||||
Salio:
|
||||
Salio
|
@ -1 +0,0 @@
|
||||
Select language:
|
@ -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 . *
|
@ -1 +0,0 @@
|
||||
Chagua lugha:
|
@ -1 +1,2 @@
|
||||
Your community balance is: 0.00SRF
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
Your language change request was successful.
|
@ -1,5 +0,0 @@
|
||||
MOUT back 0
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP ^ 0
|
||||
INCMP quit 9
|
@ -1 +0,0 @@
|
||||
Ombi lako la kubadilisha lugha limefanikiwa.
|
@ -9,7 +9,6 @@ MOUT back 0
|
||||
HALT
|
||||
INCMP _ 0
|
||||
INCMP edit_profile 1
|
||||
INCMP change_language 2
|
||||
INCMP balances 3
|
||||
INCMP pin_management 5
|
||||
INCMP address 6
|
||||
|
@ -1 +0,0 @@
|
||||
Mipangilio ya PIN:
|
@ -1 +0,0 @@
|
||||
Quit
|
@ -1 +0,0 @@
|
||||
Ondoka
|
@ -1 +0,0 @@
|
||||
Ondoa mlinzi
|
@ -1 +0,0 @@
|
||||
Weka namba ya simu ya mlinzi unayetaka kuondoa:
|
@ -1 +0,0 @@
|
||||
retry
|
@ -1 +0,0 @@
|
||||
jaribu tena
|
@ -1,6 +1,6 @@
|
||||
MOUT english 0
|
||||
MOUT kiswahili 1
|
||||
HALT
|
||||
INCMP set_default 0
|
||||
INCMP set_swa 1
|
||||
INCMP terms 0
|
||||
INCMP terms 1
|
||||
INCMP . *
|
||||
|
@ -1,3 +0,0 @@
|
||||
LOAD set_language 6
|
||||
CATCH terms flag_account_created 0
|
||||
MOVE language_changed
|
@ -1,3 +0,0 @@
|
||||
LOAD set_language 6
|
||||
CATCH terms flag_account_created 0
|
||||
MOVE language_changed
|
@ -1,3 +1,5 @@
|
||||
LOAD select_language 0
|
||||
RELOAD select_language
|
||||
MOUT yes 0
|
||||
MOUT no 1
|
||||
HALT
|
||||
|
@ -1 +0,0 @@
|
||||
Weka PIN yako ili kuona walinzi wako:
|
@ -1 +0,0 @@
|
||||
Angalia walinzi
|
@ -1,2 +1 @@
|
||||
Wasifu wangu:
|
||||
{{.get_profile_info}}
|
||||
Wasifu wangu
|
Loading…
Reference in New Issue
Block a user