Compare commits

...

38 Commits

Author SHA1 Message Date
9647d29bd7
resolve failing test 2024-10-04 11:17:19 +03:00
64cc9bc752
Merge remote-tracking branch 'refs/remotes/origin/menu-traversals' into menu-traversals 2024-10-04 11:13:58 +03:00
ddfd9d4e89
fix failing test 2024-10-04 11:11:41 +03:00
a1201e2525
Merge remote-tracking branch 'remotes/origin/master' into menu-traversals 2024-10-03 17:13:40 +03:00
ddeafe015b Merge pull request 'tests-update' (#100) from tests-update into master
Reviewed-on: #100
2024-09-27 22:14:50 +02:00
a3ff3be5b1
clean up 2024-09-27 16:32:47 +03:00
ea52a7cf0a
update tests 2024-09-26 23:11:37 +03:00
a993026380
update tests 2024-09-26 23:07:48 +03:00
lash
4ee241714b
Attempt 2 revert changes from ssh 2024-09-26 15:08:15 +01:00
lash
d7dc743fa2 Merge remote-tracking branch 'origin/master' 2024-09-26 15:07:13 +01:00
lash
c220cbb767
Revert accidental merge of ssh 2024-09-26 15:05:17 +01:00
0dc322729f Merge pull request 'SSH server entry point.' (#77) from lash/ssh-2 into master
Reviewed-on: #77
2024-09-26 15:55:51 +02:00
726d6dd338 Merge pull request 'menu-profile-edit' (#82) from menu-profile-edit into master
Reviewed-on: #82
2024-09-26 15:48:55 +02:00
a8b202bd79 Merge branch 'master' into menu-profile-edit 2024-09-25 15:19:04 +02:00
6dbd250694
remove extra spaces 2024-09-25 09:29:26 +03:00
cc760e7698
remove move 2024-09-25 09:20:45 +03:00
8648ea599c
add catch node 2024-09-25 09:20:45 +03:00
77e4c5d43a
reset the positon of LOAD function 2024-09-25 09:20:44 +03:00
b15ba367c4
change position of LOAD function 2024-09-25 09:20:44 +03:00
4db862bc97
LOAD and RELOAD get_amount 2024-09-25 09:20:43 +03:00
6ad67f6adc
change position of LOAD 2024-09-25 09:20:42 +03:00
0dea34daab
resolve confilict 2024-09-24 09:18:21 +03:00
8057313c78
Merge remote-tracking branch 'remotes/origin/master' into menu-profile-edit 2024-09-24 09:10:17 +03:00
1bd96d0689
setup dedicated nodes for case selection 2024-09-24 09:02:04 +03:00
bbfe46f162
use current rendering symbol for case selection 2024-09-24 09:01:19 +03:00
eff2cbde8b
setup check for unused code 2024-09-24 09:00:31 +03:00
5c85ecffd1
remove unused code 2024-09-24 09:00:13 +03:00
lash
ad1f9233ca Merge branch 'master' into lash/ssh-2 2024-09-23 20:26:47 +01:00
lash
c18c40b1b8 Merge branch 'lash/thread-gdbm' into lash/ssh-2 2024-09-23 18:56:38 +01:00
lash
a07fce527f Merge branch 'lash/thread-gdbm' into lash/ssh-2 2024-09-22 16:26:59 +01:00
lash
ddc8f6dad1
Update module dep 2024-09-22 16:24:09 +01:00
lash
c2b68231f5
Update gitignore 2024-09-22 16:15:40 +01:00
lash
3f3dbf414c
Clarify keyfile use in readme 2024-09-22 16:13:30 +01:00
lash
e4c3e9f015
Add ssh instructions, log host key 2024-09-22 16:09:57 +01:00
lash
9b71244391 Merge branch 'lash/thread-gdbm' into lash/ssh-2 2024-09-22 15:43:18 +01:00
lash
ada1f26b68
Add keystore class, separate keystore tool executable 2024-09-22 15:41:55 +01:00
lash
935b777e57
Factor out ssh service code 2024-09-22 14:41:01 +01:00
lash
19372c17f4
Reinstate ssh executable 2024-09-22 03:06:24 +01:00
17 changed files with 173 additions and 234 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@ go.work*
**/*/*.bin
**/*/.state/
cmd/.state/
id_*
*.gdbm

View File

@ -6,6 +6,7 @@ import (
"os"
"path"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource"
@ -20,7 +21,7 @@ var (
scriptDir = path.Join(baseDir, "services", "registration")
)
func TestEngine(sessionId string) (engine.Engine, func()) {
func TestEngine(sessionId string) (engine.Engine, func(), *db.Db) {
ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId)
pfp := path.Join(scriptDir, "pp.csv")
@ -98,5 +99,5 @@ func TestEngine(sessionId string) (engine.Engine, func()) {
}
//en = en.WithDebug(nil)
return en, cleanFn
return en, cleanFn, lhs.UserdataStore
}

View File

@ -88,7 +88,6 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) {
ls.DbRs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
ls.DbRs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
ls.DbRs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
ls.DbRs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
ls.DbRs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
ls.DbRs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)

View File

@ -118,16 +118,13 @@ func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (r
var res resource.Result
symbol, _ := h.st.Where()
code := strings.Split(symbol, "_")[1]
switch symbol {
case "set_default":
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "eng"
case "set_swa":
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = "swa"
default:
if !utils.IsValidISO639(code) {
return res, nil
}
res.FlagSet = append(res.FlagSet, state.FLAG_LANG)
res.Content = code
languageSetFlag, err := h.flagManager.GetFlag("flag_language_set")
if err != nil {
@ -319,32 +316,6 @@ func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byt
return res, nil
}
// SetResetSingleEdit sets and resets flags to allow gradual editing of profile information.
func (h *Handlers) SetResetSingleEdit(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
menuOption := string(input)
flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update")
flag_single_edit, _ := h.flagManager.GetFlag("flag_single_edit")
switch menuOption {
case "2":
res.FlagReset = append(res.FlagReset, flag_allow_update)
res.FlagSet = append(res.FlagSet, flag_single_edit)
case "3":
res.FlagReset = append(res.FlagReset, flag_allow_update)
res.FlagSet = append(res.FlagSet, flag_single_edit)
case "4":
res.FlagReset = append(res.FlagReset, flag_allow_update)
res.FlagSet = append(res.FlagSet, flag_single_edit)
default:
res.FlagReset = append(res.FlagReset, flag_single_edit)
}
return res, nil
}
// VerifyPin checks whether the confirmation PIN is similar to the account PIN
// If similar, it sets the USERFLAG_PIN_SET flag allowing the user
// to access the main menu
@ -475,6 +446,7 @@ func (h *Handlers) SaveLocation(ctx context.Context, sym string, input []byte) (
// SaveGender updates the gender in the gdbm with the provided input.
func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (resource.Result, error) {
symbol, _ := h.st.Where()
var res resource.Result
var err error
sessionId, ok := ctx.Value("SessionId").(string)
@ -482,22 +454,12 @@ func (h *Handlers) SaveGender(ctx context.Context, sym string, input []byte) (re
return res, fmt.Errorf("missing session")
}
if len(input) > 0 {
gender := string(input)
switch gender {
case "1":
gender = "Male"
case "2":
gender = "Female"
case "3":
gender = "Unspecified"
}
gender := strings.Split(symbol, "_")[1]
store := h.userdataStore
err = store.WriteEntry(ctx, sessionId, utils.DATA_GENDER, []byte(gender))
if err != nil {
return res, nil
}
}
return res, nil
}

View File

@ -9,6 +9,7 @@ import (
"testing"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/state"
"git.grassecon.net/urdt/ussd/internal/mocks"
@ -16,6 +17,7 @@ import (
"git.grassecon.net/urdt/ussd/internal/utils"
"github.com/alecthomas/assert/v2"
testdataloader "github.com/peteole/testdata-loader"
"github.com/stretchr/testify/require"
)
var (
@ -94,6 +96,25 @@ func TestCreateAccount(t *testing.T) {
mockDataStore.AssertExpectations(t)
}
func TestWithPersister(t *testing.T) {
// Test case: Setting a persister
h := &Handlers{}
p := &persist.Persister{}
result := h.WithPersister(p)
assert.Equal(t, p, h.pe, "The persister should be set correctly.")
assert.Equal(t, h, result, "The returned handler should be the same instance.")
}
func TestWithPersister_PanicWhenAlreadySet(t *testing.T) {
// Test case: Panic on multiple calls
h := &Handlers{pe: &persist.Persister{}}
require.Panics(t, func() {
h.WithPersister(&persist.Persister{})
}, "Should panic when trying to set a persister again.")
}
func TestSaveFirstname(t *testing.T) {
// Create a new instance of MockMyDataStore
mockStore := new(mocks.MockUserDataStore)
@ -295,6 +316,7 @@ func TestSaveOfferings(t *testing.T) {
func TestSaveGender(t *testing.T) {
// Create a new instance of MockMyDataStore
mockStore := new(mocks.MockUserDataStore)
mockState := state.NewState(16)
// Define the session ID and context
sessionId := "session123"
@ -306,31 +328,29 @@ func TestSaveGender(t *testing.T) {
input []byte
expectedGender string
expectCall bool
executingSymbol string
}{
{
name: "Valid Male Input",
input: []byte("1"),
expectedGender: "Male",
expectedGender: "male",
executingSymbol: "set_male",
expectCall: true,
},
{
name: "Valid Female Input",
input: []byte("2"),
expectedGender: "Female",
expectedGender: "female",
executingSymbol: "set_female",
expectCall: true,
},
{
name: "Valid Unspecified Input",
input: []byte("3"),
expectedGender: "Unspecified",
executingSymbol: "set_unspecified",
expectedGender: "unspecified",
expectCall: true,
},
{
name: "Empty Input",
input: []byte(""),
expectedGender: "",
expectCall: false,
},
}
for _, tt := range tests {
@ -342,14 +362,15 @@ func TestSaveGender(t *testing.T) {
} else {
mockStore.On("WriteEntry", ctx, sessionId, utils.DATA_GENDER, []byte(tt.expectedGender)).Return(nil)
}
mockState.ExecPath = append(mockState.ExecPath, tt.executingSymbol)
// Create the Handlers instance with the mock store
h := &Handlers{
userdataStore: mockStore,
st: mockState,
}
// Call the method
_, err := h.SaveGender(ctx, "someSym", tt.input)
_, err := h.SaveGender(ctx, "save_gender", tt.input)
// Assert no error
assert.NoError(t, err)
@ -544,7 +565,7 @@ func TestSetLanguage(t *testing.T) {
}{
{
name: "Set Default Language (English)",
execPath: []string{"set_default"},
execPath: []string{"set_eng"},
expectedResult: resource.Result{
FlagSet: []uint32{state.FLAG_LANG, 8},
Content: "eng",
@ -558,13 +579,6 @@ func TestSetLanguage(t *testing.T) {
Content: "swa",
},
},
{
name: "Unhandled path",
execPath: []string{""},
expectedResult: resource.Result{
FlagSet: []uint32{8},
},
},
}
for _, tt := range tests {
@ -592,76 +606,6 @@ func TestSetLanguage(t *testing.T) {
})
}
}
func TestSetResetSingleEdit(t *testing.T) {
fm, err := NewFlagManager(flagsPath)
flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
flag_single_edit, _ := fm.parser.GetFlag("flag_single_edit")
if err != nil {
log.Fatal(err)
}
// Define test cases
tests := []struct {
name string
input []byte
expectedResult resource.Result
}{
{
name: "Set single Edit",
input: []byte("2"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_single_edit},
FlagReset: []uint32{flag_allow_update},
},
},
{
name: "Set single Edit",
input: []byte("3"),
expectedResult: resource.Result{
FlagSet: []uint32{flag_single_edit},
FlagReset: []uint32{flag_allow_update},
},
},
{
name: "Set single edit",
input: []byte("4"),
expectedResult: resource.Result{
FlagReset: []uint32{flag_allow_update},
FlagSet: []uint32{flag_single_edit},
},
},
{
name: "No single edit set",
input: []byte("1"),
expectedResult: resource.Result{
FlagReset: []uint32{flag_single_edit},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Create the Handlers instance with the mock flag manager
h := &Handlers{
flagManager: fm.parser,
}
// Call the method
res, err := h.SetResetSingleEdit(context.Background(), "set_reset_single_edit", 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, "Flags should match reset edit")
})
}
}
func TestResetAllowUpdate(t *testing.T) {
fm, err := NewFlagManager(flagsPath)
@ -1483,7 +1427,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)
@ -1512,26 +1456,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 {
@ -1539,7 +1483,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)
mockDataStore.On("WriteEntry", ctx, sessionId, utils.DATA_AMOUNT, tt.input).Return(nil).Maybe()
// Call the method under test
res, _ := h.ValidateAmount(ctx, "test_validate_amount", tt.input)
@ -1651,6 +1595,7 @@ func TestGetProfile(t *testing.T) {
mockDataStore := new(mocks.MockUserDataStore)
mockCreateAccountService := new(mocks.MockAccountService)
h := &Handlers{
userdataStore: mockDataStore,
accountService: mockCreateAccountService,

11
internal/utils/isocode.go Normal file
View File

@ -0,0 +1,11 @@
package utils
var isoCodes = map[string]bool{
"eng": true, // English
"swa": true, // Swahili
}
func IsValidISO639(code string) bool {
return isoCodes[code]
}

View File

@ -0,0 +1 @@
Something went wrong.Please try again

View File

@ -0,0 +1 @@
HALT

View File

@ -12,8 +12,6 @@ MOUT view 7
MOUT back 0
HALT
INCMP my_account 0
LOAD set_reset_single_edit 0
RELOAD set_reset_single_edit
INCMP enter_name 1
INCMP enter_familyname 2
INCMP select_gender 3

View File

@ -1,11 +1,15 @@
CATCH incorrect_pin flag_incorrect_pin 1
CATCH profile_update_success flag_allow_update 1
LOAD save_gender 0
MOUT male 1
MOUT female 2
MOUT unspecified 3
MOUT back 0
HALT
RELOAD save_gender
INCMP _ 0
INCMP pin_entry *
INCMP set_male 1
INCMP set_female 2
INCMP set_unspecified 3

View File

@ -1,6 +1,6 @@
MOUT english 0
MOUT kiswahili 1
HALT
INCMP set_default 0
INCMP set_eng 0
INCMP set_swa 1
INCMP . *

View File

@ -0,0 +1,4 @@
LOAD save_gender 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH profile_update_success flag_allow_update 1
MOVE pin_entry

View File

@ -0,0 +1,4 @@
LOAD save_gender 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH profile_update_success flag_allow_update 1
MOVE pin_entry

View File

@ -0,0 +1,4 @@
LOAD save_gender 0
CATCH incorrect_pin flag_incorrect_pin 1
CATCH profile_update_success flag_allow_update 1
MOVE pin_entry

View File

@ -3,6 +3,7 @@ package main
import (
"bytes"
"context"
"fmt"
"regexp"
"testing"
"time"
@ -43,7 +44,7 @@ func TestMain(m *testing.M) {
}
func TestAccountCreationSuccessful(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -77,7 +78,7 @@ func TestAccountCreationSuccessful(t *testing.T) {
func TestAccountRegistrationRejectTerms(t *testing.T) {
// Generate a new UUID for this edge case test
edgeCaseSessionID := GenerateUUID()
en, fn := enginetest.TestEngine(edgeCaseSessionID)
en, fn, _ := enginetest.TestEngine(edgeCaseSessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -108,7 +109,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
}
func TestSendWithInvalidInputs(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -146,7 +147,7 @@ func TestSendWithInvalidInputs(t *testing.T) {
}
func TestMyAccount_Check_My_Balance(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -177,7 +178,7 @@ func TestMyAccount_Check_My_Balance(t *testing.T) {
}
func TestMainMenuHelp(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -208,7 +209,7 @@ func TestMainMenuHelp(t *testing.T) {
}
func TestMainMenuQuit(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -239,7 +240,7 @@ func TestMainMenuQuit(t *testing.T) {
}
func TestMyAccount_Check_Community_Balance(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -270,7 +271,7 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) {
}
func TestMyAccountChangePin(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -301,7 +302,7 @@ func TestMyAccountChangePin(t *testing.T) {
}
func TestMyAccount_Change_Language(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -332,7 +333,7 @@ func TestMyAccount_Change_Language(t *testing.T) {
}
func TestMyAccount_Edit_firstname(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -363,7 +364,7 @@ func TestMyAccount_Edit_firstname(t *testing.T) {
}
func TestMyAccount_Edit_familyname(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -394,7 +395,7 @@ func TestMyAccount_Edit_familyname(t *testing.T) {
}
func TestMyAccount_Edit_gender(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -416,6 +417,7 @@ func TestMyAccount_Edit_gender(t *testing.T) {
t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err)
}
b := w.Bytes()
fmt.Println("Content:", string(b))
if !bytes.Equal(b, []byte(step.ExpectedContent)) {
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b)
}
@ -425,7 +427,7 @@ func TestMyAccount_Edit_gender(t *testing.T) {
}
func TestMyAccount_Edit_yob(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -456,7 +458,7 @@ func TestMyAccount_Edit_yob(t *testing.T) {
}
func TestMyAccount_Edit_location(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -487,7 +489,7 @@ func TestMyAccount_Edit_location(t *testing.T) {
}
func TestMyAccount_Edit_offerings(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -496,37 +498,7 @@ func TestMyAccount_Edit_offerings(t *testing.T) {
for _, group := range groups {
for index, step := range group.Steps {
t.Logf("step %v with input %v", index, step.Input)
cont, err := en.Exec(ctx, []byte(step.Input))
if err != nil {
t.Errorf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
return
}
if !cont {
break
}
w := bytes.NewBuffer(nil)
if _, err := en.Flush(ctx, w); err != nil {
t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err)
}
b := w.Bytes()
if !bytes.Equal(b, []byte(step.ExpectedContent)) {
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b)
}
}
}
}
}
func TestMyAccount_View_Profile(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
for _, session := range sessions {
groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_view_profile")
for _, group := range groups {
for index, step := range group.Steps {
t.Logf("step %v with input %v", index, step.Input)
cont, err := en.Exec(ctx, []byte(step.Input))
if err != nil {
t.Errorf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
@ -549,7 +521,7 @@ func TestMyAccount_View_Profile(t *testing.T) {
}
func TestMyAccount_MyAddress(t *testing.T) {
en, fn := enginetest.TestEngine(sessionID)
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
@ -583,3 +555,34 @@ func TestMyAccount_MyAddress(t *testing.T) {
}
}
}
func TestMyAccount_View_Profile(t *testing.T) {
en, fn, _ := enginetest.TestEngine(sessionID)
defer fn()
ctx := context.Background()
sessions := testData
for _, session := range sessions {
groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_view_profile")
for _, group := range groups {
for index, step := range group.Steps {
t.Logf("step %v with input %v", index, step.Input)
cont, err := en.Exec(ctx, []byte(step.Input))
if err != nil {
t.Errorf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
return
}
if !cont {
break
}
w := bytes.NewBuffer(nil)
if _, err := en.Flush(ctx, w); err != nil {
t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err)
}
b := w.Bytes()
if !bytes.Equal(b, []byte(step.ExpectedContent)) {
t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b)
}
}
}
}
}

View File

@ -291,7 +291,7 @@
"expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back"
},
{
"input": "Female",
"input": "1",
"expectedContent": "Please enter your PIN:"
},
{
@ -399,7 +399,7 @@
},
{
"input": "9",
"expectedContent": "Thank you for using Sarafu. Goodbye!"
"expectedContent": "Thank you for using Sarafu. Goodbye!{{.Variable}}"
}
]
},
@ -424,7 +424,7 @@
},
{
"input": "1234",
"expectedContent": "My profile:\nName: foo bar\nGender: Female\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back"
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back"
},
{
"input": "0",