From e1506a3dcf0ac6fa0e21494ea22b3e0648133754 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 18 Nov 2024 17:20:12 +0300 Subject: [PATCH 1/7] show a placehlolder community balance --- internal/handlers/ussd/menuhandler.go | 42 +++++---------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index f2d3173..d8e6fa0 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -822,42 +822,14 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) ( return res, nil } -func (h *Handlers) FetchCustodialBalances(ctx context.Context, sym string, input []byte) (resource.Result, error) { +func (h *Handlers) FetchCommunityBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result - - flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") - - sessionId, ok := ctx.Value("SessionId").(string) - if !ok { - return res, fmt.Errorf("missing session") - } - symbol, _ := h.st.Where() - balanceType := strings.Split(symbol, "_")[0] - - store := h.userdataStore - publicKey, err := store.ReadEntry(ctx, sessionId, common.DATA_PUBLIC_KEY) - if err != nil { - logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", common.DATA_PUBLIC_KEY, "error", err) - return res, err - } - - balanceResponse, err := h.accountService.CheckBalance(ctx, string(publicKey)) - if err != nil { - res.FlagSet = append(res.FlagSet, flag_api_error) - return res, nil - } - res.FlagReset = append(res.FlagReset, flag_api_error) - - balance := balanceResponse.Balance - - switch balanceType { - case "my": - res.Content = fmt.Sprintf("Your balance is %s", balance) - case "community": - res.Content = fmt.Sprintf("Your community balance is %s", balance) - default: - break - } + code := codeFromCtx(ctx) + l := gotext.NewLocale(translationDir, code) + l.AddDomain("default") + //TODO: + //Check if the address is a community account,if then,get the actual balance + res.Content = l.Get("Community Balance: 0.00") return res, nil } From 454f67b3177bce34cbd6448b2ef3263c645eec76 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 18 Nov 2024 17:21:04 +0300 Subject: [PATCH 2/7] show balance based on current voucher --- services/registration/my_balance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/registration/my_balance b/services/registration/my_balance index f8f8318..afae8c1 100644 --- a/services/registration/my_balance +++ b/services/registration/my_balance @@ -1 +1 @@ -{{.fetch_custodial_balances}} \ No newline at end of file +{{.check_balance}} \ No newline at end of file From 44c52b6ed717f619d0912fd60f90653fed4a6782 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 18 Nov 2024 17:23:36 +0300 Subject: [PATCH 3/7] rename fetch_custodial_balances -> fetch_community_balance --- internal/handlers/handlerservice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/handlers/handlerservice.go b/internal/handlers/handlerservice.go index e0cad8f..fe88c1f 100644 --- a/internal/handlers/handlerservice.go +++ b/internal/handlers/handlerservice.go @@ -103,7 +103,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn 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("fetch_custodial_balances", ussdHandlers.FetchCustodialBalances) + ls.DbRs.AddLocalFunc("fetch_community_balance", ussdHandlers.FetchCommunityBalance) ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher) ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers) ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList) From 1d4f11607963437e46fa9145c22f17340193e679 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 18 Nov 2024 17:23:59 +0300 Subject: [PATCH 4/7] community balance str --- services/registration/locale/swa/default.po | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/registration/locale/swa/default.po b/services/registration/locale/swa/default.po index f933dde..aa033b5 100644 --- a/services/registration/locale/swa/default.po +++ b/services/registration/locale/swa/default.po @@ -21,3 +21,6 @@ msgstr "Ombi lako la kumwalika %s kwa matandao wa Sarafu limetumwa." msgid "Your request failed. Please try again later." msgstr "Ombi lako halikufaulu. Tafadhali jaribu tena baadaye." + +msgid "Community Balance: 0.00" +msgid "Salio la Kikundi: 0.00" From f2b17880bab2f45d4a4b9b03b8f25e1905c933ee Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 18 Nov 2024 17:30:09 +0300 Subject: [PATCH 5/7] check community and my balance separately --- services/registration/comminity_balance_swa | 2 +- services/registration/community_balance | 2 +- services/registration/community_balance.vis | 4 ++-- services/registration/my_balance.vis | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/registration/comminity_balance_swa b/services/registration/comminity_balance_swa index 726fc99..d9f1d6e 100644 --- a/services/registration/comminity_balance_swa +++ b/services/registration/comminity_balance_swa @@ -1 +1 @@ -Salio la kikundi \ No newline at end of file +{{.fetch_community_balance}} \ No newline at end of file diff --git a/services/registration/community_balance b/services/registration/community_balance index f8f8318..d9f1d6e 100644 --- a/services/registration/community_balance +++ b/services/registration/community_balance @@ -1 +1 @@ -{{.fetch_custodial_balances}} \ No newline at end of file +{{.fetch_community_balance}} \ No newline at end of file diff --git a/services/registration/community_balance.vis b/services/registration/community_balance.vis index 85ae93a..f3e0ae1 100644 --- a/services/registration/community_balance.vis +++ b/services/registration/community_balance.vis @@ -1,7 +1,7 @@ LOAD reset_incorrect 6 -LOAD fetch_custodial_balances 0 +LOAD fetch_community_balance 0 CATCH api_failure flag_api_call_error 1 -MAP fetch_custodial_balances +MAP fetch_community_balance CATCH incorrect_pin flag_incorrect_pin 1 CATCH pin_entry flag_account_authorized 0 MOUT back 0 diff --git a/services/registration/my_balance.vis b/services/registration/my_balance.vis index 85ae93a..9144da9 100644 --- a/services/registration/my_balance.vis +++ b/services/registration/my_balance.vis @@ -1,7 +1,7 @@ LOAD reset_incorrect 6 -LOAD fetch_custodial_balances 0 +LOAD check_balance 0 CATCH api_failure flag_api_call_error 1 -MAP fetch_custodial_balances +MAP check_balance CATCH incorrect_pin flag_incorrect_pin 1 CATCH pin_entry flag_account_authorized 0 MOUT back 0 From 01e75e92170cb26b81dbadd31fd2057f105972e6 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 18 Nov 2024 17:30:34 +0300 Subject: [PATCH 6/7] update test --- internal/handlers/ussd/menuhandler_test.go | 42 +++++++--------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index ff6f0ad..51693df 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -2,7 +2,6 @@ package ussd import ( "context" - "encoding/json" "fmt" "log" "path" @@ -1773,58 +1772,43 @@ func TestConfirmPin(t *testing.T) { } } -func TestFetchCustodialBalances(t *testing.T) { - fm, err := NewFlagManager(flagsPath) - if err != nil { - t.Logf(err.Error()) - } - flag_api_error, _ := fm.GetFlag("flag_api_call_error") +func TestFetchCommunityBalance(t *testing.T) { // Define test data sessionId := "session123" - publicKey := "0X13242618721" - ctx, store := InitializeTestStore(t) - ctx = context.WithValue(ctx, "SessionId", sessionId) - - err = store.WriteEntry(ctx, sessionId, common.DATA_PUBLIC_KEY, []byte(publicKey)) - if err != nil { - t.Fatal(err) - } tests := []struct { - name string - balanceResponse *models.BalanceResult - expectedResult resource.Result + name string + languageCode string + expectedResult resource.Result }{ { - name: "Test when fetch custodial balances is not a success", - balanceResponse: &models.BalanceResult{ - Balance: "0.003 CELO", - Nonce: json.Number("0"), - }, + name: "Test community balance content when language is english", expectedResult: resource.Result{ - FlagReset: []uint32{flag_api_error}, + Content: "Community Balance: 0.00", }, + languageCode: "eng", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + mockAccountService := new(mocks.MockAccountService) mockState := state.NewState(16) h := &Handlers{ userdataStore: store, - flagManager: fm.parser, st: mockState, accountService: mockAccountService, } - - // Set up the expected behavior of the mock - mockAccountService.On("CheckBalance", string(publicKey)).Return(tt.balanceResponse, nil) + ctx = context.WithValue(ctx, "SessionId", sessionId) + ctx = context.WithValue(ctx, "Language", lang.Language{ + Code: tt.languageCode, + }) // Call the method - res, _ := h.FetchCustodialBalances(ctx, "fetch_custodial_balances", []byte("")) + res, _ := h.FetchCommunityBalance(ctx, "fetch_community_balance", []byte("")) //Assert that the result set to content is what was expected assert.Equal(t, res, tt.expectedResult, "Result should match expected result") From bc6d8098f3cc25b69d920b62663f1b72bdf251f8 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 19 Nov 2024 10:15:34 +0300 Subject: [PATCH 7/7] updated the failed test --- menutraversal_test/group_test.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index 449c42f..52fab59 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -103,7 +103,7 @@ }, { "input": "1234", - "expectedContent": "Your balance is 0.003 CELO\n0:Back\n9:Quit" + "expectedContent": "Balance: {balance}\n\n0:Back\n9:Quit" }, { "input": "0", @@ -149,7 +149,7 @@ }, { "input": "1234", - "expectedContent": "Your community balance is 0.003 CELO\n0:Back\n9:Quit" + "expectedContent": "{balance}\n0:Back\n9:Quit" }, { "input": "0",