Compare commits

...

17 Commits

Author SHA1 Message Date
c735bf688d
update tests 2024-09-18 11:26:18 +03:00
4098ac8a19 Merge pull request 'change-language' (#58) from change-language into master
Reviewed-on: #58
2024-09-17 18:31:10 +02:00
2982f08b41 Merge branch 'master' into change-language 2024-09-17 18:30:52 +02:00
75ab9c66a3
run TestSetLanguage with execPath instead of input 2024-09-17 18:54:07 +03:00
95f02231b3 Merge pull request 'Unit tests' (#62) from wip-unit-tests into master
Reviewed-on: #62
2024-09-17 15:55:33 +02:00
2e7c07e6f4
added missing functions to the other getHandlers 2024-09-17 15:31:44 +03:00
01f7571185
use dedicated nodes to set the language 2024-09-17 15:29:21 +03:00
065c8e5c1d
use a single set_language function for setting and changing language 2024-09-17 15:26:50 +03:00
dc14480519 remove extra space 2024-09-16 17:29:27 +03:00
aaf4923f64 ensure a PIN is set before changing the language 2024-09-16 17:29:27 +03:00
e9c645bd87 added the profile info on the swa menu template 2024-09-16 17:29:27 +03:00
1be6da9139 remove new lines on templates and menus to clean up the empty spaces on the menu 2024-09-16 17:29:27 +03:00
fa2930d93a added quit menu to handle eng and swa 2024-09-16 17:29:27 +03:00
a409e292ab add the change_language functionality to the account menu 2024-09-16 17:29:27 +03:00
00c86a2850 change language 2024-09-16 17:29:27 +03:00
4daac7e90b added change_language node and templates 2024-09-16 17:29:27 +03:00
06e23565df added the SetNewLanguage function 2024-09-16 17:29:27 +03:00
58 changed files with 153 additions and 107 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("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
} }

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("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
} }

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("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
} }

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("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)

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

View File

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

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

View 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 . *

View File

@ -1 +1 @@
Badili lugha Badili lugha

View File

@ -0,0 +1 @@
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,2 +1 @@
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. The year of birth you entered is invalid.
Please try again. Please try again.

View File

@ -1 +1 @@
Incorrect pin Incorrect pin

View File

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

View File

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

View File

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

View File

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

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

@ -0,0 +1 @@
Quit

View File

@ -0,0 +1 @@
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 terms 0 INCMP set_default 0
INCMP terms 1 INCMP set_swa 1
INCMP . * INCMP . *

View File

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

View File

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

View File

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

View File

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

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