From 10abad9e5911171aeb62ad7b4c9137073fca22f1 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Fri, 13 Sep 2024 18:00:50 +0300 Subject: [PATCH] add test for quit with help --- internal/handlers/ussd/menuhandler_test.go | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index e091bb9..0a87451 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -1378,6 +1378,61 @@ func TestQuit(t *testing.T) { }) } } + +func TestQuitWithHelp(t *testing.T) { + fm, err := NewFlagManager(flagsPath) + + if err != nil { + t.Logf(err.Error()) + } + flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized") + + mockDataStore := new(mocks.MockUserDataStore) + mockCreateAccountService := new(mocks.MockAccountService) + + sessionId := "session123" + + ctx := context.WithValue(context.Background(), "SessionId", sessionId) + + h := &Handlers{ + userdataStore: mockDataStore, + accountService: mockCreateAccountService, + flagManager: fm.parser, + } + tests := []struct { + name string + input []byte + status string + expectedResult resource.Result + }{ + { + name: "Test quit with help message", + expectedResult: resource.Result{ + FlagReset: []uint32{flag_account_authorized}, + Content: "For more help,please call: 0757628885", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + // Call the method under test + res, _ := h.QuitWithHelp(ctx, "test_quit with help", tt.input) + + // Assert that no errors occurred + assert.NoError(t, err) + + //Assert that the account created flag has been set to the result + assert.Equal(t, res, tt.expectedResult, "Expected result should be equal to the actual result") + + // Assert that expectations were met + mockDataStore.AssertExpectations(t) + + }) + } +} + func TestIsValidPIN(t *testing.T) { tests := []struct { name string