forked from grassrootseconomics/visedriver
Compare commits
1 Commits
wip-unit-t
...
wip-pin-re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41e9de845e |
@@ -74,7 +74,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P
|
|||||||
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
||||||
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||||
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||||
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
|
|
||||||
|
|
||||||
return ussdHandlers, nil
|
return ussdHandlers, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -630,22 +630,6 @@ func (h *Handlers) Quit(ctx context.Context, sym string, input []byte) (resource
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuitWithHelp displays helpline information then exits the menu
|
|
||||||
func (h *Handlers) QuitWithHelp(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
|
||||||
var res resource.Result
|
|
||||||
|
|
||||||
flag_account_authorized, _ := h.flagManager.GetFlag("flag_account_authorized")
|
|
||||||
|
|
||||||
code := codeFromCtx(ctx)
|
|
||||||
l := gotext.NewLocale(translationDir, code)
|
|
||||||
l.AddDomain("default")
|
|
||||||
|
|
||||||
res.Content = l.Get("For more help,please call: 0757628885")
|
|
||||||
res.FlagReset = append(res.FlagReset, flag_account_authorized)
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// VerifyYob verifies the length of the given input
|
// VerifyYob verifies the length of the given input
|
||||||
func (h *Handlers) VerifyYob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) VerifyYob(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
|
|||||||
@@ -1696,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,2 +0,0 @@
|
|||||||
LOAD quit_with_help 0
|
|
||||||
HALT
|
|
||||||
@@ -6,7 +6,3 @@ msgstr "Ombi lako limetumwa. %s atapokea %s kutoka kwa %s."
|
|||||||
|
|
||||||
msgid "Thank you for using Sarafu. Goodbye!"
|
msgid "Thank you for using Sarafu. Goodbye!"
|
||||||
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
|
||||||
|
|
||||||
|
|
||||||
msgid "For more help,please call: 0757628885"
|
|
||||||
msgstr "Kwa usaidizi zaidi,piga: 0757628885"
|
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ HALT
|
|||||||
INCMP send 1
|
INCMP send 1
|
||||||
INCMP quit 2
|
INCMP quit 2
|
||||||
INCMP my_account 3
|
INCMP my_account 3
|
||||||
INCMP help 4
|
INCMP quit 4
|
||||||
INCMP quit 9
|
INCMP quit 9
|
||||||
INCMP . *
|
INCMP . *
|
||||||
|
|||||||
Reference in New Issue
Block a user