From be165e50337dc5ed52237992f8c165c54d76a11d Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 30 Sep 2024 16:05:14 +0300 Subject: [PATCH] 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!" + } + ] } ]