Compare commits

...

3 Commits

6 changed files with 76 additions and 11 deletions

View File

@ -91,7 +91,7 @@ func main() {
rfs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
rfs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier)
rfs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus)
rfs.AddLocalFunc("unlock_account", ussdHandlers.Authorize)
rfs.AddLocalFunc("authorize_account", ussdHandlers.Authorize)
rfs.AddLocalFunc("quit", ussdHandlers.Quit)
rfs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
rfs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
@ -110,8 +110,8 @@ func main() {
rfs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
rfs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
rfs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance)
rfs.AddLocalFunc("reset_unlocked", ussdHandlers.ResetAccountAuthorized)
rfs.AddLocalFunc("reset_unlock_for_update", ussdHandlers.ResetAllowUpdate)
rfs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
rfs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
rfs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
rfs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
rfs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)

View File

@ -332,3 +332,67 @@ func TestSavePin(t *testing.T) {
})
}
}
func TestSaveLocation(t *testing.T) {
// Create a new instance of MockAccountFileHandler
mockFileHandler := new(mocks.MockAccountFileHandler)
// Define test cases
tests := []struct {
name string
input []byte
existingData map[string]string
writeError error
expectedResult resource.Result
expectedError error
}{
{
name: "Successful Save",
input: []byte("Mombasa"),
existingData: map[string]string{"Location": "Mombasa"},
writeError: nil,
expectedResult: resource.Result{},
expectedError: nil,
},
{
name: "Empty location input",
input: []byte{},
existingData: map[string]string{"OtherKey": "OtherValue"},
writeError: nil,
expectedResult: resource.Result{},
expectedError: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Set up the mock expectations
mockFileHandler.On("ReadAccountData").Return(tt.existingData, tt.expectedError)
if tt.expectedError == nil && len(tt.input) > 0 {
mockFileHandler.On("WriteAccountData", mock.MatchedBy(func(data map[string]string) bool {
return data["Location"] == string(tt.input)
})).Return(tt.writeError)
}else if len(tt.input) == 0 {
// For empty input, no WriteAccountData call should be made
mockFileHandler.On("WriteAccountData", mock.Anything).Maybe().Return(tt.writeError)
}
// Create the Handlers instance with the mock file handler
h := &Handlers{
accountFileHandler: mockFileHandler,
}
// Call the method
result, err := h.SaveLocation(context.Background(), "save_location", tt.input)
// Assert the results
assert.Equal(t, tt.expectedResult, result)
assert.Equal(t, tt.expectedError, err)
// Assert all expectations were met
mockFileHandler.AssertExpectations(t)
})
}
}

View File

@ -1,6 +1,6 @@
LOAD reset_unlocked 16
LOAD reset_unlock_for_update 0
RELOAD reset_unlock_for_update
LOAD reset_account_authorized 16
LOAD reset_allow_update 0
RELOAD reset_allow_update
MOUT edit_name 1
MOUT edit_gender 2
MOUT edit_yob 3

View File

@ -1,4 +1,4 @@
LOAD reset_unlock_for_update 0
LOAD reset_allow_update 0
MOUT profile 1
MOUT change_language 2
MOUT check_balance 3

View File

@ -1,4 +1,4 @@
LOAD unlock_account 0
LOAD authorize_account 0
HALT
RELOAD unlock_account
RELOAD authorize_account
MOVE _

View File

@ -6,9 +6,10 @@ MAP get_sender
MOUT back 0
MOUT quit 9
HALT
LOAD unlock_account 1
RELOAD unlock_account
LOAD authorize_account 1
RELOAD authorize_account
CATCH incorrect_pin 15 1
INCMP _ 0
INCMP quit 9
MOVE transaction_initiated