From 188cb573dd713278b417d8fab9ea1bdc0ec6f9cb Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 25 Sep 2024 13:27:13 +0300 Subject: [PATCH 01/65] add dummy vouchers list --- internal/handlers/handlerservice.go | 1 + internal/handlers/ussd/menuhandler.go | 32 ++++++++++++++++++++++++ services/registration/main.vis | 2 +- services/registration/select_voucher | 2 ++ services/registration/select_voucher.vis | 9 +++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 services/registration/select_voucher create mode 100644 services/registration/select_voucher.vis diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index 1d6f5fd..b733efe 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -94,6 +94,7 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) { ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp) + ls.DbRs.AddLocalFunc("get_vouchers",ussdHandlers.GetVoucherList) return ussdHandlers, nil } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index ff8d8bd..7902cd2 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -254,6 +254,38 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt return res, nil } + +func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) (resource.Result,error){ + var res resource.Result + vouchers := []string{ + "SRF", + "CRF", + "VCF", + "VSAPA", + "FSTMP", + "FSAW", + "PTAQ", + "VCRXT", + "VSGAQ", + "QPWIQQ", + "FSTMP", + "FSAW", + "PTAQ", + "VCRXT", + "VSGAQ", + "QPWIQQ", + "FSTMP", + "FSAW", + "PTAQ", + "VCRXT", + "VSGAQ", + "QPWIQQ", + } + res.Content = strings.Join(vouchers,"\n") + + return res,nil +} + func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result sessionId, ok := ctx.Value("SessionId").(string) diff --git a/services/registration/main.vis b/services/registration/main.vis index d883dca..b5d791d 100644 --- a/services/registration/main.vis +++ b/services/registration/main.vis @@ -8,7 +8,7 @@ MOUT help 4 MOUT quit 9 HALT INCMP send 1 -INCMP quit 2 +INCMP select_voucher 2 INCMP my_account 3 INCMP help 4 INCMP quit 9 diff --git a/services/registration/select_voucher b/services/registration/select_voucher new file mode 100644 index 0000000..084b9b8 --- /dev/null +++ b/services/registration/select_voucher @@ -0,0 +1,2 @@ +Select number or symbol from your vouchers: +{{.get_vouchers}} \ No newline at end of file diff --git a/services/registration/select_voucher.vis b/services/registration/select_voucher.vis new file mode 100644 index 0000000..3919f71 --- /dev/null +++ b/services/registration/select_voucher.vis @@ -0,0 +1,9 @@ +LOAD get_vouchers 0 +MAP get_vouchers +MNEXT next 11 +MPREV back 22 +HALT +INCMP > 11 +INCMP < 22 +INCMP _* + -- 2.45.2 From 7aa44caea27c8e45f5ac2a02e20c123430ccf0fa Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 25 Sep 2024 15:57:23 +0300 Subject: [PATCH 02/65] add voucher nodes --- services/registration/main.vis | 2 +- services/registration/my_vouchers | 1 + services/registration/my_vouchers.vis | 9 +++++++++ services/registration/select_voucher_menu | 1 + services/registration/voucher_details_menu | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 services/registration/my_vouchers create mode 100644 services/registration/my_vouchers.vis create mode 100644 services/registration/select_voucher_menu create mode 100644 services/registration/voucher_details_menu diff --git a/services/registration/main.vis b/services/registration/main.vis index b5d791d..1009039 100644 --- a/services/registration/main.vis +++ b/services/registration/main.vis @@ -8,7 +8,7 @@ MOUT help 4 MOUT quit 9 HALT INCMP send 1 -INCMP select_voucher 2 +INCMP my_vouchers 2 INCMP my_account 3 INCMP help 4 INCMP quit 9 diff --git a/services/registration/my_vouchers b/services/registration/my_vouchers new file mode 100644 index 0000000..548de9c --- /dev/null +++ b/services/registration/my_vouchers @@ -0,0 +1 @@ +My vouchers \ No newline at end of file diff --git a/services/registration/my_vouchers.vis b/services/registration/my_vouchers.vis new file mode 100644 index 0000000..b70dbfa --- /dev/null +++ b/services/registration/my_vouchers.vis @@ -0,0 +1,9 @@ +MOUT select_voucher 1 +MOUT voucher_details 2 +MOUT back 0 +HALT +INCMP _ 0 +INCMP select_voucher 1 + + + diff --git a/services/registration/select_voucher_menu b/services/registration/select_voucher_menu new file mode 100644 index 0000000..8ee06df --- /dev/null +++ b/services/registration/select_voucher_menu @@ -0,0 +1 @@ +Select voucher \ No newline at end of file diff --git a/services/registration/voucher_details_menu b/services/registration/voucher_details_menu new file mode 100644 index 0000000..a588f23 --- /dev/null +++ b/services/registration/voucher_details_menu @@ -0,0 +1 @@ +Voucher details \ No newline at end of file -- 2.45.2 From 0e376e0d9e0bc7164bff7e4314c8ffb74ce5306a Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 25 Sep 2024 16:03:08 +0300 Subject: [PATCH 03/65] include back and quit --- services/registration/select_voucher.vis | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/registration/select_voucher.vis b/services/registration/select_voucher.vis index 3919f71..4fb1d40 100644 --- a/services/registration/select_voucher.vis +++ b/services/registration/select_voucher.vis @@ -1,9 +1,11 @@ LOAD get_vouchers 0 MAP get_vouchers +MOUT back 0 +MOUT quit 9 MNEXT next 11 -MPREV back 22 +MPREV prev 22 HALT +INCMP _ 0 +INCMP quit 9 INCMP > 11 INCMP < 22 -INCMP _* - -- 2.45.2 From 221db4e998ce4b5bcda91e6f99ec3aec18f28fbb Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 25 Sep 2024 16:06:06 +0300 Subject: [PATCH 04/65] return a numbered list of vouchers --- internal/handlers/ussd/menuhandler.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 7902cd2..e998bd5 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -281,7 +281,12 @@ func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) ( "VSGAQ", "QPWIQQ", } - res.Content = strings.Join(vouchers,"\n") + + var numberedVouchers []string + for i, voucher := range vouchers { + numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, voucher)) + } + res.Content = strings.Join(numberedVouchers,"\n") return res,nil } -- 2.45.2 From ece80b31f6f476b051e264c1cbd5274279ddd5fd Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 26 Sep 2024 21:27:54 +0300 Subject: [PATCH 05/65] start menu traversal tests setup --- internal/handlers/ussd/menu_traversal_test.go | 141 ++++++++++++++++++ testdata/main.vis | 0 testdata/testdata.go | 119 +++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 internal/handlers/ussd/menu_traversal_test.go create mode 100644 testdata/main.vis create mode 100644 testdata/testdata.go diff --git a/internal/handlers/ussd/menu_traversal_test.go b/internal/handlers/ussd/menu_traversal_test.go new file mode 100644 index 0000000..86c909d --- /dev/null +++ b/internal/handlers/ussd/menu_traversal_test.go @@ -0,0 +1,141 @@ +package ussd + +import ( + "bytes" + "context" + "fmt" + "path" + "testing" + + "git.defalsify.org/vise.git/db" + fsdb "git.defalsify.org/vise.git/db/fs" + "git.defalsify.org/vise.git/engine" + "git.defalsify.org/vise.git/persist" + "git.defalsify.org/vise.git/resource" + "git.grassecon.net/urdt/ussd/internal/storage" + "git.grassecon.net/urdt/ussd/testdata" + testdataloader "github.com/peteole/testdata-loader" +) + +var ( + dataGenerated bool = false + dataDir string = testdata.DataDir + BaseDir = testdataloader.GetBasePath() +) + +type testWrapper struct { + resource.Resource + db db.Db +} + +func generateTestData(t *testing.T) { + if dataGenerated { + return + } + var err error + dataDir, err = testdata.Generate() + if err != nil { + t.Fatal(err) + } +} + +func newTestWrapper(path string) testWrapper { + ctx := context.Background() + store := fsdb.NewFsDb() + store.Connect(ctx, path) + rs := resource.NewDbResource(store) + rs.With(db.DATATYPE_STATICLOAD) + wr := testWrapper{ + rs, + store, + } + rs.AddLocalFunc("quit", quit) + + return wr +} + +func quit(ctx context.Context, sym string, input []byte) (resource.Result, error) { + return resource.Result{ + Content: "Thank you for using Sarafu network", + }, nil +} + +func TestTerms(t *testing.T) { + generateTestData(t) + ctx := context.Background() + rs := newTestWrapper(dataDir) + cfg := engine.Config{ + Root: "terms", + FlagCount: uint32(9), + } + store := storage.NewThreadGdbmDb() + storeFile := path.Join(baseDir, "state.gdbm") + err := store.Connect(ctx, storeFile) + if err != nil { + t.Fail() + } + + pr := persist.NewPersister(store) + en := engine.NewEngine(cfg, &rs) + en.WithPersister(pr) + if pr.GetState() == nil || pr.GetMemory() == nil { + t.Fail() + } + _, err = en.Exec(ctx, []byte{}) + if err != nil { + t.Fatal(err) + } + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(err) + } + b := w.Bytes() + + expect_str := `Do you agree to terms and conditions? +1:yes +2:no` + + if !bytes.Equal(b, []byte(expect_str)) { + t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect_str, b) + } + + tests := []struct { + name string + expectedSymbol string + input []byte + }{ + { + name: "Test accept terms option(yes)", + expectedSymbol: "create_pin", + input: []byte("1"), + }, + // { + // name: "Test reject terms option(no)", + // input: []byte("2"), + // expectedSymbol: "quit", + // }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err = en.Exec(ctx, tt.input) + if err != nil { + t.Fatal(err) + } + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(err) + } + + b = w.Bytes() + fmt.Println("result", string(b)) + symbol, _ := pr.State.Where() + + if symbol != tt.expectedSymbol { + t.Fatalf("expected symbol to be 'create_pin', got %s", symbol) + } + }) + } +} diff --git a/testdata/main.vis b/testdata/main.vis new file mode 100644 index 0000000..e69de29 diff --git a/testdata/testdata.go b/testdata/testdata.go new file mode 100644 index 0000000..b3b1f00 --- /dev/null +++ b/testdata/testdata.go @@ -0,0 +1,119 @@ +package testdata + +import ( + "context" + "io/ioutil" + "os" + "path" + "git.defalsify.org/vise.git/db" + fsdb "git.defalsify.org/vise.git/db/fs" + "git.defalsify.org/vise.git/logging" + "git.defalsify.org/vise.git/vm" + testdataloader "github.com/peteole/testdata-loader" +) + + + +func outNew(sym string, b []byte, tpl string, data map[string]string) error { + logg.Debugf("testdata out", "sym", sym) + store.SetPrefix(db.DATATYPE_TEMPLATE) + err := store.Put(ctx, []byte(sym), []byte(tpl)) + if err != nil { + return err + } + store.SetPrefix(db.DATATYPE_BIN) + err = store.Put(ctx, []byte(sym), b) + if err != nil { + return err + } + store.SetPrefix(db.DATATYPE_STATICLOAD) + for k, v := range data { + logg.Debugf("testdata out staticload", "sym", sym, "k", k, "v", v) + err = store.Put(ctx, []byte(k), []byte(v)) + if err != nil { + return err + } + } + return nil +} + +var ( + ctx = context.Background() + store = fsdb.NewFsDb() + out = outNew + logg = logging.NewVanilla().WithDomain("testdata") + BaseDir = testdataloader.GetBasePath() + DataDir = "" + dirLock = false +) + +type genFunc func() error + +func terms() error { + b := []byte{} + b = vm.NewLine(b, vm.MOUT, []string{"yes", "1"}, nil, nil) + b = vm.NewLine(b, vm.MOUT, []string{"no", "2"}, nil, nil) + b = vm.NewLine(b, vm.HALT, nil, nil, nil) + b = vm.NewLine(b, vm.INCMP, []string{"create_pin", "1"}, nil, nil) + b = vm.NewLine(b, vm.INCMP, []string{"quit", "2"}, nil, nil) + tpl := "Do you agree to terms and conditions?" + return out("terms", b, tpl, nil) +} + +func createPin() error { + b := []byte{} + b = vm.NewLine(b, vm.MOUT, []string{"exit", "0"}, nil, nil) + b = vm.NewLine(b, vm.HALT, nil, nil, nil) + b = vm.NewLine(b, vm.INCMP, []string{"0", "1"}, nil, nil) + tpl := "create pin" + return out("create_pin", b, tpl, nil) +} + +func quit() error { + // b := []byte{} + // b = vm.NewLine(b, vm.LOAD, []string{"quit"}, []byte{0x00}, nil) + // //b = vm.NewLine(b, vm.RELOAD, []string{"quit"}, []byte{0x00}, nil) + // b = vm.NewLine(b, vm.HALT, nil, nil, nil) + + // return out("quit", b, "quit", nil) + b := vm.NewLine(nil, vm.LOAD, []string{"quit"}, []byte{0x00}, nil) + b = vm.NewLine(b, vm.RELOAD, []string{"quit"}, nil, nil) + b = vm.NewLine(b, vm.HALT, nil, nil, nil) + + fp := path.Join(DataDir, "nothing.bin") + err := os.WriteFile(fp, b, 0600) + return err +} + +func generate() error { + err := os.MkdirAll(DataDir, 0755) + if err != nil { + return err + } + store = fsdb.NewFsDb() + store.Connect(ctx, DataDir) + store.SetLock(db.DATATYPE_TEMPLATE, false) + store.SetLock(db.DATATYPE_BIN, false) + store.SetLock(db.DATATYPE_MENU, false) + store.SetLock(db.DATATYPE_STATICLOAD, false) + + fns := []genFunc{terms, createPin, quit} + for _, fn := range fns { + err = fn() + if err != nil { + return err + } + } + return nil +} + +func Generate() (string, error) { + dir, err := ioutil.TempDir("", "vise_testdata_") + if err != nil { + return "", err + } + DataDir = dir + dirLock = true + err = generate() + return dir, err +} -- 2.45.2 From afe98b8695ec6187d9f6b3fc5fff7acfebe91dcf Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 27 Sep 2024 15:02:29 +0300 Subject: [PATCH 06/65] setup traversal tests --- enginetest/engine.go | 88 +++++++++++ internal/handlers/ussd/menu_traversal_test.go | 141 ------------------ menu_traversal_test.go | 61 ++++++++ test_data.json | 18 +++ testdata/testdata.go | 5 +- 5 files changed, 169 insertions(+), 144 deletions(-) create mode 100644 enginetest/engine.go delete mode 100644 internal/handlers/ussd/menu_traversal_test.go create mode 100644 menu_traversal_test.go create mode 100644 test_data.json diff --git a/enginetest/engine.go b/enginetest/engine.go new file mode 100644 index 0000000..f6ab886 --- /dev/null +++ b/enginetest/engine.go @@ -0,0 +1,88 @@ +package enginetest + +import ( + "context" + "fmt" + "os" + "path" + + "git.defalsify.org/vise.git/engine" + "git.defalsify.org/vise.git/logging" + "git.defalsify.org/vise.git/persist" + "git.defalsify.org/vise.git/resource" + "git.grassecon.net/urdt/ussd/internal/handlers" + "git.grassecon.net/urdt/ussd/internal/storage" +) +var ( + logg = logging.NewVanilla() + scriptDir = path.Join("services", "registration") +) + +func TestEngine(sessionId string) (engine.Engine,*persist.Persister){ + ctx := context.Background() + ctx = context.WithValue(ctx, "SessionId", sessionId) + pfp := path.Join(scriptDir, "pp.csv") + + cfg := engine.Config{ + Root: "root", + SessionId: sessionId, + OutputSize: uint32(106), + FlagCount: uint32(16), + } + + dbDir := ".test_state" + resourceDir := scriptDir + menuStorageService := storage.NewMenuStorageService(dbDir, resourceDir) + + err := menuStorageService.EnsureDbDir() + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + rs, err := menuStorageService.GetResource(ctx) + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + pe, err := menuStorageService.GetPersister(ctx) + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + userdatastore, err := menuStorageService.GetUserdataDb(ctx) + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + dbResource, ok := rs.(*resource.DbResource) + if !ok { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) + lhs.SetDataStore(&userdatastore) + lhs.SetPersister(pe) + + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + hl, err := lhs.GetHandler() + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + + en := lhs.GetEngine() + en = en.WithFirst(hl.Init) + + //en = en.WithDebug(nil) + return en,pe + +} diff --git a/internal/handlers/ussd/menu_traversal_test.go b/internal/handlers/ussd/menu_traversal_test.go deleted file mode 100644 index 86c909d..0000000 --- a/internal/handlers/ussd/menu_traversal_test.go +++ /dev/null @@ -1,141 +0,0 @@ -package ussd - -import ( - "bytes" - "context" - "fmt" - "path" - "testing" - - "git.defalsify.org/vise.git/db" - fsdb "git.defalsify.org/vise.git/db/fs" - "git.defalsify.org/vise.git/engine" - "git.defalsify.org/vise.git/persist" - "git.defalsify.org/vise.git/resource" - "git.grassecon.net/urdt/ussd/internal/storage" - "git.grassecon.net/urdt/ussd/testdata" - testdataloader "github.com/peteole/testdata-loader" -) - -var ( - dataGenerated bool = false - dataDir string = testdata.DataDir - BaseDir = testdataloader.GetBasePath() -) - -type testWrapper struct { - resource.Resource - db db.Db -} - -func generateTestData(t *testing.T) { - if dataGenerated { - return - } - var err error - dataDir, err = testdata.Generate() - if err != nil { - t.Fatal(err) - } -} - -func newTestWrapper(path string) testWrapper { - ctx := context.Background() - store := fsdb.NewFsDb() - store.Connect(ctx, path) - rs := resource.NewDbResource(store) - rs.With(db.DATATYPE_STATICLOAD) - wr := testWrapper{ - rs, - store, - } - rs.AddLocalFunc("quit", quit) - - return wr -} - -func quit(ctx context.Context, sym string, input []byte) (resource.Result, error) { - return resource.Result{ - Content: "Thank you for using Sarafu network", - }, nil -} - -func TestTerms(t *testing.T) { - generateTestData(t) - ctx := context.Background() - rs := newTestWrapper(dataDir) - cfg := engine.Config{ - Root: "terms", - FlagCount: uint32(9), - } - store := storage.NewThreadGdbmDb() - storeFile := path.Join(baseDir, "state.gdbm") - err := store.Connect(ctx, storeFile) - if err != nil { - t.Fail() - } - - pr := persist.NewPersister(store) - en := engine.NewEngine(cfg, &rs) - en.WithPersister(pr) - if pr.GetState() == nil || pr.GetMemory() == nil { - t.Fail() - } - _, err = en.Exec(ctx, []byte{}) - if err != nil { - t.Fatal(err) - } - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatal(err) - } - b := w.Bytes() - - expect_str := `Do you agree to terms and conditions? -1:yes -2:no` - - if !bytes.Equal(b, []byte(expect_str)) { - t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expect_str, b) - } - - tests := []struct { - name string - expectedSymbol string - input []byte - }{ - { - name: "Test accept terms option(yes)", - expectedSymbol: "create_pin", - input: []byte("1"), - }, - // { - // name: "Test reject terms option(no)", - // input: []byte("2"), - // expectedSymbol: "quit", - // }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - _, err = en.Exec(ctx, tt.input) - if err != nil { - t.Fatal(err) - } - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatal(err) - } - - b = w.Bytes() - fmt.Println("result", string(b)) - symbol, _ := pr.State.Where() - - if symbol != tt.expectedSymbol { - t.Fatalf("expected symbol to be 'create_pin', got %s", symbol) - } - }) - } -} diff --git a/menu_traversal_test.go b/menu_traversal_test.go new file mode 100644 index 0000000..091d02e --- /dev/null +++ b/menu_traversal_test.go @@ -0,0 +1,61 @@ +package main + +import ( + "bufio" + "bytes" + "context" + "encoding/json" + "fmt" + "os" + "strings" + "testing" + + "git.defalsify.org/vise.git/engine" + + "git.grassecon.net/urdt/ussd/enginetest" +) + +type TestCase struct { + Input []string `json:"input"` + Expected string `json:"expected"` +} + +type UserRegistration struct { + UserRegistration []TestCase `json:"user_registration"` +} + +type TestData struct { + UserRegistration []TestCase `json:"user_registration"` + PinCheck []TestCase `json:"pincheck"` +} + +func TestUserRegistration(t *testing.T) { + en, pe := enginetest.TestEngine("session1234112") + w := bytes.NewBuffer(nil) + file, err := os.Open("test_data.json") + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + var testData TestData + decoder := json.NewDecoder(file) + if err := decoder.Decode(&testData); err != nil { + fmt.Println("Error decoding JSON:", err) + return + } + + var inputBuilder strings.Builder + for _, testCase := range testData.UserRegistration { + inputBuilder.WriteString(strings.Join(testCase.Input, "\n") + "\n") + } + readers := bufio.NewReader(strings.NewReader(inputBuilder.String())) + engine.Loop(context.Background(), en, readers, w, nil) + st := pe.GetState() + sym, _ := st.Where() + b := w.Bytes() + fmt.Println("Menu:",string(b)) + fmt.Println("Rendering symbol:", sym) + +} diff --git a/test_data.json b/test_data.json new file mode 100644 index 0000000..cc54b50 --- /dev/null +++ b/test_data.json @@ -0,0 +1,18 @@ +{ + "user_registration": [ + { + "input": ["0", "0","1234","1234"], + "expected": "Registration successful" + } + ], + "pincheck": [ + { + "input": ["1234"], + "expected": "PIN valid" + }, + { + "input": ["5678"], + "expected": "PIN invalid" + } + ] +} diff --git a/testdata/testdata.go b/testdata/testdata.go index b3b1f00..338c1f2 100644 --- a/testdata/testdata.go +++ b/testdata/testdata.go @@ -4,7 +4,8 @@ import ( "context" "io/ioutil" "os" - "path" + "path" + "git.defalsify.org/vise.git/db" fsdb "git.defalsify.org/vise.git/db/fs" "git.defalsify.org/vise.git/logging" @@ -12,8 +13,6 @@ import ( testdataloader "github.com/peteole/testdata-loader" ) - - func outNew(sym string, b []byte, tpl string, data map[string]string) error { logg.Debugf("testdata out", "sym", sym) store.SetPrefix(db.DATATYPE_TEMPLATE) -- 2.45.2 From 7d1db50294523f6dd94fb97108760193cec620ca Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 27 Sep 2024 16:26:00 +0300 Subject: [PATCH 07/65] update --- enginetest/engine.go | 4 ++-- menu_traversal_test.go | 9 +++------ test_data.json | 3 ++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/enginetest/engine.go b/enginetest/engine.go index f6ab886..4eed863 100644 --- a/enginetest/engine.go +++ b/enginetest/engine.go @@ -26,8 +26,8 @@ func TestEngine(sessionId string) (engine.Engine,*persist.Persister){ cfg := engine.Config{ Root: "root", SessionId: sessionId, - OutputSize: uint32(106), - FlagCount: uint32(16), + OutputSize: uint32(160), + //FlagCount: uint32(16), } dbDir := ".test_state" diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 091d02e..c674e50 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -2,7 +2,6 @@ package main import ( "bufio" - "bytes" "context" "encoding/json" "fmt" @@ -30,8 +29,8 @@ type TestData struct { } func TestUserRegistration(t *testing.T) { - en, pe := enginetest.TestEngine("session1234112") - w := bytes.NewBuffer(nil) + en, pe := enginetest.TestEngine("session12341122") + //w := bytes.NewBuffer(nil) file, err := os.Open("test_data.json") if err != nil { fmt.Println("Error opening file:", err) @@ -51,11 +50,9 @@ func TestUserRegistration(t *testing.T) { inputBuilder.WriteString(strings.Join(testCase.Input, "\n") + "\n") } readers := bufio.NewReader(strings.NewReader(inputBuilder.String())) - engine.Loop(context.Background(), en, readers, w, nil) + engine.Loop(context.Background(), en, readers, os.Stdout, nil) st := pe.GetState() sym, _ := st.Where() - b := w.Bytes() - fmt.Println("Menu:",string(b)) fmt.Println("Rendering symbol:", sym) } diff --git a/test_data.json b/test_data.json index cc54b50..34bc573 100644 --- a/test_data.json +++ b/test_data.json @@ -1,8 +1,9 @@ { "user_registration": [ { - "input": ["0", "0","1234","1234"], + "input": ["","0", "0","1234","1234"], "expected": "Registration successful" + } ], "pincheck": [ -- 2.45.2 From 4aad23ab305423d9240eac2210f2c254bec97323 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Sep 2024 13:21:17 +0300 Subject: [PATCH 08/65] update tests --- driver/testdata.go | 55 +++++++++++++++++++++++ enginetest/engine.go | 2 +- menu_traversal_test.go | 100 +++++++++++++++++++++++------------------ 3 files changed, 112 insertions(+), 45 deletions(-) create mode 100644 driver/testdata.go diff --git a/driver/testdata.go b/driver/testdata.go new file mode 100644 index 0000000..e8d9575 --- /dev/null +++ b/driver/testdata.go @@ -0,0 +1,55 @@ +package driver + +import ( + "encoding/json" + "log" + "os" +) + +type Step struct { + Input string `json:"input"` + ExpectedContent string `json:"expectedContent"` +} + +type Group struct { + Name string `json:"name"` + Steps []Step `json:"steps"` +} + +type Session struct { + Name string `json:"name"` + Groups []Group `json:"groups"` +} + +func ReadData() []Session { + data, err := os.ReadFile("test_data_two.json") + if err != nil { + log.Fatalf("Failed to read file: %v", err) + } + // Unmarshal JSON data + var sessions []Session + err = json.Unmarshal(data, &sessions) + if err != nil { + log.Fatalf("Failed to unmarshal JSON: %v", err) + } + + return sessions +} + +func FilterGroupsByName(groups []Group, name string) []Group { + var filteredGroups []Group + for _, group := range groups { + if group.Name == name { + filteredGroups = append(filteredGroups, group) + } + } + return filteredGroups +} + +func Map[T any, U any](input []T, fn func(T) U) []U { + result := make([]U, len(input)) + for i, v := range input { + result[i] = fn(v) + } + return result +} diff --git a/enginetest/engine.go b/enginetest/engine.go index 4eed863..7ea57cb 100644 --- a/enginetest/engine.go +++ b/enginetest/engine.go @@ -27,7 +27,7 @@ func TestEngine(sessionId string) (engine.Engine,*persist.Persister){ Root: "root", SessionId: sessionId, OutputSize: uint32(160), - //FlagCount: uint32(16), + FlagCount: uint32(16), } dbDir := ".test_state" diff --git a/menu_traversal_test.go b/menu_traversal_test.go index c674e50..2483bd5 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -1,58 +1,70 @@ package main import ( - "bufio" + "bytes" "context" - "encoding/json" - "fmt" - "os" - "strings" "testing" - "git.defalsify.org/vise.git/engine" - + "git.grassecon.net/urdt/ussd/driver" "git.grassecon.net/urdt/ussd/enginetest" ) -type TestCase struct { - Input []string `json:"input"` - Expected string `json:"expected"` -} - -type UserRegistration struct { - UserRegistration []TestCase `json:"user_registration"` -} - -type TestData struct { - UserRegistration []TestCase `json:"user_registration"` - PinCheck []TestCase `json:"pincheck"` -} +var ( + testData = driver.ReadData() +) func TestUserRegistration(t *testing.T) { - en, pe := enginetest.TestEngine("session12341122") - //w := bytes.NewBuffer(nil) - file, err := os.Open("test_data.json") - if err != nil { - fmt.Println("Error opening file:", err) - return - } - defer file.Close() + en, _ := enginetest.TestEngine("session1234112") + var err error + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful") + for _, group := range groups { + for _, step := range group.Steps { + cont, _ := en.Exec(ctx, []byte(step.Input)) + if cont { + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(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) + } - var testData TestData - decoder := json.NewDecoder(file) - if err := decoder.Decode(&testData); err != nil { - fmt.Println("Error decoding JSON:", err) - return + } + } + } + } +} + +func TestAcceptTerms(t *testing.T) { + en, _ := enginetest.TestEngine("session12341123") + var err error + ctx := context.Background() + sessions := testData + + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "account_creation_accept_terms") + for _, group := range groups { + for _, step := range group.Steps { + cont, _ := en.Exec(ctx, []byte(step.Input)) + if cont { + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(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) + } + + } + + } + } } - - var inputBuilder strings.Builder - for _, testCase := range testData.UserRegistration { - inputBuilder.WriteString(strings.Join(testCase.Input, "\n") + "\n") - } - readers := bufio.NewReader(strings.NewReader(inputBuilder.String())) - engine.Loop(context.Background(), en, readers, os.Stdout, nil) - st := pe.GetState() - sym, _ := st.Where() - fmt.Println("Rendering symbol:", sym) - } -- 2.45.2 From 170d075545c618a7c0da38aba75083104b0d3d09 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Sep 2024 13:25:38 +0300 Subject: [PATCH 09/65] update tests --- {enginetest => engine}/engine.go | 5 ++- menu_traversal_test.go | 2 +- test_data.json | 69 +++++++++++++++++++++++--------- 3 files changed, 54 insertions(+), 22 deletions(-) rename {enginetest => engine}/engine.go (95%) diff --git a/enginetest/engine.go b/engine/engine.go similarity index 95% rename from enginetest/engine.go rename to engine/engine.go index 7ea57cb..5ac62ec 100644 --- a/enginetest/engine.go +++ b/engine/engine.go @@ -13,12 +13,13 @@ import ( "git.grassecon.net/urdt/ussd/internal/handlers" "git.grassecon.net/urdt/ussd/internal/storage" ) + var ( logg = logging.NewVanilla() scriptDir = path.Join("services", "registration") ) -func TestEngine(sessionId string) (engine.Engine,*persist.Persister){ +func TestEngine(sessionId string) (engine.Engine, *persist.Persister) { ctx := context.Background() ctx = context.WithValue(ctx, "SessionId", sessionId) pfp := path.Join(scriptDir, "pp.csv") @@ -83,6 +84,6 @@ func TestEngine(sessionId string) (engine.Engine,*persist.Persister){ en = en.WithFirst(hl.Init) //en = en.WithDebug(nil) - return en,pe + return en, pe } diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 2483bd5..a39fb7b 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -6,7 +6,7 @@ import ( "testing" "git.grassecon.net/urdt/ussd/driver" - "git.grassecon.net/urdt/ussd/enginetest" + "git.grassecon.net/urdt/ussd/engine" ) var ( diff --git a/test_data.json b/test_data.json index 34bc573..2a2428d 100644 --- a/test_data.json +++ b/test_data.json @@ -1,19 +1,50 @@ -{ - "user_registration": [ - { - "input": ["","0", "0","1234","1234"], - "expected": "Registration successful" - - } - ], - "pincheck": [ - { - "input": ["1234"], - "expected": "PIN valid" - }, - { - "input": ["5678"], - "expected": "PIN invalid" - } - ] -} +[ + { + "name": "session one", + "groups": [ + { + "name": "account_creation_successful", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "0", + "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" + }, + { + "input": "1234", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1234", + "expectedContent": "Enter your four number PIN again:" + } + ] + }, + { + "name": "account_creation_accept_terms", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "0", + "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" + } + + ] + } + ] + } +] -- 2.45.2 From 80ce141b806eda8aaf9834bec3413a0deb9942eb Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Sep 2024 13:31:49 +0300 Subject: [PATCH 10/65] reference correct test data file --- driver/testdata.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/testdata.go b/driver/testdata.go index e8d9575..9603c00 100644 --- a/driver/testdata.go +++ b/driver/testdata.go @@ -22,7 +22,7 @@ type Session struct { } func ReadData() []Session { - data, err := os.ReadFile("test_data_two.json") + data, err := os.ReadFile("test_data.json") if err != nil { log.Fatalf("Failed to read file: %v", err) } -- 2.45.2 From cf5b4ec74493ee809e2843538689b45cd796ddbc Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Sep 2024 18:05:20 +0300 Subject: [PATCH 11/65] call finish on engine --- menu_traversal_test.go | 66 ++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index a39fb7b..382ca76 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -3,10 +3,11 @@ package main import ( "bytes" "context" + "fmt" "testing" "git.grassecon.net/urdt/ussd/driver" - "git.grassecon.net/urdt/ussd/engine" + enginetest "git.grassecon.net/urdt/ussd/engine" ) var ( @@ -15,34 +16,39 @@ var ( func TestUserRegistration(t *testing.T) { en, _ := enginetest.TestEngine("session1234112") - var err error + defer en.Finish() + //var err error ctx := context.Background() sessions := testData for _, session := range sessions { groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful") for _, group := range groups { for _, step := range group.Steps { - cont, _ := en.Exec(ctx, []byte(step.Input)) - if cont { - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatal(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) - } + // for { + _, err := en.Exec(ctx, []byte(step.Input)) + if err != nil { + t.Fail() } + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(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 TestAcceptTerms(t *testing.T) { - en, _ := enginetest.TestEngine("session12341123") - var err error +func TestTerms(t *testing.T) { + en, _ := enginetest.TestEngine("session1234112") + defer en.Finish() ctx := context.Background() sessions := testData @@ -50,20 +56,24 @@ func TestAcceptTerms(t *testing.T) { groups := driver.FilterGroupsByName(session.Groups, "account_creation_accept_terms") for _, group := range groups { for _, step := range group.Steps { - cont, _ := en.Exec(ctx, []byte(step.Input)) - if cont { - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatal(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) - } - + // for { + _, err := en.Exec(ctx, []byte(step.Input)) + if err != nil { + t.Fail() } + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(err) + } + b := w.Bytes() + fmt.Println("valuehere:", string(b)) + if !bytes.Equal(b, []byte(step.ExpectedContent)) { + t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) + } + // } + } } } -- 2.45.2 From e7a3de526c36337c8b75c169bbcccb37c4b43a39 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Sep 2024 18:09:53 +0300 Subject: [PATCH 12/65] remove log --- menu_traversal_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 382ca76..dfda89e 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "context" - "fmt" "testing" "git.grassecon.net/urdt/ussd/driver" @@ -68,7 +67,6 @@ func TestTerms(t *testing.T) { t.Fatal(err) } b := w.Bytes() - fmt.Println("valuehere:", string(b)) if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } -- 2.45.2 From be165e50337dc5ed52237992f8c165c54d76a11d Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 30 Sep 2024 16:05:14 +0300 Subject: [PATCH 13/65] added tests and test cases --- menu_traversal_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++ test_data.json | 53 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 382ca76..0b1397d 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -78,3 +78,57 @@ func TestTerms(t *testing.T) { } } } + +func TestAccountRegistrationRejectTerms(t *testing.T) { + en, _ := enginetest.TestEngine("session1234112") + var err error + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "account_creation_reject_terms") + for _, group := range groups { + for _, step := range group.Steps { + cont, _ := en.Exec(ctx, []byte(step.Input)) + if cont { + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(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 TestAccountRegistrationInvalidPin(t *testing.T) { + en, _ := enginetest.TestEngine("session1234112") + var err error + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "account_creation_invalid_pin") + for _, group := range groups { + for _, step := range group.Steps { + cont, _ := en.Exec(ctx, []byte(step.Input)) + if cont { + w := bytes.NewBuffer(nil) + _, err = en.Flush(ctx, w) + if err != nil { + t.Fatal(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) + } + + } + } + } + } +} diff --git a/test_data.json b/test_data.json index 2a2428d..789f064 100644 --- a/test_data.json +++ b/test_data.json @@ -23,7 +23,7 @@ }, { "input": "1234", - "expectedContent": "Enter your four number PIN again:" + "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" } ] }, @@ -43,6 +43,57 @@ "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" } + ] + }, + { + "name": "account_creation_reject_terms", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "1", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "account_creation_invalid_pin", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "0", + "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" + }, + { + "input": "1234", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1111", + "expectedContent": "The PIN is not a match. Try again\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1234", + "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" + } + ] } ] -- 2.45.2 From 9eb35ec52d589f7580284f108774179f5cd89ae2 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 30 Sep 2024 22:00:28 +0300 Subject: [PATCH 14/65] added en.Finish --- menu_traversal_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 0b1397d..4c64966 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -81,6 +81,7 @@ func TestTerms(t *testing.T) { func TestAccountRegistrationRejectTerms(t *testing.T) { en, _ := enginetest.TestEngine("session1234112") + defer en.Finish() var err error ctx := context.Background() sessions := testData @@ -108,6 +109,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { func TestAccountRegistrationInvalidPin(t *testing.T) { en, _ := enginetest.TestEngine("session1234112") + defer en.Finish() var err error ctx := context.Background() sessions := testData -- 2.45.2 From f3f276c5490d8d7166073fee672bede6b4e0a3b8 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 30 Sep 2024 22:12:49 +0300 Subject: [PATCH 15/65] check the status of cont --- menu_traversal_test.go | 54 +++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 4c64966..d415626 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -82,25 +82,28 @@ func TestTerms(t *testing.T) { func TestAccountRegistrationRejectTerms(t *testing.T) { en, _ := enginetest.TestEngine("session1234112") defer en.Finish() - var err error ctx := context.Background() sessions := testData for _, session := range sessions { groups := driver.FilterGroupsByName(session.Groups, "account_creation_reject_terms") for _, group := range groups { for _, step := range group.Steps { - cont, _ := en.Exec(ctx, []byte(step.Input)) - if cont { - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatal(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) - } + 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) } } } @@ -110,25 +113,28 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { func TestAccountRegistrationInvalidPin(t *testing.T) { en, _ := enginetest.TestEngine("session1234112") defer en.Finish() - var err error ctx := context.Background() sessions := testData for _, session := range sessions { groups := driver.FilterGroupsByName(session.Groups, "account_creation_invalid_pin") for _, group := range groups { for _, step := range group.Steps { - cont, _ := en.Exec(ctx, []byte(step.Input)) - if cont { - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatal(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) - } + 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) } } } -- 2.45.2 From 1b2c6933e1a9f7fe29f8ca639f9eb0f02c0185ca Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 30 Sep 2024 22:27:37 +0300 Subject: [PATCH 16/65] clean up test --- menu_traversal_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 466e570..728d8c3 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -16,29 +16,31 @@ var ( func TestUserRegistration(t *testing.T) { en, _ := enginetest.TestEngine("session1234112") defer en.Finish() - //var err error ctx := context.Background() sessions := testData for _, session := range sessions { groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful") for _, group := range groups { for _, step := range group.Steps { - // for { - _, err := en.Exec(ctx, []byte(step.Input)) + + cont, err := en.Exec(ctx, []byte(step.Input)) if err != nil { - t.Fail() + t.Errorf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err) + return + } + if !cont { + break } w := bytes.NewBuffer(nil) _, err = en.Flush(ctx, w) if err != nil { - t.Fatal(err) + 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) } - // } } } @@ -55,7 +57,6 @@ func TestTerms(t *testing.T) { groups := driver.FilterGroupsByName(session.Groups, "account_creation_accept_terms") for _, group := range groups { for _, step := range group.Steps { - // for { _, err := en.Exec(ctx, []byte(step.Input)) if err != nil { t.Fail() @@ -64,13 +65,12 @@ func TestTerms(t *testing.T) { w := bytes.NewBuffer(nil) _, err = en.Flush(ctx, w) if err != nil { - t.Fatal(err) + 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) } - // } } } -- 2.45.2 From f267aa2b4115138ee461ee0f480c331f12d9d9ac Mon Sep 17 00:00:00 2001 From: lash Date: Tue, 1 Oct 2024 00:18:54 +0100 Subject: [PATCH 17/65] Delete connstr in threadgdbm global channel map on close --- engine/engine.go | 18 ++++++++++++------ internal/storage/gdbm.go | 1 + menu_traversal_test.go | 33 ++++++++++++++++----------------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index 5ac62ec..5fe0977 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -8,7 +8,6 @@ import ( "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/logging" - "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" "git.grassecon.net/urdt/ussd/internal/handlers" "git.grassecon.net/urdt/ussd/internal/storage" @@ -19,7 +18,7 @@ var ( scriptDir = path.Join("services", "registration") ) -func TestEngine(sessionId string) (engine.Engine, *persist.Persister) { +func TestEngine(sessionId string) (engine.Engine, func()) { ctx := context.Background() ctx = context.WithValue(ctx, "SessionId", sessionId) pfp := path.Join(scriptDir, "pp.csv") @@ -53,7 +52,7 @@ func TestEngine(sessionId string) (engine.Engine, *persist.Persister) { os.Exit(1) } - userdatastore, err := menuStorageService.GetUserdataDb(ctx) + userDataStore, err := menuStorageService.GetUserdataDb(ctx) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) @@ -66,7 +65,7 @@ func TestEngine(sessionId string) (engine.Engine, *persist.Persister) { } lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) - lhs.SetDataStore(&userdatastore) + lhs.SetDataStore(&userDataStore) lhs.SetPersister(pe) if err != nil { @@ -83,7 +82,14 @@ func TestEngine(sessionId string) (engine.Engine, *persist.Persister) { en := lhs.GetEngine() en = en.WithFirst(hl.Init) - //en = en.WithDebug(nil) - return en, pe + cleanFn := func() { + err := menuStorageService.Close() + if err != nil { + logg.Errorf(err.Error()) + } + logg.Infof("testengine storage closed") + } + //en = en.WithDebug(nil) + return en, cleanFn } diff --git a/internal/storage/gdbm.go b/internal/storage/gdbm.go index eb959cf..49de570 100644 --- a/internal/storage/gdbm.go +++ b/internal/storage/gdbm.go @@ -109,6 +109,7 @@ func(tdb *ThreadGdbmDb) Get(ctx context.Context, key []byte) ([]byte, error) { func(tdb *ThreadGdbmDb) Close() error { tdb.reserve() close(dbC[tdb.connStr]) + delete(dbC, tdb.connStr) err := tdb.db.Close() tdb.db = nil return err diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 728d8c3..9c1e839 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -14,8 +14,8 @@ var ( ) func TestUserRegistration(t *testing.T) { - en, _ := enginetest.TestEngine("session1234112") - defer en.Finish() + en, fn := enginetest.TestEngine("session1234112") + defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { @@ -26,8 +26,7 @@ func TestUserRegistration(t *testing.T) { 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 + t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err) } if !cont { break @@ -35,7 +34,7 @@ func TestUserRegistration(t *testing.T) { w := bytes.NewBuffer(nil) _, err = en.Flush(ctx, w) if err != nil { - t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err) + t.Fatalf("Test case '%s' failed during Flush: %v", group.Name, err) } b := w.Bytes() if !bytes.Equal(b, []byte(step.ExpectedContent)) { @@ -48,8 +47,8 @@ func TestUserRegistration(t *testing.T) { } func TestTerms(t *testing.T) { - en, _ := enginetest.TestEngine("session1234112") - defer en.Finish() + en, fn := enginetest.TestEngine("session1234112_a") + defer fn() ctx := context.Background() sessions := testData @@ -59,13 +58,13 @@ func TestTerms(t *testing.T) { for _, step := range group.Steps { _, err := en.Exec(ctx, []byte(step.Input)) if err != nil { - t.Fail() + t.Fatalf("Test case '%s' failed during Exec: %v", group.Name, err) } w := bytes.NewBuffer(nil) _, err = en.Flush(ctx, w) if err != nil { - t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err) + t.Fatalf("Test case '%s' failed during Flush: %v", group.Name, err) } b := w.Bytes() if !bytes.Equal(b, []byte(step.ExpectedContent)) { @@ -78,8 +77,8 @@ func TestTerms(t *testing.T) { } func TestAccountRegistrationRejectTerms(t *testing.T) { - en, _ := enginetest.TestEngine("session1234112") - defer en.Finish() + en, fn := enginetest.TestEngine("session1234112_b") + defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { @@ -88,7 +87,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { for _, step := range group.Steps { 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) + t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err) return } if !cont { @@ -96,7 +95,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { } w := bytes.NewBuffer(nil) if _, err := en.Flush(ctx, w); err != nil { - t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err) + t.Fatalf("Test case '%s' failed during Flush: %v", group.Name, err) } b := w.Bytes() @@ -109,8 +108,8 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { } func TestAccountRegistrationInvalidPin(t *testing.T) { - en, _ := enginetest.TestEngine("session1234112") - defer en.Finish() + en, fn := enginetest.TestEngine("session1234112") + defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { @@ -119,7 +118,7 @@ func TestAccountRegistrationInvalidPin(t *testing.T) { for _, step := range group.Steps { 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) + t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err) return } if !cont { @@ -127,7 +126,7 @@ func TestAccountRegistrationInvalidPin(t *testing.T) { } w := bytes.NewBuffer(nil) if _, err := en.Flush(ctx, w); err != nil { - t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err) + t.Fatalf("Test case '%s' failed during Flush: %v", group.Name, err) } b := w.Bytes() -- 2.45.2 From 285002738fff2c8c206b823d46b6053c810cbbeb Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 1 Oct 2024 13:15:05 +0300 Subject: [PATCH 18/65] added send_with_invalid_recipient test --- menu_traversal_test.go | 31 +++++++++++++++++++++++++++++++ test_data.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 9c1e839..7513436 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -137,3 +137,34 @@ func TestAccountRegistrationInvalidPin(t *testing.T) { } } } + +func TestSendWithInvalidRecipient(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "send_with_invalid_recipient") + for _, group := range groups { + for _, step := range group.Steps { + cont, err := en.Exec(ctx, []byte(step.Input)) + if err != nil { + t.Fatalf("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.Fatalf("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) + } + } + } + } +} diff --git a/test_data.json b/test_data.json index 789f064..60a7a97 100644 --- a/test_data.json +++ b/test_data.json @@ -95,6 +95,39 @@ } ] + }, + { + "name": "send_with_invalid_recipient", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter recipient's phone number:\n0:Back" + }, + { + "input": "000", + "expectedContent": "000 is not registered or invalid, please try again:\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter recipient's phone number:\n0:Back" + }, + { + "input": "065656", + "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" + }, + { + "input": "0.001", + "expectedContent": "065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + }, + { + "input": "1234", + "expectedContent": "Your request has been sent. 065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b." + } + ] } ] } -- 2.45.2 From 3e74c1d939f82fd58b3dbad2ed9245a634d8dc72 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 1 Oct 2024 13:26:47 +0300 Subject: [PATCH 19/65] test with all invalid inputs --- menu_traversal_test.go | 4 ++-- test_data.json | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 7513436..42a5d13 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -138,13 +138,13 @@ func TestAccountRegistrationInvalidPin(t *testing.T) { } } -func TestSendWithInvalidRecipient(t *testing.T) { +func TestSendWithInvalidInputs(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "send_with_invalid_recipient") + groups := driver.FilterGroupsByName(session.Groups, "send_with_invalid_inputs") for _, group := range groups { for _, step := range group.Steps { cont, err := en.Exec(ctx, []byte(step.Input)) diff --git a/test_data.json b/test_data.json index 60a7a97..f9e3084 100644 --- a/test_data.json +++ b/test_data.json @@ -97,7 +97,7 @@ ] }, { - "name": "send_with_invalid_recipient", + "name": "send_with_invalid_inputs", "steps": [ { "input": "", @@ -119,10 +119,26 @@ "input": "065656", "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" }, + { + "input": "0.1", + "expectedContent": "Amount 0.1 is invalid, please try again:\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" + }, { "input": "0.001", "expectedContent": "065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" }, + { + "input": "1222", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + }, { "input": "1234", "expectedContent": "Your request has been sent. 065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b." -- 2.45.2 From 14218ffb88d0d425a05adb0089a66b51f5680395 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 1 Oct 2024 14:50:45 +0300 Subject: [PATCH 20/65] add a dynamic value --- menu_traversal_test.go | 25 ++++++++++++++++++++++--- test_data.json | 6 +++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 42a5d13..270f360 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "regexp" "testing" "git.grassecon.net/urdt/ussd/driver" @@ -13,6 +14,17 @@ var ( testData = driver.ReadData() ) +// Extract the public key from the engine response +func extractPublicKey(response []byte) string { + // Regex pattern to match the public key starting with 0x and 40 characters + re := regexp.MustCompile(`0x[a-fA-F0-9]{40}`) + match := re.Find(response) + if match != nil { + return string(match) + } + return "" +} + func TestUserRegistration(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() @@ -108,7 +120,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { } func TestAccountRegistrationInvalidPin(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine("session1234112_c") defer fn() ctx := context.Background() sessions := testData @@ -161,8 +173,15 @@ func TestSendWithInvalidInputs(t *testing.T) { } b := w.Bytes() - if !bytes.Equal(b, []byte(step.ExpectedContent)) { - t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) + + // Extract the dynamic public key from the output + publicKey := extractPublicKey(b) + + // Replace placeholder {public_key} with the actual dynamic public key + expectedContent := bytes.Replace([]byte(step.ExpectedContent), []byte("{public_key}"), []byte(publicKey), -1) + + if !bytes.Equal(b, expectedContent) { + t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expectedContent, b) } } } diff --git a/test_data.json b/test_data.json index f9e3084..44c86c8 100644 --- a/test_data.json +++ b/test_data.json @@ -129,7 +129,7 @@ }, { "input": "0.001", - "expectedContent": "065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" }, { "input": "1222", @@ -137,11 +137,11 @@ }, { "input": "1", - "expectedContent": "065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" }, { "input": "1234", - "expectedContent": "Your request has been sent. 065656 will receive 0.001 from 0xd6CF3C87b0D4aD5978448bBbD6Db9EC6D74D624b." + "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." } ] } -- 2.45.2 From 48c608ad4d8379bf58657eec78d0990670e29aa1 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 1 Oct 2024 15:36:59 +0300 Subject: [PATCH 21/65] add Help and Quit menu tests --- menu_traversal_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++ test_data.json | 26 ++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 270f360..66f36f6 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -187,3 +187,65 @@ func TestSendWithInvalidInputs(t *testing.T) { } } } + +func TestMainMenuHelp(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "main_menu_help") + for _, group := range groups { + for _, step := range group.Steps { + cont, err := en.Exec(ctx, []byte(step.Input)) + if err != nil { + t.Fatalf("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.Fatalf("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 TestMainMenuQuit(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "main_menu_quit") + for _, group := range groups { + for _, step := range group.Steps { + cont, err := en.Exec(ctx, []byte(step.Input)) + if err != nil { + t.Fatalf("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.Fatalf("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) + } + } + } + } +} diff --git a/test_data.json b/test_data.json index 44c86c8..59e0dcb 100644 --- a/test_data.json +++ b/test_data.json @@ -144,6 +144,32 @@ "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." } ] + }, + { + "name": "main_menu_help", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "4", + "expectedContent": "For more help,please call: 0757628885" + } + ] + }, + { + "name": "main_menu_quit", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] } ] } -- 2.45.2 From c5b2348f5e589d87776a3c93629710a6c88e71f3 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 1 Oct 2024 16:54:16 +0300 Subject: [PATCH 22/65] add tests --- menu_traversal_test.go | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 728d8c3..fcc578a 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -138,3 +138,69 @@ func TestAccountRegistrationInvalidPin(t *testing.T) { } } } + +func TestMyAccount_Change_Language(t *testing.T) { + en, _ := enginetest.TestEngine("session1234112") + defer en.Finish() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_language_change") + 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_Savefirstname(t *testing.T) { + en, _ := enginetest.TestEngine("session1234112") + defer en.Finish() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_save_firstname") + 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) + } + + } + } + } +} -- 2.45.2 From a0ef57ca1597f7b0aeec1ed6cafacd133fd43623 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 1 Oct 2024 21:43:52 +0300 Subject: [PATCH 23/65] add Change PIN test --- menu_traversal_test.go | 31 +++++++++++++++++++++++++++++++ test_data.json | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 66f36f6..7275afa 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -249,3 +249,34 @@ func TestMainMenuQuit(t *testing.T) { } } } + +func TestMyAccountChangePin(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "my_account_change_pin") + for _, group := range groups { + for _, step := range group.Steps { + cont, err := en.Exec(ctx, []byte(step.Input)) + if err != nil { + t.Fatalf("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.Fatalf("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) + } + } + } + } +} diff --git a/test_data.json b/test_data.json index 59e0dcb..ea6301d 100644 --- a/test_data.json +++ b/test_data.json @@ -170,6 +170,43 @@ "expectedContent": "Thank you for using Sarafu. Goodbye!" } ] + }, + { + "name": "my_account_change_pin", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "5", + "expectedContent": "PIN Management\n1:Change PIN\n2:Reset other's PIN\n3:Guard my PIN\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your old PIN\n\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Enter a new four number pin\n\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Confirm your new PIN:\n\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Your PIN change request has been successful\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] } ] } -- 2.45.2 From 1ff2c3602fa171233e66f712fc6dc9edd8befe47 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Tue, 1 Oct 2024 23:21:29 +0300 Subject: [PATCH 24/65] update tests --- menu_traversal_test.go | 14 +++++---- test_data.json | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 5709b1d..e2eb06f 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -139,8 +139,8 @@ func TestAccountRegistrationInvalidPin(t *testing.T) { } func TestMyAccount_Change_Language(t *testing.T) { - en, _ := enginetest.TestEngine("session1234112") - defer en.Finish() + en, fn := enginetest.TestEngine("session1234112") + defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { @@ -172,8 +172,8 @@ func TestMyAccount_Change_Language(t *testing.T) { } func TestMyAccount_Savefirstname(t *testing.T) { - en, _ := enginetest.TestEngine("session1234112") - defer en.Finish() + en, fn := enginetest.TestEngine("session1234112") + defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { @@ -181,11 +181,14 @@ func TestMyAccount_Savefirstname(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)) + + cont, err := en.Exec(ctx, []byte("3")) + if err != nil { t.Errorf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err) return } + if !cont { break } @@ -198,6 +201,7 @@ func TestMyAccount_Savefirstname(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } + en.Finish() } } diff --git a/test_data.json b/test_data.json index 789f064..c9b0593 100644 --- a/test_data.json +++ b/test_data.json @@ -95,6 +95,71 @@ } ] + }, + { + "name": "menu_my_account_language_change", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Select language:\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Your language change request was successful.\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + + ] + }, + { + "name": "menu_my_account_save_firstname", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your first names:\n0:Back" + }, + { + "input": "foo", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] } ] } -- 2.45.2 From 6eec9571c7c2d900b0cd5201adbcf2582b8fbde1 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 09:01:27 +0300 Subject: [PATCH 25/65] update test --- menu_traversal_test.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index ef5f1ab..6cd41de 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -324,27 +324,19 @@ func TestMyAccount_Savefirstname(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("3")) - + _, 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) } - en.Finish() } } -- 2.45.2 From abbf22086f5d1225f412741fe538b2e6c352a5b0 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 09:55:56 +0300 Subject: [PATCH 26/65] update tests --- menu_traversal_test.go | 170 +++++++++++++++++++++++++++++++++++++++- test_data.json | 173 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 338 insertions(+), 5 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 6cd41de..64778ff 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -303,7 +303,6 @@ func TestMyAccount_Change_Language(t *testing.T) { 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) @@ -314,21 +313,184 @@ func TestMyAccount_Change_Language(t *testing.T) { } } -func TestMyAccount_Savefirstname(t *testing.T) { +func TestMyAccount_Edit_firstname(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_save_firstname") + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_firstname") for _, group := range groups { for index, step := range group.Steps { t.Logf("step %v with input %v", index, step.Input) - _, err := en.Exec(ctx, []byte(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_Edit_familyname(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_familyname") + 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_Edit_gender(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_gender") + 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_Edit_yob(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_yob") + 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_Edit_location(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_location") + 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_Edit_offerings(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_offerings") + 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) diff --git a/test_data.json b/test_data.json index c37d4b9..56ad23b 100644 --- a/test_data.json +++ b/test_data.json @@ -240,7 +240,7 @@ ] }, { - "name": "menu_my_account_save_firstname", + "name": "menu_my_account_edit_firstname", "steps": [ { @@ -272,7 +272,178 @@ "expectedContent": "Thank you for using Sarafu. Goodbye!" } ] + }, + { + "name": "menu_my_account_edit_familyname", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "2", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "bar", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_gender", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "3", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "foo", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_yob", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "4", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1945", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_location", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "5", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "1945", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_offerings", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "6", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "1945", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] } + ] } ] -- 2.45.2 From 204ce3ce56401ded8b0f6dd741056bf3f4ca7b18 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 10:18:04 +0300 Subject: [PATCH 27/65] update tests --- menu_traversal_test.go | 32 ++++++++++++++++++++++++++++ test_data.json | 47 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 64778ff..02782c0 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -504,3 +504,35 @@ func TestMyAccount_Edit_offerings(t *testing.T) { } } } + +func TestMyAccount_View_Profile(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + 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) + } + + } + } + } +} diff --git a/test_data.json b/test_data.json index 56ad23b..4388b5a 100644 --- a/test_data.json +++ b/test_data.json @@ -324,11 +324,11 @@ "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, { - "input": "3", + "input": "2", "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" }, { - "input": "foo", + "input": "Female", "expectedContent": "Please enter your PIN:" }, { @@ -396,7 +396,7 @@ "expectedContent": "Enter your location:\n0:Back" }, { - "input": "1945", + "input": "Kilifi", "expectedContent": "Please enter your PIN:" }, { @@ -430,7 +430,7 @@ "expectedContent": "Enter the services or goods you offer: \n0:Back" }, { - "input": "1945", + "input": "Bananas", "expectedContent": "Please enter your PIN:" }, { @@ -442,6 +442,45 @@ "expectedContent": "Thank you for using Sarafu. Goodbye!" } ] + }, + { + "name": "menu_my_account_view_profile", + "steps": [ + { + + "input": "", + "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "7", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "My profile:\nName: foo foo\nGender: foo\nAge: 79\nLocation: 1945\nYou provide: 1945\n\n0:Back" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + + "input": "9", + "expectedContent":"" + } + ] } ] -- 2.45.2 From 74fa2c3d65e2236aab4aa56ead1ca59eff4f8019 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 11:23:34 +0300 Subject: [PATCH 28/65] update tests --- menu_traversal_test.go | 67 ++++++++++++++++++++++++++++++++++++++++++ test_data.json | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 02782c0..2dc7bd8 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -536,3 +536,70 @@ func TestMyAccount_View_Profile(t *testing.T) { } } } + + +func TestMyAccount_Check_Balance(t *testing.T){ + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_balance") + 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_Check_Balance_IncorrectPin(t *testing.T){ + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_balance_incorrect_pin") + 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) + } + + } + } + } +} + diff --git a/test_data.json b/test_data.json index 4388b5a..651fa80 100644 --- a/test_data.json +++ b/test_data.json @@ -481,6 +481,60 @@ "expectedContent":"" } ] + }, + { + "name": "menu_my_account_check_balance", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Please enter your PIN:" + } + + ] + }, + { + "name": "menu_my_account_check_balance_incorrect_pin", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + } + + ] } ] -- 2.45.2 From ab02a8882a7bf748a7e867f0ebd71e0b73622dca Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 12:10:32 +0300 Subject: [PATCH 29/65] update tests --- menu_traversal_test.go | 37 +++++++++++++++++++++++++++++++++---- test_data.json | 29 ++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 2dc7bd8..861a09d 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -537,8 +537,7 @@ func TestMyAccount_View_Profile(t *testing.T) { } } - -func TestMyAccount_Check_Balance(t *testing.T){ +func TestMyAccount_Check_Balance(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() @@ -570,8 +569,7 @@ func TestMyAccount_Check_Balance(t *testing.T){ } } - -func TestMyAccount_Check_Balance_IncorrectPin(t *testing.T){ +func TestMyAccount_Check_Balance_IncorrectPin(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() @@ -603,3 +601,34 @@ func TestMyAccount_Check_Balance_IncorrectPin(t *testing.T){ } } +func TestMyAccount_MyAddress(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_my_address") + 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) + } + + } + } + } +} diff --git a/test_data.json b/test_data.json index 651fa80..a6737f4 100644 --- a/test_data.json +++ b/test_data.json @@ -229,12 +229,12 @@ "expectedContent": "Select language:\n0:english\n1:kiswahili" }, { - "input": "0", - "expectedContent": "Your language change request was successful.\n0:Back\n9:Quit" + "input": "1", + "expectedContent": "Ombi lako la kubadilisha lugha limefanikiwa.\n0:Rudi\n9:Ondoka" }, { "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" + "expectedContent": "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" } ] @@ -534,6 +534,29 @@ "expectedContent": "Incorrect pin\n1:retry\n9:Quit" } + ] + }, + { + "name": "menu_my_account_my_address", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "6", + "expectedContent": "Address: 0xdF8CB1D9b5BDaE418E5Bee107031cA7d933906CD\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] } -- 2.45.2 From 01476d5408b4a89f69385ea85f1bee4c39ab669a Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 13:22:00 +0300 Subject: [PATCH 30/65] update tests --- menu_traversal_test.go | 104 +++++++++++++++++++++++++++++++++++++++-- test_data.json | 87 ++++++++++++++++++++++++++++++++-- 2 files changed, 182 insertions(+), 9 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 861a09d..b200322 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -313,6 +313,38 @@ func TestMyAccount_Change_Language(t *testing.T) { } } +func TestMyAccount_Change_Language_Incorrect_Pin(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_language_change_incorectpin") + 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_Edit_firstname(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() @@ -537,13 +569,13 @@ func TestMyAccount_View_Profile(t *testing.T) { } } -func TestMyAccount_Check_Balance(t *testing.T) { +func TestMyAccount_Check_My_Balance(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_balance") + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_my_balance") for _, group := range groups { for index, step := range group.Steps { t.Logf("step %v with input %v", index, step.Input) @@ -569,13 +601,77 @@ func TestMyAccount_Check_Balance(t *testing.T) { } } -func TestMyAccount_Check_Balance_IncorrectPin(t *testing.T) { +func TestMyAccount_Check_My_Balance_IncorrectPin(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() sessions := testData for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_balance_incorrect_pin") + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_my_balance_incorrect_pin") + 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_Check_Community_Balance(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_community_balance") + 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_Check_Community_Balance_IncorrectPin(t *testing.T) { + en, fn := enginetest.TestEngine("session1234112") + defer fn() + ctx := context.Background() + sessions := testData + for _, session := range sessions { + groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_community_balance_incorrect_pin") for _, group := range groups { for index, step := range group.Steps { t.Logf("step %v with input %v", index, step.Input) diff --git a/test_data.json b/test_data.json index a6737f4..66d9702 100644 --- a/test_data.json +++ b/test_data.json @@ -239,6 +239,29 @@ ] }, + { + "name": "menu_my_account_language_change_incorectpin", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + } + + ] + }, { "name": "menu_my_account_edit_firstname", "steps": [ @@ -324,7 +347,7 @@ "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" }, { - "input": "2", + "input": "3", "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" }, { @@ -465,7 +488,7 @@ }, { "input": "1234", - "expectedContent": "My profile:\nName: foo foo\nGender: foo\nAge: 79\nLocation: 1945\nYou provide: 1945\n\n0:Back" + "expectedContent": "My profile:\nName: foo bar\nGender: Female\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" }, { "input": "0", @@ -483,7 +506,7 @@ ] }, { - "name": "menu_my_account_check_balance", + "name": "menu_my_account_check_my_balance", "steps": [ { "input":"", @@ -504,13 +527,40 @@ }, { "input": "1234", - "expectedContent": "Please enter your PIN:" + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" } ] }, { - "name": "menu_my_account_check_balance_incorrect_pin", + "name": "menu_my_account_check_community_balance", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" + } + + ] + }, + { + "name": "menu_my_account_check_my_balance_incorrect_pin", "steps": [ { "input":"", @@ -536,6 +586,33 @@ ] }, + { + "name": "menu_my_account_check_community_balance_incorrect_pin", + "steps": [ + { + "input":"", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + } + + ] + }, { "name": "menu_my_account_my_address", "steps": [ -- 2.45.2 From 948a9d3a93e8a29f81744f62ad38ab31106752a5 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 13:24:03 +0300 Subject: [PATCH 31/65] allow one to go back during the change PIN --- internal/handlers/ussd/menuhandler.go | 29 +++++++++++++++------------ services/registration/new_pin.vis | 11 ++++------ services/registration/old_pin.vis | 6 ++++-- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index e998bd5..0e40cb5 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -241,21 +241,24 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt accountPIN := string(input) - // Validate that the PIN is a 4-digit number - if !isValidPIN(accountPIN) { - res.FlagSet = append(res.FlagSet, flag_incorrect_pin) + if accountPIN != "0" { // for the 0:Back case + // Validate that the PIN is a 4-digit number + if !isValidPIN(accountPIN) { + res.FlagSet = append(res.FlagSet, flag_incorrect_pin) + return res, nil + } + store := h.userdataStore + err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN)) + if err != nil { + return res, err + } return res, nil } - store := h.userdataStore - err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_PIN, []byte(accountPIN)) - if err != nil { - return res, err - } + return res, nil } - -func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) (resource.Result,error){ +func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result vouchers := []string{ "SRF", @@ -286,9 +289,9 @@ func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) ( for i, voucher := range vouchers { numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, voucher)) } - res.Content = strings.Join(numberedVouchers,"\n") + res.Content = strings.Join(numberedVouchers, "\n") - return res,nil + return res, nil } func (h *Handlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) { @@ -577,7 +580,7 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res if err != nil { return res, err } - if len(input) == 4 { + if len(input) > 1 { if bytes.Equal(input, AccountPin) { if h.st.MatchFlag(flag_account_authorized, false) { res.FlagReset = append(res.FlagReset, flag_incorrect_pin) diff --git a/services/registration/new_pin.vis b/services/registration/new_pin.vis index 29013a9..ddcb7cc 100644 --- a/services/registration/new_pin.vis +++ b/services/registration/new_pin.vis @@ -1,13 +1,10 @@ -LOAD authorize_account 12 -RELOAD authorize_account -CATCH incorrect_pin flag_incorrect_pin 1 -CATCH old_pin flag_allow_update 0 +CATCH _ flag_allow_update 0 MOUT back 0 HALT INCMP _ 0 LOAD save_temporary_pin 6 -LOAD verify_new_pin 0 RELOAD save_temporary_pin +LOAD verify_new_pin 8 RELOAD verify_new_pin -INCMP * confirm_pin_change - +CATCH incorrect_pin flag_incorrect_pin 1 +INCMP confirm_pin_change * diff --git a/services/registration/old_pin.vis b/services/registration/old_pin.vis index 1e99f4f..52379eb 100644 --- a/services/registration/old_pin.vis +++ b/services/registration/old_pin.vis @@ -1,7 +1,9 @@ LOAD reset_allow_update 0 +RELOAD reset_allow_update MOUT back 0 HALT -RELOAD reset_allow_update +LOAD authorize_account 12 +RELOAD authorize_account +CATCH incorrect_pin flag_incorrect_pin 1 INCMP _ 0 INCMP new_pin * - -- 2.45.2 From 6b8f62fbc621e2c0af832046d6f579805ff257d0 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 13:26:19 +0300 Subject: [PATCH 32/65] code cleanup - removed unused new lines --- services/registration/confirm_pin_change | 2 +- services/registration/confirm_pin_change.vis | 4 +--- services/registration/confirm_pin_change_swa | 2 +- services/registration/enter_familyname_swa | 2 +- services/registration/enter_name.vis | 3 --- services/registration/invalid_pin_swa | 3 ++- services/registration/my_vouchers.vis | 3 --- services/registration/new_pin | 2 +- services/registration/new_pin_swa | 3 +-- services/registration/old_pin | 2 +- services/registration/old_pin_swa | 2 +- services/registration/pin_management.vis | 3 +-- services/registration/pin_reset_mismatch | 2 +- services/registration/pin_reset_mismatch.vis | 1 - services/registration/pin_reset_success | 2 +- services/registration/pin_reset_success.vis | 4 +--- services/registration/pin_reset_success_swa | 2 +- services/registration/profile_update_success | 2 +- services/registration/profile_update_success_swa | 2 +- services/registration/select_gender.vis | 2 -- 20 files changed, 17 insertions(+), 31 deletions(-) diff --git a/services/registration/confirm_pin_change b/services/registration/confirm_pin_change index 398a827..2e1b83e 100644 --- a/services/registration/confirm_pin_change +++ b/services/registration/confirm_pin_change @@ -1 +1 @@ -Confirm your new PIN: +Confirm your new PIN: \ No newline at end of file diff --git a/services/registration/confirm_pin_change.vis b/services/registration/confirm_pin_change.vis index 7691e01..269e83c 100644 --- a/services/registration/confirm_pin_change.vis +++ b/services/registration/confirm_pin_change.vis @@ -2,6 +2,4 @@ CATCH invalid_pin flag_valid_pin 0 MOUT back 0 HALT INCMP _ 0 -INCMP * pin_reset_success - - +INCMP pin_reset_success * diff --git a/services/registration/confirm_pin_change_swa b/services/registration/confirm_pin_change_swa index c7af4ea..e407fec 100644 --- a/services/registration/confirm_pin_change_swa +++ b/services/registration/confirm_pin_change_swa @@ -1 +1 @@ -Thibitisha PIN yako mpya: +Thibitisha PIN yako mpya: \ No newline at end of file diff --git a/services/registration/enter_familyname_swa b/services/registration/enter_familyname_swa index 82f64cd..48a38b2 100644 --- a/services/registration/enter_familyname_swa +++ b/services/registration/enter_familyname_swa @@ -1 +1 @@ -Weka jina la familia +Weka jina la familia \ No newline at end of file diff --git a/services/registration/enter_name.vis b/services/registration/enter_name.vis index 563577e..2703068 100644 --- a/services/registration/enter_name.vis +++ b/services/registration/enter_name.vis @@ -7,6 +7,3 @@ HALT RELOAD save_firstname INCMP _ 0 INCMP pin_entry * - - - diff --git a/services/registration/invalid_pin_swa b/services/registration/invalid_pin_swa index 1817570..fd2509f 100644 --- a/services/registration/invalid_pin_swa +++ b/services/registration/invalid_pin_swa @@ -1 +1,2 @@ -PIN mpya na udhibitisho wa pin mpya hazilingani.Tafadhali jaribu tena.Kwa usaidizi piga simu +254757628885. +PIN mpya na udhibitisho wa PIN mpya hazilingani. Tafadhali jaribu tena. +Kwa usaidizi piga simu +254757628885. \ No newline at end of file diff --git a/services/registration/my_vouchers.vis b/services/registration/my_vouchers.vis index b70dbfa..9702573 100644 --- a/services/registration/my_vouchers.vis +++ b/services/registration/my_vouchers.vis @@ -4,6 +4,3 @@ MOUT back 0 HALT INCMP _ 0 INCMP select_voucher 1 - - - diff --git a/services/registration/new_pin b/services/registration/new_pin index bae2814..c2d654e 100644 --- a/services/registration/new_pin +++ b/services/registration/new_pin @@ -1 +1 @@ -Enter a new four number pin +Enter a new four number PIN \ No newline at end of file diff --git a/services/registration/new_pin_swa b/services/registration/new_pin_swa index 1ec32d9..a2dc212 100644 --- a/services/registration/new_pin_swa +++ b/services/registration/new_pin_swa @@ -1,2 +1 @@ -Weka PIN mpya ya nne nambari: - +Weka PIN mpya ya nne nambari: \ No newline at end of file diff --git a/services/registration/old_pin b/services/registration/old_pin index 2c64d42..798d1ce 100644 --- a/services/registration/old_pin +++ b/services/registration/old_pin @@ -1 +1 @@ -Enter your old PIN +Enter your old PIN \ No newline at end of file diff --git a/services/registration/old_pin_swa b/services/registration/old_pin_swa index 312b597..e082773 100644 --- a/services/registration/old_pin_swa +++ b/services/registration/old_pin_swa @@ -1 +1 @@ -Weka PIN yako ya zamani: +Weka PIN yako ya zamani: \ No newline at end of file diff --git a/services/registration/pin_management.vis b/services/registration/pin_management.vis index 3b33dad..86b5bb3 100644 --- a/services/registration/pin_management.vis +++ b/services/registration/pin_management.vis @@ -4,5 +4,4 @@ MOUT guard_pin 3 MOUT back 0 HALT INCMP _ 0 -INCMP old_pin 1 - +INCMP old_pin 1 diff --git a/services/registration/pin_reset_mismatch b/services/registration/pin_reset_mismatch index dc0236b..e75068c 100644 --- a/services/registration/pin_reset_mismatch +++ b/services/registration/pin_reset_mismatch @@ -1 +1 @@ -The PIN is not a match. Try again +The PIN is not a match. Try again \ No newline at end of file diff --git a/services/registration/pin_reset_mismatch.vis b/services/registration/pin_reset_mismatch.vis index 5dc7e7c..b0d4a44 100644 --- a/services/registration/pin_reset_mismatch.vis +++ b/services/registration/pin_reset_mismatch.vis @@ -3,4 +3,3 @@ MOUT quit 9 HALT INCMP confirm_pin_change 1 INCMP quit 9 - diff --git a/services/registration/pin_reset_success b/services/registration/pin_reset_success index e9326ec..47a0fcb 100644 --- a/services/registration/pin_reset_success +++ b/services/registration/pin_reset_success @@ -1 +1 @@ -Your PIN change request has been successful +Your PIN change request has been successful \ No newline at end of file diff --git a/services/registration/pin_reset_success.vis b/services/registration/pin_reset_success.vis index c942519..9a5aedb 100644 --- a/services/registration/pin_reset_success.vis +++ b/services/registration/pin_reset_success.vis @@ -1,10 +1,8 @@ LOAD confirm_pin_change 0 RELOAD confirm_pin_change -CATCH pin_reset_mismatch flag_pin_mismatch 1 +CATCH pin_reset_mismatch flag_pin_mismatch 1 MOUT back 0 MOUT quit 9 HALT INCMP main 0 INCMP quit 9 - - diff --git a/services/registration/pin_reset_success_swa b/services/registration/pin_reset_success_swa index af69b9f..59580ad 100644 --- a/services/registration/pin_reset_success_swa +++ b/services/registration/pin_reset_success_swa @@ -1 +1 @@ -Ombi lako la kubadili PIN limefanikiwa +Ombi lako la kubadili PIN limefanikiwa \ No newline at end of file diff --git a/services/registration/profile_update_success b/services/registration/profile_update_success index 652942a..d8d5706 100644 --- a/services/registration/profile_update_success +++ b/services/registration/profile_update_success @@ -1 +1 @@ -Profile updated successfully +Profile updated successfully \ No newline at end of file diff --git a/services/registration/profile_update_success_swa b/services/registration/profile_update_success_swa index df0af2c..6b46b3d 100644 --- a/services/registration/profile_update_success_swa +++ b/services/registration/profile_update_success_swa @@ -1 +1 @@ -Ombi la Kuweka wasifu limefanikiwa +Ombi la Kuweka wasifu limefanikiwa \ No newline at end of file diff --git a/services/registration/select_gender.vis b/services/registration/select_gender.vis index 25e53d3..c4e60d1 100644 --- a/services/registration/select_gender.vis +++ b/services/registration/select_gender.vis @@ -9,5 +9,3 @@ HALT RELOAD save_gender INCMP _ 0 INCMP pin_entry * - - -- 2.45.2 From 2a1e48e5e8ccc2b8d6b9d1e145deb78699fe4cd2 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 13:31:47 +0300 Subject: [PATCH 33/65] update the test_data with expected output --- test_data.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test_data.json b/test_data.json index a6737f4..3481543 100644 --- a/test_data.json +++ b/test_data.json @@ -188,19 +188,19 @@ }, { "input": "1", - "expectedContent": "Enter your old PIN\n\n0:Back" + "expectedContent": "Enter your old PIN\n0:Back" }, { "input": "1234", - "expectedContent": "Enter a new four number pin\n\n0:Back" + "expectedContent": "Enter a new four number pin\n0:Back" }, { "input": "1234", - "expectedContent": "Confirm your new PIN:\n\n0:Back" + "expectedContent": "Confirm your new PIN:\n0:Back" }, { "input": "1234", - "expectedContent": "Your PIN change request has been successful\n\n0:Back\n9:Quit" + "expectedContent": "Your PIN change request has been successful\n0:Back\n9:Quit" }, { "input": "9", @@ -265,7 +265,7 @@ }, { "input": "1234", - "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" }, { "input": "9", @@ -299,7 +299,7 @@ }, { "input": "1234", - "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" }, { "input": "9", @@ -333,7 +333,7 @@ }, { "input": "1234", - "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" }, { "input": "9", @@ -367,7 +367,7 @@ }, { "input": "1234", - "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" }, { "input": "9", @@ -401,7 +401,7 @@ }, { "input": "1234", - "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" }, { "input": "9", @@ -435,7 +435,7 @@ }, { "input": "1234", - "expectedContent": "Profile updated successfully\n\n0:Back\n9:Quit" + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" }, { "input": "9", -- 2.45.2 From 24380e1449e0bfd97db9e9d74467bd34881087d1 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 14:25:29 +0300 Subject: [PATCH 34/65] update the templates --- services/registration/new_pin | 2 +- services/registration/new_pin_swa | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/registration/new_pin b/services/registration/new_pin index c2d654e..30536ea 100644 --- a/services/registration/new_pin +++ b/services/registration/new_pin @@ -1 +1 @@ -Enter a new four number PIN \ No newline at end of file +Enter a new four number PIN: \ No newline at end of file diff --git a/services/registration/new_pin_swa b/services/registration/new_pin_swa index a2dc212..a0e087c 100644 --- a/services/registration/new_pin_swa +++ b/services/registration/new_pin_swa @@ -1 +1 @@ -Weka PIN mpya ya nne nambari: \ No newline at end of file +Weka PIN mpya ya nne nambari: \ No newline at end of file -- 2.45.2 From 94bf4ffaa6690307bcb9015e1afacdc9d51fee47 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 14:28:21 +0300 Subject: [PATCH 35/65] combine some test cases and rename the account creation test --- menu_traversal_test.go | 63 +--------------------------------- test_data.json | 78 +++++++++--------------------------------- 2 files changed, 18 insertions(+), 123 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 861a09d..e8ffdba 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -25,7 +25,7 @@ func extractPublicKey(response []byte) string { return "" } -func TestUserRegistration(t *testing.T) { +func TestAccountCreationSuccessful(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() ctx := context.Background() @@ -58,36 +58,6 @@ func TestUserRegistration(t *testing.T) { } } -func TestTerms(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112_a") - defer fn() - ctx := context.Background() - sessions := testData - - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "account_creation_accept_terms") - for _, group := range groups { - for _, step := range group.Steps { - _, err := en.Exec(ctx, []byte(step.Input)) - if err != nil { - t.Fatalf("Test case '%s' failed during Exec: %v", group.Name, err) - } - - w := bytes.NewBuffer(nil) - _, err = en.Flush(ctx, w) - if err != nil { - t.Fatalf("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 TestAccountRegistrationRejectTerms(t *testing.T) { en, fn := enginetest.TestEngine("session1234112_b") defer fn() @@ -119,37 +89,6 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { } } -func TestAccountRegistrationInvalidPin(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112_c") - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "account_creation_invalid_pin") - for _, group := range groups { - for _, step := range group.Steps { - cont, err := en.Exec(ctx, []byte(step.Input)) - if err != nil { - t.Fatalf("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.Fatalf("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 TestSendWithInvalidInputs(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() diff --git a/test_data.json b/test_data.json index 3481543..8fe3ba0 100644 --- a/test_data.json +++ b/test_data.json @@ -4,66 +4,6 @@ "groups": [ { "name": "account_creation_successful", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "0", - "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" - }, - { - "input": "1234", - "expectedContent": "Enter your four number PIN again:" - }, - { - "input": "1234", - "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "account_creation_accept_terms", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "0", - "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" - } - - ] - }, - { - "name": "account_creation_reject_terms", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "1", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "account_creation_invalid_pin", "steps": [ { "input": "", @@ -93,7 +33,23 @@ "input": "1234", "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" } - + ] + }, + { + "name": "account_creation_reject_terms", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "1", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } ] }, { -- 2.45.2 From 96ec3919b2ff45e939233141fbdc10f291b3fef8 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 2 Oct 2024 14:39:48 +0300 Subject: [PATCH 36/65] update test data file --- test_data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_data.json b/test_data.json index 6b8c678..405d3b7 100644 --- a/test_data.json +++ b/test_data.json @@ -148,7 +148,7 @@ }, { "input": "1234", - "expectedContent": "Enter a new four number pin\n0:Back" + "expectedContent": "Enter a new four number PIN:\n0:Back" }, { "input": "1234", -- 2.45.2 From 986f3979fb8bd77d2c87ecb15330a70f6b14672b Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 15:50:52 +0300 Subject: [PATCH 37/65] use a dynamic public_key --- menu_traversal_test.go | 10 +++++++--- test_data.json | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/menu_traversal_test.go b/menu_traversal_test.go index 3bf88fd..77ff5de 100644 --- a/menu_traversal_test.go +++ b/menu_traversal_test.go @@ -659,10 +659,14 @@ func TestMyAccount_MyAddress(t *testing.T) { 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) - } + publicKey := extractPublicKey(b) + + expectedContent := bytes.Replace([]byte(step.ExpectedContent), []byte("{public_key}"), []byte(publicKey), -1) + + if !bytes.Equal(b, expectedContent) { + t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", expectedContent, b) + } } } } diff --git a/test_data.json b/test_data.json index 405d3b7..5967788 100644 --- a/test_data.json +++ b/test_data.json @@ -583,7 +583,7 @@ }, { "input": "6", - "expectedContent": "Address: 0xdF8CB1D9b5BDaE418E5Bee107031cA7d933906CD\n9:Quit" + "expectedContent": "Address: {public_key}\n9:Quit" }, { "input": "9", -- 2.45.2 From 73013f53bb8ace93ccf35e287d39e2adf2f956ca Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 15:52:55 +0300 Subject: [PATCH 38/65] added engine Finish --- engine/engine.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/engine.go b/engine/engine.go index 5fe0977..e66dc0c 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -83,7 +83,12 @@ func TestEngine(sessionId string) (engine.Engine, func()) { en = en.WithFirst(hl.Init) cleanFn := func() { - err := menuStorageService.Close() + err := en.Finish() + if err != nil { + logg.Errorf(err.Error()) + } + + err = menuStorageService.Close() if err != nil { logg.Errorf(err.Error()) } -- 2.45.2 From 0fa4a818262ae9d117e531273f5fe8cfd9c2a0ba Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 11:42:41 +0300 Subject: [PATCH 39/65] updated the TestAuthorize --- internal/handlers/ussd/menuhandler_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index d0367f0..64d0b0e 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -892,7 +892,10 @@ func TestAuthorize(t *testing.T) { { name: "Test with pin that is not a 4 digit", input: []byte("1235aqds"), - expectedResult: resource.Result{}, + expectedResult: resource.Result{ + FlagReset: []uint32{flag_account_authorized}, + FlagSet: []uint32{flag_incorrect_pin}, + }, }, } -- 2.45.2 From d94758c32c2157bd03293da423eb23f3e1ac7703 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 11:44:34 +0300 Subject: [PATCH 40/65] moved the test to test_engine folder --- test_data.json | 598 ------------------ .../menu_traversal_test.go | 16 - test_engine/test_data.json | 575 +++++++++++++++++ 3 files changed, 575 insertions(+), 614 deletions(-) delete mode 100644 test_data.json rename menu_traversal_test.go => test_engine/menu_traversal_test.go (99%) create mode 100644 test_engine/test_data.json diff --git a/test_data.json b/test_data.json deleted file mode 100644 index 5967788..0000000 --- a/test_data.json +++ /dev/null @@ -1,598 +0,0 @@ -[ - { - "name": "session one", - "groups": [ - { - "name": "account_creation_successful", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "0", - "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" - }, - { - "input": "1234", - "expectedContent": "Enter your four number PIN again:" - }, - { - "input": "1111", - "expectedContent": "The PIN is not a match. Try again\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Enter your four number PIN again:" - }, - { - "input": "1234", - "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "account_creation_reject_terms", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "1", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "send_with_invalid_inputs", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Enter recipient's phone number:\n0:Back" - }, - { - "input": "000", - "expectedContent": "000 is not registered or invalid, please try again:\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Enter recipient's phone number:\n0:Back" - }, - { - "input": "065656", - "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" - }, - { - "input": "0.1", - "expectedContent": "Amount 0.1 is invalid, please try again:\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" - }, - { - "input": "0.001", - "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" - }, - { - "input": "1222", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" - }, - { - "input": "1234", - "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." - } - ] - }, - { - "name": "main_menu_help", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "4", - "expectedContent": "For more help,please call: 0757628885" - } - ] - }, - { - "name": "main_menu_quit", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "my_account_change_pin", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "5", - "expectedContent": "PIN Management\n1:Change PIN\n2:Reset other's PIN\n3:Guard my PIN\n0:Back" - }, - { - "input": "1", - "expectedContent": "Enter your old PIN\n0:Back" - }, - { - "input": "1234", - "expectedContent": "Enter a new four number PIN:\n0:Back" - }, - { - "input": "1234", - "expectedContent": "Confirm your new PIN:\n0:Back" - }, - { - "input": "1234", - "expectedContent": "Your PIN change request has been successful\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_language_change", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Select language:\n0:english\n1:kiswahili" - }, - { - "input": "1", - "expectedContent": "Ombi lako la kubadilisha lugha limefanikiwa.\n0:Rudi\n9:Ondoka" - }, - { - "input": "9", - "expectedContent": "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" - } - - ] - }, - { - "name": "menu_my_account_language_change_incorectpin", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - } - - ] - }, - { - "name": "menu_my_account_edit_firstname", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "1", - "expectedContent": "Enter your first names:\n0:Back" - }, - { - "input": "foo", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_familyname", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "2", - "expectedContent": "Enter family name:\n0:Back" - }, - { - "input": "bar", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_gender", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "3", - "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" - }, - { - "input": "Female", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_yob", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "4", - "expectedContent": "Enter your year of birth\n0:Back" - }, - { - "input": "1945", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_location", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "5", - "expectedContent": "Enter your location:\n0:Back" - }, - { - "input": "Kilifi", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_offerings", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "6", - "expectedContent": "Enter the services or goods you offer: \n0:Back" - }, - { - "input": "Bananas", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_view_profile", - "steps": [ - { - - "input": "", - "expectedContent":"Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "7", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "My profile:\nName: foo bar\nGender: Female\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" - }, - { - "input": "0", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - - "input": "9", - "expectedContent":"" - } - ] - }, - { - "name": "menu_my_account_check_my_balance", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" - } - - ] - }, - { - "name": "menu_my_account_check_community_balance", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" - } - - ] - }, - { - "name": "menu_my_account_check_my_balance_incorrect_pin", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - } - - ] - }, - { - "name": "menu_my_account_check_community_balance_incorrect_pin", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - } - - ] - }, - { - "name": "menu_my_account_my_address", - "steps": [ - { - "input":"", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "6", - "expectedContent": "Address: {public_key}\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - - ] - } - - ] - } -] diff --git a/menu_traversal_test.go b/test_engine/menu_traversal_test.go similarity index 99% rename from menu_traversal_test.go rename to test_engine/menu_traversal_test.go index 77ff5de..15c3e20 100644 --- a/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -34,9 +34,7 @@ func TestAccountCreationSuccessful(t *testing.T) { groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful") for _, group := range groups { for _, step := range group.Steps { - cont, err := en.Exec(ctx, []byte(step.Input)) - if err != nil { t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err) } @@ -52,7 +50,6 @@ func TestAccountCreationSuccessful(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -246,7 +243,6 @@ func TestMyAccount_Change_Language(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -278,7 +274,6 @@ func TestMyAccount_Change_Language_Incorrect_Pin(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -310,7 +305,6 @@ func TestMyAccount_Edit_firstname(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -342,7 +336,6 @@ func TestMyAccount_Edit_familyname(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -374,7 +367,6 @@ func TestMyAccount_Edit_gender(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -406,7 +398,6 @@ func TestMyAccount_Edit_yob(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -438,7 +429,6 @@ func TestMyAccount_Edit_location(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -470,7 +460,6 @@ func TestMyAccount_Edit_offerings(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -502,7 +491,6 @@ func TestMyAccount_View_Profile(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -534,7 +522,6 @@ func TestMyAccount_Check_My_Balance(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -566,7 +553,6 @@ func TestMyAccount_Check_My_Balance_IncorrectPin(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -598,7 +584,6 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } @@ -630,7 +615,6 @@ func TestMyAccount_Check_Community_Balance_IncorrectPin(t *testing.T) { if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } - } } } diff --git a/test_engine/test_data.json b/test_engine/test_data.json new file mode 100644 index 0000000..7e81354 --- /dev/null +++ b/test_engine/test_data.json @@ -0,0 +1,575 @@ +[ + { + "name": "session one", + "groups": [ + { + "name": "account_creation_successful", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "0", + "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" + }, + { + "input": "1234", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1111", + "expectedContent": "The PIN is not a match. Try again\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1234", + "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "account_creation_reject_terms", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "1", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "send_with_invalid_inputs", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter recipient's phone number:\n0:Back" + }, + { + "input": "000", + "expectedContent": "000 is not registered or invalid, please try again:\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter recipient's phone number:\n0:Back" + }, + { + "input": "065656", + "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" + }, + { + "input": "0.1", + "expectedContent": "Amount 0.1 is invalid, please try again:\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" + }, + { + "input": "0.001", + "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + }, + { + "input": "1222", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + }, + { + "input": "1234", + "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." + } + ] + }, + { + "name": "main_menu_help", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "4", + "expectedContent": "For more help,please call: 0757628885" + } + ] + }, + { + "name": "main_menu_quit", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "my_account_change_pin", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "5", + "expectedContent": "PIN Management\n1:Change PIN\n2:Reset other's PIN\n3:Guard my PIN\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your old PIN\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Enter a new four number PIN:\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Confirm your new PIN:\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Your PIN change request has been successful\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_language_change", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Select language:\n0:english\n1:kiswahili" + }, + { + "input": "1", + "expectedContent": "Ombi lako la kubadilisha lugha limefanikiwa.\n0:Rudi\n9:Ondoka" + }, + { + "input": "9", + "expectedContent": "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" + } + ] + }, + { + "name": "menu_my_account_language_change_incorectpin", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_edit_firstname", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your first names:\n0:Back" + }, + { + "input": "foo", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_familyname", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "2", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "bar", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_gender", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "3", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "Female", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_yob", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "4", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1945", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_location", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "5", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_edit_offerings", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "6", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_view_profile", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "7", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "My profile:\nName: foo bar\nGender: Female\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "9", + "expectedContent": "" + } + ] + }, + { + "name": "menu_my_account_check_my_balance", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" + } + ] + }, + { + "name": "menu_my_account_check_community_balance", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" + } + ] + }, + { + "name": "menu_my_account_check_my_balance_incorrect_pin", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_check_community_balance_incorrect_pin", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_my_address", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "6", + "expectedContent": "Address: {public_key}\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + } + ] + } +] \ No newline at end of file -- 2.45.2 From 587cfb5a364b1762e57d607256f98b6757701665 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 11:45:37 +0300 Subject: [PATCH 41/65] use the pp.csv from the scriptDir --- engine/engine.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engine/engine.go b/engine/engine.go index e66dc0c..c936b91 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -11,11 +11,13 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/urdt/ussd/internal/handlers" "git.grassecon.net/urdt/ussd/internal/storage" + testdataloader "github.com/peteole/testdata-loader" ) var ( + baseDir = testdataloader.GetBasePath() logg = logging.NewVanilla() - scriptDir = path.Join("services", "registration") + scriptDir = path.Join(baseDir, "services", "registration") ) func TestEngine(sessionId string) (engine.Engine, func()) { -- 2.45.2 From 59aa4eae77fac4739efbaa3d73b5d72a1e758542 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 11:45:56 +0300 Subject: [PATCH 42/65] removed unused code --- testdata/main.vis | 0 testdata/testdata.go | 118 ------------------------------------------- 2 files changed, 118 deletions(-) delete mode 100644 testdata/main.vis delete mode 100644 testdata/testdata.go diff --git a/testdata/main.vis b/testdata/main.vis deleted file mode 100644 index e69de29..0000000 diff --git a/testdata/testdata.go b/testdata/testdata.go deleted file mode 100644 index 338c1f2..0000000 --- a/testdata/testdata.go +++ /dev/null @@ -1,118 +0,0 @@ -package testdata - -import ( - "context" - "io/ioutil" - "os" - "path" - - "git.defalsify.org/vise.git/db" - fsdb "git.defalsify.org/vise.git/db/fs" - "git.defalsify.org/vise.git/logging" - "git.defalsify.org/vise.git/vm" - testdataloader "github.com/peteole/testdata-loader" -) - -func outNew(sym string, b []byte, tpl string, data map[string]string) error { - logg.Debugf("testdata out", "sym", sym) - store.SetPrefix(db.DATATYPE_TEMPLATE) - err := store.Put(ctx, []byte(sym), []byte(tpl)) - if err != nil { - return err - } - store.SetPrefix(db.DATATYPE_BIN) - err = store.Put(ctx, []byte(sym), b) - if err != nil { - return err - } - store.SetPrefix(db.DATATYPE_STATICLOAD) - for k, v := range data { - logg.Debugf("testdata out staticload", "sym", sym, "k", k, "v", v) - err = store.Put(ctx, []byte(k), []byte(v)) - if err != nil { - return err - } - } - return nil -} - -var ( - ctx = context.Background() - store = fsdb.NewFsDb() - out = outNew - logg = logging.NewVanilla().WithDomain("testdata") - BaseDir = testdataloader.GetBasePath() - DataDir = "" - dirLock = false -) - -type genFunc func() error - -func terms() error { - b := []byte{} - b = vm.NewLine(b, vm.MOUT, []string{"yes", "1"}, nil, nil) - b = vm.NewLine(b, vm.MOUT, []string{"no", "2"}, nil, nil) - b = vm.NewLine(b, vm.HALT, nil, nil, nil) - b = vm.NewLine(b, vm.INCMP, []string{"create_pin", "1"}, nil, nil) - b = vm.NewLine(b, vm.INCMP, []string{"quit", "2"}, nil, nil) - tpl := "Do you agree to terms and conditions?" - return out("terms", b, tpl, nil) -} - -func createPin() error { - b := []byte{} - b = vm.NewLine(b, vm.MOUT, []string{"exit", "0"}, nil, nil) - b = vm.NewLine(b, vm.HALT, nil, nil, nil) - b = vm.NewLine(b, vm.INCMP, []string{"0", "1"}, nil, nil) - tpl := "create pin" - return out("create_pin", b, tpl, nil) -} - -func quit() error { - // b := []byte{} - // b = vm.NewLine(b, vm.LOAD, []string{"quit"}, []byte{0x00}, nil) - // //b = vm.NewLine(b, vm.RELOAD, []string{"quit"}, []byte{0x00}, nil) - // b = vm.NewLine(b, vm.HALT, nil, nil, nil) - - // return out("quit", b, "quit", nil) - b := vm.NewLine(nil, vm.LOAD, []string{"quit"}, []byte{0x00}, nil) - b = vm.NewLine(b, vm.RELOAD, []string{"quit"}, nil, nil) - b = vm.NewLine(b, vm.HALT, nil, nil, nil) - - fp := path.Join(DataDir, "nothing.bin") - err := os.WriteFile(fp, b, 0600) - return err -} - -func generate() error { - err := os.MkdirAll(DataDir, 0755) - if err != nil { - return err - } - store = fsdb.NewFsDb() - store.Connect(ctx, DataDir) - store.SetLock(db.DATATYPE_TEMPLATE, false) - store.SetLock(db.DATATYPE_BIN, false) - store.SetLock(db.DATATYPE_MENU, false) - store.SetLock(db.DATATYPE_STATICLOAD, false) - - fns := []genFunc{terms, createPin, quit} - for _, fn := range fns { - err = fn() - if err != nil { - return err - } - } - return nil -} - -func Generate() (string, error) { - dir, err := ioutil.TempDir("", "vise_testdata_") - if err != nil { - return "", err - } - DataDir = dir - dirLock = true - err = generate() - return dir, err -} -- 2.45.2 From c965d3083d251cdbaae07a57dfa7571fd9a4e7e5 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 11:53:46 +0300 Subject: [PATCH 43/65] renamed sym to symbol to avoid confusion --- internal/handlers/ussd/menuhandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 0e40cb5..4fc6dbb 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -117,9 +117,9 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result - sym, _ = h.st.Where() + symbol, _ := h.st.Where() - switch sym { + switch symbol { case "set_default": res.FlagSet = append(res.FlagSet, state.FLAG_LANG) res.Content = "eng" -- 2.45.2 From 1b8c8a12c081a1bc7c342e89c778982415af61cd Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 12:51:03 +0300 Subject: [PATCH 44/65] combine the invalid PIN case --- test_engine/test_data.json | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/test_engine/test_data.json b/test_engine/test_data.json index 7e81354..21cf451 100644 --- a/test_engine/test_data.json +++ b/test_engine/test_data.json @@ -179,38 +179,25 @@ "input": "2", "expectedContent": "Please enter your PIN:" }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, { "input": "1234", "expectedContent": "Select language:\n0:english\n1:kiswahili" }, { - "input": "1", - "expectedContent": "Ombi lako la kubadilisha lugha limefanikiwa.\n0:Rudi\n9:Ondoka" + "input": "0", + "expectedContent": "Your language change request was successful.\n0:Back\n9:Quit" }, { "input": "9", - "expectedContent": "Asante kwa kutumia huduma ya Sarafu. Kwaheri!" - } - ] - }, - { - "name": "menu_my_account_language_change_incorectpin", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + "expectedContent": "Thank you for using Sarafu. Goodbye!" } ] }, -- 2.45.2 From 089691db4c91239188c516e0c82aae43645d9b72 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 12:51:46 +0300 Subject: [PATCH 45/65] remove combined test --- test_engine/menu_traversal_test.go | 31 ------------------------------ 1 file changed, 31 deletions(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 15c3e20..af7c329 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -248,37 +248,6 @@ func TestMyAccount_Change_Language(t *testing.T) { } } -func TestMyAccount_Change_Language_Incorrect_Pin(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_language_change_incorectpin") - 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_Edit_firstname(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() -- 2.45.2 From 0f2ec2f2bd17ad421ee47b68265b9f043a7ae679 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 3 Oct 2024 13:47:31 +0300 Subject: [PATCH 46/65] reset authorized flag,update test data file --- services/registration/language_changed.vis | 1 + test_engine/test_data.json | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/services/registration/language_changed.vis b/services/registration/language_changed.vis index 832ef22..109b237 100644 --- a/services/registration/language_changed.vis +++ b/services/registration/language_changed.vis @@ -1,3 +1,4 @@ +RELOAD reset_account_authorized MOUT back 0 MOUT quit 9 HALT diff --git a/test_engine/test_data.json b/test_engine/test_data.json index 21cf451..1d16cba 100644 --- a/test_engine/test_data.json +++ b/test_engine/test_data.json @@ -195,6 +195,10 @@ "input": "0", "expectedContent": "Your language change request was successful.\n0:Back\n9:Quit" }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, { "input": "9", "expectedContent": "Thank you for using Sarafu. Goodbye!" -- 2.45.2 From d94037d4998fb1f2a554297ec62ebafaaa86d219 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 14:07:36 +0300 Subject: [PATCH 47/65] combine the invalid PIN case and remove unused tests --- test_engine/menu_traversal_test.go | 62 ------------------------------ test_engine/test_data.json | 58 ++++++---------------------- 2 files changed, 12 insertions(+), 108 deletions(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index af7c329..81dfa8f 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -496,37 +496,6 @@ func TestMyAccount_Check_My_Balance(t *testing.T) { } } -func TestMyAccount_Check_My_Balance_IncorrectPin(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_my_balance_incorrect_pin") - 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_Check_Community_Balance(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() @@ -558,37 +527,6 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) { } } -func TestMyAccount_Check_Community_Balance_IncorrectPin(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_community_balance_incorrect_pin") - 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_MyAddress(t *testing.T) { en, fn := enginetest.TestEngine("session1234112") defer fn() diff --git a/test_engine/test_data.json b/test_engine/test_data.json index 1d16cba..e31694d 100644 --- a/test_engine/test_data.json +++ b/test_engine/test_data.json @@ -459,6 +459,14 @@ "input": "1", "expectedContent": "Please enter your PIN:" }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, { "input": "1234", "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" @@ -485,58 +493,16 @@ "expectedContent": "Please enter your PIN:" }, { - "input": "1234", - "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" - } - ] - }, - { - "name": "menu_my_account_check_my_balance_incorrect_pin", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" }, { "input": "1", "expectedContent": "Please enter your PIN:" }, { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - } - ] - }, - { - "name": "menu_my_account_check_community_balance_incorrect_pin", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + "input": "1234", + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" } ] }, -- 2.45.2 From e2316b38a85039af24c57250e1c1dac58139f890 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Thu, 3 Oct 2024 14:55:25 +0300 Subject: [PATCH 48/65] reset account authorized and perform clean quit on view profile test --- services/registration/edit_profile.vis | 1 + test_engine/test_data.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/registration/edit_profile.vis b/services/registration/edit_profile.vis index 6c1986f..4116809 100644 --- a/services/registration/edit_profile.vis +++ b/services/registration/edit_profile.vis @@ -1,4 +1,5 @@ LOAD reset_account_authorized 16 +RELOAD reset_account_authorized LOAD reset_allow_update 0 RELOAD reset_allow_update MOUT edit_name 1 diff --git a/test_engine/test_data.json b/test_engine/test_data.json index e31694d..525c11b 100644 --- a/test_engine/test_data.json +++ b/test_engine/test_data.json @@ -435,7 +435,7 @@ "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" }, { - "input": "9", + "input": "0", "expectedContent": "" } ] -- 2.45.2 From d6cd2766dfcccfd3599f495a1dbda8f122237526 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 16:54:30 +0300 Subject: [PATCH 49/65] add a Random SessionID for each test run --- test_engine/menu_traversal_test.go | 177 ++++++++++++++++------------- test_engine/test_data.json | 6 +- 2 files changed, 104 insertions(+), 79 deletions(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 81dfa8f..657b1db 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -3,17 +3,31 @@ package main import ( "bytes" "context" + "crypto/rand" + "encoding/hex" "regexp" "testing" + "time" "git.grassecon.net/urdt/ussd/driver" enginetest "git.grassecon.net/urdt/ussd/engine" ) var ( - testData = driver.ReadData() + testData = driver.ReadData() + sessionID string ) +// GenerateRandomSessionID generates a random session ID of 10 characters +func GenerateRandomSessionID() string { + bytes := make([]byte, 5) + _, err := rand.Read(bytes) + if err != nil { + return "default_session" + } + return hex.EncodeToString(bytes) +} + // Extract the public key from the engine response func extractPublicKey(response []byte) string { // Regex pattern to match the public key starting with 0x and 40 characters @@ -25,8 +39,13 @@ func extractPublicKey(response []byte) string { return "" } +func TestMain(m *testing.M) { + sessionID = GenerateRandomSessionID() + m.Run() +} + func TestAccountCreationSuccessful(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -53,10 +72,12 @@ func TestAccountCreationSuccessful(t *testing.T) { } } } + // Adding a sleep after the test to wait for registration to complete the process + time.Sleep(5 * time.Second) } func TestAccountRegistrationRejectTerms(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112_b") + en, fn := enginetest.TestEngine(sessionID + "_b") defer fn() ctx := context.Background() sessions := testData @@ -87,7 +108,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) { } func TestSendWithInvalidInputs(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -124,8 +145,39 @@ func TestSendWithInvalidInputs(t *testing.T) { } } +func TestMyAccount_Check_My_Balance(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_check_my_balance") + 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 TestMainMenuHelp(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -156,7 +208,7 @@ func TestMainMenuHelp(t *testing.T) { } func TestMainMenuQuit(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -186,8 +238,39 @@ func TestMainMenuQuit(t *testing.T) { } } +func TestMyAccount_Check_Community_Balance(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_check_community_balance") + 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 TestMyAccountChangePin(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -218,7 +301,7 @@ func TestMyAccountChangePin(t *testing.T) { } func TestMyAccount_Change_Language(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -249,7 +332,7 @@ func TestMyAccount_Change_Language(t *testing.T) { } func TestMyAccount_Edit_firstname(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -280,7 +363,7 @@ func TestMyAccount_Edit_firstname(t *testing.T) { } func TestMyAccount_Edit_familyname(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -311,7 +394,7 @@ func TestMyAccount_Edit_familyname(t *testing.T) { } func TestMyAccount_Edit_gender(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -342,7 +425,7 @@ func TestMyAccount_Edit_gender(t *testing.T) { } func TestMyAccount_Edit_yob(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -373,7 +456,7 @@ func TestMyAccount_Edit_yob(t *testing.T) { } func TestMyAccount_Edit_location(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -404,7 +487,7 @@ func TestMyAccount_Edit_location(t *testing.T) { } func TestMyAccount_Edit_offerings(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -435,7 +518,7 @@ func TestMyAccount_Edit_offerings(t *testing.T) { } func TestMyAccount_View_Profile(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -465,70 +548,8 @@ func TestMyAccount_View_Profile(t *testing.T) { } } -func TestMyAccount_Check_My_Balance(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_my_balance") - 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_Check_Community_Balance(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_check_community_balance") - 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_MyAddress(t *testing.T) { - en, fn := enginetest.TestEngine("session1234112") + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData diff --git a/test_engine/test_data.json b/test_engine/test_data.json index 525c11b..91efad8 100644 --- a/test_engine/test_data.json +++ b/test_engine/test_data.json @@ -436,7 +436,11 @@ }, { "input": "0", - "expectedContent": "" + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" } ] }, -- 2.45.2 From b7d93c22494cd71ba97876753f2961bf45b60347 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 3 Oct 2024 17:47:48 +0300 Subject: [PATCH 50/65] use a UUID for the sessionId --- go.mod | 1 + go.sum | 2 ++ test_engine/menu_traversal_test.go | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index c4c5167..1f67f34 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/barbashov/iso639-3 v0.0.0-20211020172741-1f4ffb2d8d1c // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect + github.com/gofrs/uuid v4.4.0+incompatible github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect github.com/mattn/kinako v0.0.0-20170717041458-332c0a7e205a // indirect diff --git a/go.sum b/go.sum index ed5636f..0eccb60 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= +github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= +github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4 h1:U4kkNYryi/qfbBF8gh7Vsbuz+cVmhf5kt6pE9bYYyLo= github.com/graygnuorg/go-gdbm v0.0.0-20220711140707-71387d66dce4/go.mod h1:zpZDgZFzeq9s0MIeB1P50NIEWDFFHSFBohI/NbaTD/Y= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 657b1db..0112b00 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -3,14 +3,13 @@ package main import ( "bytes" "context" - "crypto/rand" - "encoding/hex" "regexp" "testing" "time" "git.grassecon.net/urdt/ussd/driver" enginetest "git.grassecon.net/urdt/ussd/engine" + "github.com/gofrs/uuid" ) var ( @@ -18,14 +17,13 @@ var ( sessionID string ) -// GenerateRandomSessionID generates a random session ID of 10 characters -func GenerateRandomSessionID() string { - bytes := make([]byte, 5) - _, err := rand.Read(bytes) +// GenerateRandomSessionID generates a random UUID for the sessionID +func GenerateUUID() string { + u, err := uuid.NewV4() if err != nil { - return "default_session" + return "default_uuid" } - return hex.EncodeToString(bytes) + return u.String() } // Extract the public key from the engine response @@ -40,7 +38,7 @@ func extractPublicKey(response []byte) string { } func TestMain(m *testing.M) { - sessionID = GenerateRandomSessionID() + sessionID = GenerateUUID() m.Run() } @@ -77,7 +75,9 @@ func TestAccountCreationSuccessful(t *testing.T) { } func TestAccountRegistrationRejectTerms(t *testing.T) { - en, fn := enginetest.TestEngine(sessionID + "_b") + // Generate a new UUID for this edge case test + edgeCaseSessionID := GenerateUUID() + en, fn := enginetest.TestEngine(edgeCaseSessionID) defer fn() ctx := context.Background() sessions := testData -- 2.45.2 From ddfd9d4e895549470b946c7bc7e1f2518b2542cf Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 11:11:41 +0300 Subject: [PATCH 51/65] fix failing test --- engine/engine.go | 5 +- test_engine/menu_traversal_test.go | 103 ++++++++++++++++------------- test_engine/test_data.json | 6 +- 3 files changed, 63 insertions(+), 51 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index c936b91..b5510aa 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -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 } diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 657b1db..116da59 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -5,12 +5,14 @@ import ( "context" "crypto/rand" "encoding/hex" + "fmt" "regexp" "testing" "time" "git.grassecon.net/urdt/ussd/driver" enginetest "git.grassecon.net/urdt/ussd/engine" + "git.grassecon.net/urdt/ussd/internal/utils" ) var ( @@ -45,7 +47,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 +79,7 @@ func TestAccountCreationSuccessful(t *testing.T) { } func TestAccountRegistrationRejectTerms(t *testing.T) { - en, fn := enginetest.TestEngine(sessionID + "_b") + en, fn, _ := enginetest.TestEngine(sessionID + "_b") defer fn() ctx := context.Background() sessions := testData @@ -108,7 +110,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 +148,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 +179,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 +210,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 +241,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 +272,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 +303,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 +334,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 +365,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 +396,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 +418,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 +428,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,10 +459,12 @@ func TestMyAccount_Edit_yob(t *testing.T) { } func TestMyAccount_Edit_location(t *testing.T) { - en, fn := enginetest.TestEngine(sessionID) + en, fn, db := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData + + userDataStore := utils.UserDataStore{Db: *db} for _, session := range sessions { groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_location") for _, group := range groups { @@ -478,6 +483,11 @@ func TestMyAccount_Edit_location(t *testing.T) { t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err) } b := w.Bytes() + location, err := userDataStore.ReadEntry(ctx, sessionID, utils.DATA_LOCATION) + if err != nil { + t.Fail() + } + fmt.Println("location:", string(location)) if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } @@ -487,7 +497,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 +506,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 +529,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 +563,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) + } + } + } + } +} diff --git a/test_engine/test_data.json b/test_engine/test_data.json index 91efad8..4af08e9 100644 --- a/test_engine/test_data.json +++ b/test_engine/test_data.json @@ -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", -- 2.45.2 From 9647d29bd7a75cc12fef512dd219b2a6e8199a4e Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 11:17:19 +0300 Subject: [PATCH 52/65] resolve failing test --- test_engine/menu_traversal_test.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index f234f6d..51d85ec 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -458,12 +458,10 @@ func TestMyAccount_Edit_yob(t *testing.T) { } func TestMyAccount_Edit_location(t *testing.T) { - en, fn, db := enginetest.TestEngine(sessionID) + en, fn, _ := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData - - userDataStore := utils.UserDataStore{Db: *db} for _, session := range sessions { groups := driver.FilterGroupsByName(session.Groups, "menu_my_account_edit_location") for _, group := range groups { @@ -482,11 +480,6 @@ func TestMyAccount_Edit_location(t *testing.T) { t.Errorf("Test case '%s' failed during Flush: %v", group.Name, err) } b := w.Bytes() - location, err := userDataStore.ReadEntry(ctx, sessionID, utils.DATA_LOCATION) - if err != nil { - t.Fail() - } - fmt.Println("location:", string(location)) if !bytes.Equal(b, []byte(step.ExpectedContent)) { t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", step.ExpectedContent, b) } -- 2.45.2 From bf1df95af1007e7f292ab7302d8ab96c8fcd4f41 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 16:53:52 +0300 Subject: [PATCH 53/65] pass account service implementation --- cmd/africastalking/main.go | 4 +++- cmd/async/main.go | 5 ++++- cmd/http/main.go | 4 +++- cmd/main.go | 5 +++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index c24c4b1..cc5124d 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -17,6 +17,7 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/urdt/ussd/internal/handlers" + "git.grassecon.net/urdt/ussd/internal/handlers/server" httpserver "git.grassecon.net/urdt/ussd/internal/http" "git.grassecon.net/urdt/ussd/internal/storage" ) @@ -127,7 +128,8 @@ func main() { os.Exit(1) } - hl, err := lhs.GetHandler() + accountService := server.AccountService{} + hl, err := lhs.GetHandler(&accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/async/main.go b/cmd/async/main.go index 09236fd..2d4e083 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -14,6 +14,7 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/urdt/ussd/internal/handlers" + "git.grassecon.net/urdt/ussd/internal/handlers/server" "git.grassecon.net/urdt/ussd/internal/storage" ) @@ -95,7 +96,9 @@ func main() { lhs, err := handlers.NewLocalHandlerService(pfp, true, dbResource, cfg, rs) lhs.SetDataStore(&userdataStore) - hl, err := lhs.GetHandler() + accountService := server.AccountService{} + + hl, err := lhs.GetHandler(&accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/http/main.go b/cmd/http/main.go index 6b868ed..8864135 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -16,6 +16,7 @@ import ( "git.defalsify.org/vise.git/resource" "git.grassecon.net/urdt/ussd/internal/handlers" + "git.grassecon.net/urdt/ussd/internal/handlers/server" httpserver "git.grassecon.net/urdt/ussd/internal/http" "git.grassecon.net/urdt/ussd/internal/storage" ) @@ -88,7 +89,8 @@ func main() { os.Exit(1) } - hl, err := lhs.GetHandler() + accountService := server.AccountService{} + hl, err := lhs.GetHandler(&accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/cmd/main.go b/cmd/main.go index 9db5e0a..c8055bc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -11,6 +11,7 @@ import ( "git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/resource" "git.grassecon.net/urdt/ussd/internal/handlers" + "git.grassecon.net/urdt/ussd/internal/handlers/server" "git.grassecon.net/urdt/ussd/internal/storage" ) @@ -84,8 +85,8 @@ func main() { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) } - - hl, err := lhs.GetHandler() + accountService := server.AccountService{} + hl, err := lhs.GetHandler(&accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) -- 2.45.2 From 09bf2666446eea5078cc08e2599330c7512640de Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 16:56:23 +0300 Subject: [PATCH 54/65] pass account service --- engine/engine.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/engine/engine.go b/engine/engine.go index b5510aa..9fcff37 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -6,11 +6,11 @@ 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" "git.grassecon.net/urdt/ussd/internal/handlers" + "git.grassecon.net/urdt/ussd/internal/handlers/server" "git.grassecon.net/urdt/ussd/internal/storage" testdataloader "github.com/peteole/testdata-loader" ) @@ -21,7 +21,7 @@ var ( scriptDir = path.Join(baseDir, "services", "registration") ) -func TestEngine(sessionId string) (engine.Engine, func(), *db.Db) { +func TestEngine(sessionId string) (engine.Engine, func()) { ctx := context.Background() ctx = context.WithValue(ctx, "SessionId", sessionId) pfp := path.Join(scriptDir, "pp.csv") @@ -76,7 +76,8 @@ func TestEngine(sessionId string) (engine.Engine, func(), *db.Db) { os.Exit(1) } - hl, err := lhs.GetHandler() + mockAccountService := server.MockAccountService{} + hl, err := lhs.GetHandler(&mockAccountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) @@ -99,5 +100,5 @@ func TestEngine(sessionId string) (engine.Engine, func(), *db.Db) { } //en = en.WithDebug(nil) - return en, cleanFn, lhs.UserdataStore + return en, cleanFn } -- 2.45.2 From 617842535515893ecb6e7633264affabfd24c234 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 16:57:25 +0300 Subject: [PATCH 55/65] create a mocked account service --- internal/handlers/server/accountservice.go | 44 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/internal/handlers/server/accountservice.go b/internal/handlers/server/accountservice.go index f4375a1..8783892 100644 --- a/internal/handlers/server/accountservice.go +++ b/internal/handlers/server/accountservice.go @@ -18,7 +18,8 @@ type AccountServiceInterface interface { type AccountService struct { } - +type MockAccountService struct { +} // CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID. // @@ -27,12 +28,10 @@ type AccountService struct { // CreateAccount or a similar function that returns an AccountResponse. The `trackingId` field in the // AccountResponse struct can be used here to check the account status during a transaction. // -// // Returns: // - string: The status of the transaction as a string. If there is an error during the request or processing, this will be an empty string. // - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data. // If no error occurs, this will be nil. -// func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) { resp, err := http.Get(config.TrackStatusURL + trackingId) if err != nil { @@ -56,7 +55,6 @@ func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) return status, nil } - // CheckBalance retrieves the balance for a given public key from the custodial balance API endpoint. // Parameters: // - publicKey: The public key associated with the account whose balance needs to be checked. @@ -83,8 +81,7 @@ func (as *AccountService) CheckBalance(publicKey string) (string, error) { return balance, nil } - -//CreateAccount creates a new account in the custodial system. +// CreateAccount creates a new account in the custodial system. // Returns: // - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account. // If there is an error during the request or processing, this will be nil. @@ -110,3 +107,38 @@ func (as *AccountService) CreateAccount() (*models.AccountResponse, error) { return &accountResp, nil } + +func (mas *MockAccountService) CreateAccount() (*models.AccountResponse, error) { + return &models.AccountResponse{ + Ok: true, + Result: struct { + CustodialId json.Number `json:"custodialId"` + PublicKey string `json:"publicKey"` + TrackingId string `json:"trackingId"` + }{ + CustodialId: json.Number("182"), + PublicKey: "0x48ADca309b5085852207FAaf2816eD72B52F527C", + TrackingId: "28ebe84d-b925-472c-87ae-bbdfa1fb97be", + }, + }, nil +} + +func (mas *MockAccountService) CheckBalance(publicKey string) (string, error) { + + balanceResponse := &models.BalanceResponse{ + Ok: true, + Result: struct { + Balance string `json:"balance"` + Nonce json.Number `json:"nonce"` + }{ + Balance: "0.003 CELO", + Nonce: json.Number("0"), + }, + } + + return balanceResponse.Result.Balance, nil +} + +func (mas *MockAccountService) CheckAccountStatus(trackingId string) (string, error) { + return "SUCCESS", nil +} -- 2.45.2 From 79a127cea990e00831a1e627bc45893d30062340 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 16:58:18 +0300 Subject: [PATCH 56/65] pass account service as a parameter --- internal/handlers/handlerservice.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index 3dffe16..50d2c78 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -6,6 +6,7 @@ import ( "git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/persist" "git.defalsify.org/vise.git/resource" + "git.grassecon.net/urdt/ussd/internal/handlers/server" "git.grassecon.net/urdt/ussd/internal/handlers/ussd" ) @@ -52,8 +53,8 @@ func (ls *LocalHandlerService) SetDataStore(db *db.Db) { ls.UserdataStore = db } -func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) { - ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore) +func (ls *LocalHandlerService) GetHandler(accountService server.AccountServiceInterface) (*ussd.Handlers, error) { + ussdHandlers, err := ussd.NewHandlers(ls.Parser, *ls.UserdataStore, accountService) if err != nil { return nil, err } @@ -93,7 +94,7 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) { ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp) - ls.DbRs.AddLocalFunc("get_vouchers",ussdHandlers.GetVoucherList) + ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList) return ussdHandlers, nil } -- 2.45.2 From f91480f3de724fa107d0acf66fbec8fedf85405d Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 16:58:47 +0300 Subject: [PATCH 57/65] pass account service as a param --- internal/handlers/ussd/menuhandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index f41d955..bc97081 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -61,7 +61,7 @@ type Handlers struct { accountService server.AccountServiceInterface } -func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db) (*Handlers, error) { +func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db, accountService server.AccountServiceInterface) (*Handlers, error) { if userdataStore == nil { return nil, fmt.Errorf("cannot create handler with nil userdata store") } @@ -71,7 +71,7 @@ func NewHandlers(appFlags *asm.FlagParser, userdataStore db.Db) (*Handlers, erro h := &Handlers{ userdataStore: userDb, flagManager: appFlags, - accountService: &server.AccountService{}, + accountService: accountService, } return h, nil } -- 2.45.2 From 86ba03b375728288f2d35cc161d37f424825b141 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 4 Oct 2024 17:04:33 +0300 Subject: [PATCH 58/65] update tests --- test_engine/menu_traversal_test.go | 67 ++++++++++++++++++------------ 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 51d85ec..08cd7a8 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -3,7 +3,9 @@ package main import ( "bytes" "context" - "fmt" + "log" + "math/rand" + "os" "regexp" "testing" "time" @@ -15,16 +17,19 @@ import ( var ( testData = driver.ReadData() + testStore = ".test_state" sessionID string + src = rand.NewSource(42) + g = rand.New(src) ) -// GenerateRandomSessionID generates a random UUID for the sessionID -func GenerateUUID() string { - u, err := uuid.NewV4() +func GenerateSessionId() string { + uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g)) + v, err := uu.NewV4() if err != nil { - return "default_uuid" + panic(err) } - return u.String() + return v.String() } // Extract the public key from the engine response @@ -39,12 +44,18 @@ func extractPublicKey(response []byte) string { } func TestMain(m *testing.M) { - sessionID = GenerateUUID() + sessionID = GenerateSessionId() + testStore = ".test_state" + defer func() { + if err := os.RemoveAll(testStore); err != nil { + log.Fatalf("Failed to delete state store %s: %v", testStore, err) + } + }() m.Run() } func TestAccountCreationSuccessful(t *testing.T) { - en, fn, _ := enginetest.TestEngine(sessionID) + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData @@ -77,8 +88,13 @@ 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) + uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g)) + v, err := uu.NewV4() + if err != nil { + t.Fail() + } + edgeCaseSessionID := v.String() + en, fn := enginetest.TestEngine(edgeCaseSessionID) defer fn() ctx := context.Background() sessions := testData @@ -109,7 +125,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 @@ -147,7 +163,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 @@ -178,7 +194,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 @@ -209,7 +225,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 @@ -240,7 +256,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 @@ -271,7 +287,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 @@ -302,7 +318,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 @@ -333,7 +349,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 @@ -364,7 +380,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 @@ -395,7 +411,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 @@ -417,7 +433,6 @@ 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) } @@ -427,7 +442,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 @@ -458,7 +473,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 @@ -489,7 +504,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 @@ -521,7 +536,7 @@ func TestMyAccount_Edit_offerings(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 @@ -557,7 +572,7 @@ func TestMyAccount_MyAddress(t *testing.T) { } func TestMyAccount_View_Profile(t *testing.T) { - en, fn, _ := enginetest.TestEngine(sessionID) + en, fn := enginetest.TestEngine(sessionID) defer fn() ctx := context.Background() sessions := testData -- 2.45.2 From 2703e6d1dfc3107b540319441bbd67eea0d7956c Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Sat, 5 Oct 2024 21:47:17 +0300 Subject: [PATCH 59/65] add tags to toggle between online and offline tests --- engine/engine.go | 11 ++++++++--- engine/tag_offline.go | 5 +++++ engine/tag_online.go | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 engine/tag_offline.go create mode 100644 engine/tag_online.go diff --git a/engine/engine.go b/engine/engine.go index 9fcff37..f597173 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -1,4 +1,4 @@ -package enginetest +package engine import ( "context" @@ -22,6 +22,7 @@ var ( ) func TestEngine(sessionId string) (engine.Engine, func()) { + var accountService server.AccountServiceInterface ctx := context.Background() ctx = context.WithValue(ctx, "SessionId", sessionId) pfp := path.Join(scriptDir, "pp.csv") @@ -76,8 +77,12 @@ func TestEngine(sessionId string) (engine.Engine, func()) { os.Exit(1) } - mockAccountService := server.MockAccountService{} - hl, err := lhs.GetHandler(&mockAccountService) + if OnlineTestEnabled { + accountService = &server.AccountService{} + } else { + accountService = &server.MockAccountService{} + } + hl, err := lhs.GetHandler(accountService) if err != nil { fmt.Fprintf(os.Stderr, err.Error()) os.Exit(1) diff --git a/engine/tag_offline.go b/engine/tag_offline.go new file mode 100644 index 0000000..d81433e --- /dev/null +++ b/engine/tag_offline.go @@ -0,0 +1,5 @@ +// +build !online + +package engine + +const OnlineTestEnabled = false \ No newline at end of file diff --git a/engine/tag_online.go b/engine/tag_online.go new file mode 100644 index 0000000..a2ba80b --- /dev/null +++ b/engine/tag_online.go @@ -0,0 +1,5 @@ +// +build online + +package engine + +const OnlineTestEnabled = true \ No newline at end of file -- 2.45.2 From 0a92444ae8c83c15ed4abd6fdd3e325a4a0d01dd Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Oct 2024 16:41:45 +0300 Subject: [PATCH 60/65] add group tests --- test_engine/menu_traversal_test.go | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 08cd7a8..20f91e9 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "fmt" "log" "math/rand" "os" @@ -45,10 +46,11 @@ func extractPublicKey(response []byte) string { func TestMain(m *testing.M) { sessionID = GenerateSessionId() - testStore = ".test_state" defer func() { if err := os.RemoveAll(testStore); err != nil { log.Fatalf("Failed to delete state store %s: %v", testStore, err) + } else { + fmt.Println("After running test") } }() m.Run() @@ -601,3 +603,38 @@ func TestMyAccount_View_Profile(t *testing.T) { } } } + +func TestGroup(t *testing.T) { + // Load sessions from JSON file + filePath := "group_test.json" + sessions, err := driver.LoadTestGroups(filePath) + if err != nil { + log.Fatalf("Failed to load test groups: %v", err) + } + en, fn := enginetest.TestEngine(sessionID) + defer fn() + ctx := context.Background() + // Create test cases from loaded groups + tests := driver.CreateTestCases(sessions) + for _, tt := range tests { + t.Run(tt.Name, func(t *testing.T) { + cont, err := en.Exec(ctx, []byte(tt.Input)) + if err != nil { + t.Errorf("Test case '%s' failed at input '%s': %v", tt.Name, tt.Input, err) + return + } + if !cont { + return + } + w := bytes.NewBuffer(nil) + if _, err := en.Flush(ctx, w); err != nil { + t.Errorf("Test case '%s' failed during Flush: %v", tt.Name, err) + } + b := w.Bytes() + if !bytes.Equal(b, []byte(tt.ExpectedContent)) { + t.Fatalf("expected:\n\t%s\ngot:\n\t%s\n", tt.ExpectedContent, b) + } + + }) + } +} -- 2.45.2 From 2ffe749c9d4ced46b0d8d6e23421c5702f8cbc35 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Oct 2024 16:42:48 +0300 Subject: [PATCH 61/65] add driver to group tests --- driver/groupdriver.go | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 driver/groupdriver.go diff --git a/driver/groupdriver.go b/driver/groupdriver.go new file mode 100644 index 0000000..f20d755 --- /dev/null +++ b/driver/groupdriver.go @@ -0,0 +1,60 @@ +package driver + +import ( + "encoding/json" + "os" +) + +type StepTest struct { + Input string `json:"input"` + ExpectedContent string `json:"expectedContent"` +} + +// Group represents a group of steps. +type GroupTest struct { + Name string `json:"name"` + Steps []Step `json:"steps"` +} + +// DataGroup represents the overall structure of the JSON. +type DataGroup struct { + Groups []Group `json:"groups"` +} + +func LoadTestGroups(filePath string) (DataGroup, error) { + var sessionsData DataGroup + data, err := os.ReadFile(filePath) + if err != nil { + return sessionsData, err + } + err = json.Unmarshal(data, &sessionsData) + return sessionsData, err +} + +func CreateTestCases(group DataGroup) []struct { + Name string + Input string + ExpectedContent string +} { + var tests []struct { + Name string + Input string + ExpectedContent string + } + for _, group := range group.Groups { + for _, step := range group.Steps { + // Create a test case for each group + tests = append(tests, struct { + Name string + Input string + ExpectedContent string + }{ + Name: group.Name, + Input: step.Input, + ExpectedContent: step.ExpectedContent, + }) + } + } + + return tests +} -- 2.45.2 From bb009fa1e2e4d51e2ddb0309ea3ed5e5f8095032 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Oct 2024 16:43:13 +0300 Subject: [PATCH 62/65] add group test cases --- test_engine/group_test.json | 332 ++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 test_engine/group_test.json diff --git a/test_engine/group_test.json b/test_engine/group_test.json new file mode 100644 index 0000000..bc6760b --- /dev/null +++ b/test_engine/group_test.json @@ -0,0 +1,332 @@ +{ + "groups": [ + { + "name": "my_account_change_pin", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "5", + "expectedContent": "PIN Management\n1:Change PIN\n2:Reset other's PIN\n3:Guard my PIN\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your old PIN\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Enter a new four number PIN:\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Confirm your new PIN:\n0:Back" + }, + { + "input": "1234", + "expectedContent": "Your PIN change request has been successful\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_language_change", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Select language:\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Your language change request was successful.\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_edit_familyname", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "2", + "expectedContent": "Enter family name:\n0:Back" + }, + { + "input": "bar", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + + ] + }, + { + "name": "menu_my_account_edit_gender", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "3", + "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_edit_yob", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "4", + "expectedContent": "Enter your year of birth\n0:Back" + }, + { + "input": "1945", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_edit_location", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "5", + "expectedContent": "Enter your location:\n0:Back" + }, + { + "input": "Kilifi", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_edit_offerings", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "6", + "expectedContent": "Enter the services or goods you offer: \n0:Back" + }, + { + "input": "Bananas", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, + { + "name": "menu_my_account_view_profile", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "7", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + } + + ] +} + + + + + + -- 2.45.2 From 0d18eec39fccf5671bec85e253a5df9f737e8ab9 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Oct 2024 16:55:07 +0300 Subject: [PATCH 63/65] remove debug message --- test_engine/menu_traversal_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 20f91e9..48a91e8 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "context" - "fmt" "log" "math/rand" "os" @@ -49,8 +48,6 @@ func TestMain(m *testing.M) { defer func() { if err := os.RemoveAll(testStore); err != nil { log.Fatalf("Failed to delete state store %s: %v", testStore, err) - } else { - fmt.Println("After running test") } }() m.Run() -- 2.45.2 From 4cd7c742ef71fd1a138698b3ff8580016c217b11 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Oct 2024 18:36:34 +0300 Subject: [PATCH 64/65] factor out tested groups --- test_engine/group_test.json | 46 ++++- test_engine/menu_traversal_test.go | 297 +---------------------------- 2 files changed, 50 insertions(+), 293 deletions(-) diff --git a/test_engine/group_test.json b/test_engine/group_test.json index bc6760b..02f2628 100644 --- a/test_engine/group_test.json +++ b/test_engine/group_test.json @@ -74,6 +74,47 @@ } ] }, + { + "name": "menu_my_account_edit_firstname", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "1", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "1", + "expectedContent": "Enter your first names:\n0:Back" + }, + { + "input": "foo", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" + }, + { + "input": "0", + "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" + }, + { + "input": "0", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "0", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + } + ] + }, { "name": "menu_my_account_edit_familyname", "steps": [ @@ -314,14 +355,9 @@ { "input": "0", "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" } ] } - ] } diff --git a/test_engine/menu_traversal_test.go b/test_engine/menu_traversal_test.go index 48a91e8..2246d85 100644 --- a/test_engine/menu_traversal_test.go +++ b/test_engine/menu_traversal_test.go @@ -16,11 +16,12 @@ import ( ) var ( - testData = driver.ReadData() - testStore = ".test_state" - sessionID string - src = rand.NewSource(42) - g = rand.New(src) + testData = driver.ReadData() + testStore = ".test_state" + groupTestFile = "group_test.json" + sessionID string + src = rand.NewSource(42) + g = rand.New(src) ) func GenerateSessionId() string { @@ -285,254 +286,7 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) { } } -func TestMyAccountChangePin(t *testing.T) { - en, fn := enginetest.TestEngine(sessionID) - defer fn() - ctx := context.Background() - sessions := testData - for _, session := range sessions { - groups := driver.FilterGroupsByName(session.Groups, "my_account_change_pin") - for _, group := range groups { - for _, step := range group.Steps { - cont, err := en.Exec(ctx, []byte(step.Input)) - if err != nil { - t.Fatalf("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.Fatalf("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_Change_Language(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_language_change") - 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_Edit_firstname(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_edit_firstname") - 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_Edit_familyname(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_edit_familyname") - 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_Edit_gender(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_edit_gender") - 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_Edit_yob(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_edit_yob") - 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_Edit_location(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_edit_location") - 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_Edit_offerings(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_edit_offerings") - 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_MyAddress(t *testing.T) { en, fn := enginetest.TestEngine(sessionID) @@ -570,41 +324,8 @@ 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) - } - } - } - } -} - -func TestGroup(t *testing.T) { - // Load sessions from JSON file - filePath := "group_test.json" - sessions, err := driver.LoadTestGroups(filePath) +func TestGroups(t *testing.T) { + groups, err := driver.LoadTestGroups(groupTestFile) if err != nil { log.Fatalf("Failed to load test groups: %v", err) } @@ -612,7 +333,7 @@ func TestGroup(t *testing.T) { defer fn() ctx := context.Background() // Create test cases from loaded groups - tests := driver.CreateTestCases(sessions) + tests := driver.CreateTestCases(groups) for _, tt := range tests { t.Run(tt.Name, func(t *testing.T) { cont, err := en.Exec(ctx, []byte(tt.Input)) -- 2.45.2 From 992dd0bd54322c8cf00c9c994404d059894b9316 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Oct 2024 19:05:36 +0300 Subject: [PATCH 65/65] factor out setup test --- driver/testdata.go | 2 +- test_engine/test_data.json | 536 ------------------------------------ test_engine/test_setup.json | 219 +++++++++++++++ 3 files changed, 220 insertions(+), 537 deletions(-) delete mode 100644 test_engine/test_data.json create mode 100644 test_engine/test_setup.json diff --git a/driver/testdata.go b/driver/testdata.go index 9603c00..673d417 100644 --- a/driver/testdata.go +++ b/driver/testdata.go @@ -22,7 +22,7 @@ type Session struct { } func ReadData() []Session { - data, err := os.ReadFile("test_data.json") + data, err := os.ReadFile("test_setup.json") if err != nil { log.Fatalf("Failed to read file: %v", err) } diff --git a/test_engine/test_data.json b/test_engine/test_data.json deleted file mode 100644 index 4af08e9..0000000 --- a/test_engine/test_data.json +++ /dev/null @@ -1,536 +0,0 @@ -[ - { - "name": "session one", - "groups": [ - { - "name": "account_creation_successful", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "0", - "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" - }, - { - "input": "1234", - "expectedContent": "Enter your four number PIN again:" - }, - { - "input": "1111", - "expectedContent": "The PIN is not a match. Try again\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Enter your four number PIN again:" - }, - { - "input": "1234", - "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "account_creation_reject_terms", - "steps": [ - { - "input": "", - "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" - }, - { - "input": "1", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "send_with_invalid_inputs", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Enter recipient's phone number:\n0:Back" - }, - { - "input": "000", - "expectedContent": "000 is not registered or invalid, please try again:\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Enter recipient's phone number:\n0:Back" - }, - { - "input": "065656", - "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" - }, - { - "input": "0.1", - "expectedContent": "Amount 0.1 is invalid, please try again:\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" - }, - { - "input": "0.001", - "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" - }, - { - "input": "1222", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" - }, - { - "input": "1234", - "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." - } - ] - }, - { - "name": "main_menu_help", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "4", - "expectedContent": "For more help,please call: 0757628885" - } - ] - }, - { - "name": "main_menu_quit", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "my_account_change_pin", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "5", - "expectedContent": "PIN Management\n1:Change PIN\n2:Reset other's PIN\n3:Guard my PIN\n0:Back" - }, - { - "input": "1", - "expectedContent": "Enter your old PIN\n0:Back" - }, - { - "input": "1234", - "expectedContent": "Enter a new four number PIN:\n0:Back" - }, - { - "input": "1234", - "expectedContent": "Confirm your new PIN:\n0:Back" - }, - { - "input": "1234", - "expectedContent": "Your PIN change request has been successful\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_language_change", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Select language:\n0:english\n1:kiswahili" - }, - { - "input": "0", - "expectedContent": "Your language change request was successful.\n0:Back\n9:Quit" - }, - { - "input": "0", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_firstname", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "1", - "expectedContent": "Enter your first names:\n0:Back" - }, - { - "input": "foo", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_familyname", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "2", - "expectedContent": "Enter family name:\n0:Back" - }, - { - "input": "bar", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_gender", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "3", - "expectedContent": "Select gender: \n1:Male\n2:Female\n3:Unspecified\n0:Back" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_yob", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "4", - "expectedContent": "Enter your year of birth\n0:Back" - }, - { - "input": "1945", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_location", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "5", - "expectedContent": "Enter your location:\n0:Back" - }, - { - "input": "Kilifi", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_edit_offerings", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "6", - "expectedContent": "Enter the services or goods you offer: \n0:Back" - }, - { - "input": "Bananas", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Profile updated successfully\n0:Back\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!{{.Variable}}" - } - ] - }, - { - "name": "menu_my_account_view_profile", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "1", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "7", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 79\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back" - }, - { - "input": "0", - "expectedContent": "My profile\n1:Edit name\n2:Edit family name\n3:Edit gender\n4:Edit year of birth\n5:Edit location\n6:Edit offerings\n7:View profile\n0:Back" - }, - { - "input": "0", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "0", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - }, - { - "name": "menu_my_account_check_my_balance", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" - } - ] - }, - { - "name": "menu_my_account_check_community_balance", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "3", - "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" - }, - { - "input": "2", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1235", - "expectedContent": "Incorrect pin\n1:retry\n9:Quit" - }, - { - "input": "1", - "expectedContent": "Please enter your PIN:" - }, - { - "input": "1234", - "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" - } - ] - }, - { - "name": "menu_my_account_my_address", - "steps": [ - { - "input": "", - "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" - }, - { - "input": "3", - "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" - }, - { - "input": "6", - "expectedContent": "Address: {public_key}\n9:Quit" - }, - { - "input": "9", - "expectedContent": "Thank you for using Sarafu. Goodbye!" - } - ] - } - ] - } -] \ No newline at end of file diff --git a/test_engine/test_setup.json b/test_engine/test_setup.json new file mode 100644 index 0000000..6793391 --- /dev/null +++ b/test_engine/test_setup.json @@ -0,0 +1,219 @@ +[ + { + "name": "session one", + "groups": [ + { + "name": "account_creation_successful", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "0", + "expectedContent": "Please enter a new four number PIN for your account:\n0:Exit" + }, + { + "input": "1234", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1111", + "expectedContent": "The PIN is not a match. Try again\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter your four number PIN again:" + }, + { + "input": "1234", + "expectedContent": "Your account is being created...Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "account_creation_reject_terms", + "steps": [ + { + "input": "", + "expectedContent": "Welcome to Sarafu Network\nPlease select a language\n0:english\n1:kiswahili" + }, + { + "input": "0", + "expectedContent": "Do you agree to terms and conditions?\n0:yes\n1:no" + }, + { + "input": "1", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "send_with_invalid_inputs", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter recipient's phone number:\n0:Back" + }, + { + "input": "000", + "expectedContent": "000 is not registered or invalid, please try again:\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Enter recipient's phone number:\n0:Back" + }, + { + "input": "065656", + "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" + }, + { + "input": "0.1", + "expectedContent": "Amount 0.1 is invalid, please try again:\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Maximum amount: 0.003 CELO\nEnter amount:\n0:Back" + }, + { + "input": "0.001", + "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + }, + { + "input": "1222", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "065656 will receive 0.001 from {public_key}\nPlease enter your PIN to confirm:\n0:Back\n9:Quit" + }, + { + "input": "1234", + "expectedContent": "Your request has been sent. 065656 will receive 0.001 from {public_key}." + } + ] + }, + { + "name": "main_menu_help", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "4", + "expectedContent": "For more help,please call: 0757628885" + } + ] + }, + { + "name": "main_menu_quit", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + }, + { + "name": "menu_my_account_check_my_balance", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" + } + ] + }, + { + "name": "menu_my_account_check_community_balance", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "3", + "expectedContent": "Balances:\n1:My balance\n2:Community balance\n0:Back" + }, + { + "input": "2", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1235", + "expectedContent": "Incorrect pin\n1:retry\n9:Quit" + }, + { + "input": "1", + "expectedContent": "Please enter your PIN:" + }, + { + "input": "1234", + "expectedContent": "Your balance is: 0.00 SRFYour account balance is 0.003 CELO" + } + ] + }, + { + "name": "menu_my_account_my_address", + "steps": [ + { + "input": "", + "expectedContent": "Balance: 0.003 CELO\n\n1:Send\n2:My Vouchers\n3:My Account\n4:Help\n9:Quit" + }, + { + "input": "3", + "expectedContent": "My Account\n1:Profile\n2:Change language\n3:Check balances\n4:Check statement\n5:PIN options\n6:My Address\n0:Back" + }, + { + "input": "6", + "expectedContent": "Address: {public_key}\n9:Quit" + }, + { + "input": "9", + "expectedContent": "Thank you for using Sarafu. Goodbye!" + } + ] + } + ] + } +] \ No newline at end of file -- 2.45.2