Compare commits

..

No commits in common. "c735bf688df25c3965d5fd5bdcc8cd4fff433dab" and "599f7a2857143279e48ed297a23c09a4daacc33f" have entirely different histories.

58 changed files with 107 additions and 153 deletions

View File

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

View File

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

View File

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

View File

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

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

View File

@ -349,7 +349,7 @@ func TestSaveGender(t *testing.T) {
}
// Call the method
_, err := h.SaveGender(ctx, "save_gender", tt.input)
_, err := h.SaveGender(ctx, "someSym", tt.input)
// Assert no error
assert.NoError(t, err)
@ -538,56 +538,64 @@ func TestSetLanguage(t *testing.T) {
}
// Define test cases
tests := []struct {
name string
execPath []string
expectedResult resource.Result
name 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")
})
}
@ -1101,27 +1109,18 @@ func TestCheckAccountStatus(t *testing.T) {
FlagReset: []uint32{flag_account_pending},
},
},
{
name: "Test when account status is not a success",
input: []byte("TrackingId12"),
status: "REVERTED",
expectedResult: resource.Result{
FlagSet: []uint32{flag_account_success},
FlagReset: []uint32{flag_account_pending},
},
},
}
typ := utils.DATA_TRACKING_ID
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
//nn := tt.status
mockCreateAccountService.On("CheckAccountStatus", string(tt.input)).Return(tt.status, nil)
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(tt.status)).Return(nil).Maybe()
// Define expected interactions with the mock
mockDataStore.On("ReadEntry", ctx, sessionId, typ).Return(tt.input, nil)
mockCreateAccountService.On("CheckAccountStatus", string(tt.input)).Return(tt.status, nil)
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_ACCOUNT_STATUS, []byte(tt.status)).Return(nil)
// Call the method under test
res, _ := h.CheckAccountStatus(ctx, "check_status", tt.input)
@ -1298,6 +1297,7 @@ func TestInitiateTransaction(t *testing.T) {
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.PublicKey, nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_AMOUNT).Return(tt.Amount, nil)
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_RECIPIENT).Return(tt.Recipient, nil)
//mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, []byte("")).Return(nil)
// Call the method under test
res, _ := h.InitiateTransaction(ctx, "transaction_reset_amount", tt.input)
@ -1488,7 +1488,7 @@ func TestValidateAmount(t *testing.T) {
if err != nil {
t.Logf(err.Error())
}
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
//flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
mockDataStore := new(mocks.MockUserDataStore)
mockCreateAccountService := new(mocks.MockAccountService)
@ -1517,26 +1517,26 @@ func TestValidateAmount(t *testing.T) {
Content: "0.001",
},
},
{
name: "Test with amount larger than balance",
input: []byte("0.02"),
balance: "0.003 CELO",
publicKey: []byte("0xrqeqrequuq"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_invalid_amount},
Content: "0.02",
},
},
{
name: "Test with invalid amount",
input: []byte("0.02ms"),
balance: "0.003 CELO",
publicKey: []byte("0xrqeqrequuq"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_invalid_amount},
Content: "0.02ms",
},
},
// {
// name: "Test with amount larger than balance",
// input: []byte("0.02"),
// balance: "0.003 CELO",
// publicKey: []byte("0xrqeqrequuq"),
// expectedResult: resource.Result{
// FlagSet: []uint32{flag_invalid_amount},
// Content: "0.02",
// },
// },
// {
// name: "Test with invalid amount",
// input: []byte("0.02ms"),
// balance: "0.003 CELO",
// publicKey: []byte("0xrqeqrequuq"),
// expectedResult: resource.Result{
// FlagSet: []uint32{flag_invalid_amount},
// Content: "0.02ms",
// },
// },
}
for _, tt := range tests {
@ -1544,7 +1544,7 @@ func TestValidateAmount(t *testing.T) {
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return(tt.publicKey, nil)
mockCreateAccountService.On("CheckBalance", string(tt.publicKey)).Return(tt.balance, nil)
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, tt.input).Return(nil).Maybe()
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, tt.input).Return(nil)
// Call the method under test
res, _ := h.ValidateAmount(ctx, "test_validate_amount", tt.input)
@ -1820,19 +1820,11 @@ func TestConfirmPin(t *testing.T) {
FlagReset: []uint32{flag_pin_mismatch},
},
},
{
name: "Test with different pin confirmation",
input: []byte("1234"),
temporarypin: []byte("12345"),
expectedResult: resource.Result{
FlagSet: []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).Maybe()
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)

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 +1,2 @@
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

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

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 kiswahili 1
HALT
INCMP set_default 0
INCMP set_swa 1
INCMP terms 0
INCMP terms 1
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 no 1
HALT

View File

@ -1,2 +1,2 @@
{{.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:
{{.get_profile_info}}
My profile:
{{.get_profile_info}}

View File

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

View File

@ -1 +1 @@
Angalia Wasifu
Angalia Wasifu

View File

@ -1 +1 @@
yes
yes

View File

@ -1 +1 @@
ndio
ndio