From 94bf4ffaa6690307bcb9015e1afacdc9d51fee47 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Wed, 2 Oct 2024 14:28:21 +0300 Subject: [PATCH] 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!" + } ] }, {