Compare commits
No commits in common. "01e75e92170cb26b81dbadd31fd2057f105972e6" and "b22a4adec15bb1e3667799be0b50e48800b0a1b1" have entirely different histories.
01e75e9217
...
b22a4adec1
@ -103,7 +103,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn
|
|||||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||||
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||||
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
||||||
ls.DbRs.AddLocalFunc("fetch_community_balance", ussdHandlers.FetchCommunityBalance)
|
ls.DbRs.AddLocalFunc("fetch_custodial_balances", ussdHandlers.FetchCustodialBalances)
|
||||||
ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher)
|
ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher)
|
||||||
ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers)
|
ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers)
|
||||||
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
||||||
|
@ -822,14 +822,42 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handlers) FetchCommunityBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *Handlers) FetchCustodialBalances(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
code := codeFromCtx(ctx)
|
|
||||||
l := gotext.NewLocale(translationDir, code)
|
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
l.AddDomain("default")
|
|
||||||
//TODO:
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
//Check if the address is a community account,if then,get the actual balance
|
if !ok {
|
||||||
res.Content = l.Get("Community Balance: 0.00")
|
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
|
||||||
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package ussd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
@ -1772,43 +1773,58 @@ func TestConfirmPin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchCommunityBalance(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")
|
||||||
|
|
||||||
// Define test data
|
// Define test data
|
||||||
sessionId := "session123"
|
sessionId := "session123"
|
||||||
|
publicKey := "0X13242618721"
|
||||||
|
|
||||||
ctx, store := InitializeTestStore(t)
|
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 {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
languageCode string
|
balanceResponse *models.BalanceResult
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test community balance content when language is english",
|
name: "Test when fetch custodial balances is not a success",
|
||||||
expectedResult: resource.Result{
|
balanceResponse: &models.BalanceResult{
|
||||||
Content: "Community Balance: 0.00",
|
Balance: "0.003 CELO",
|
||||||
|
Nonce: json.Number("0"),
|
||||||
|
},
|
||||||
|
expectedResult: resource.Result{
|
||||||
|
FlagReset: []uint32{flag_api_error},
|
||||||
},
|
},
|
||||||
languageCode: "eng",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
mockAccountService := new(mocks.MockAccountService)
|
mockAccountService := new(mocks.MockAccountService)
|
||||||
mockState := state.NewState(16)
|
mockState := state.NewState(16)
|
||||||
|
|
||||||
h := &Handlers{
|
h := &Handlers{
|
||||||
userdataStore: store,
|
userdataStore: store,
|
||||||
|
flagManager: fm.parser,
|
||||||
st: mockState,
|
st: mockState,
|
||||||
accountService: mockAccountService,
|
accountService: mockAccountService,
|
||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
|
||||||
ctx = context.WithValue(ctx, "Language", lang.Language{
|
// Set up the expected behavior of the mock
|
||||||
Code: tt.languageCode,
|
mockAccountService.On("CheckBalance", string(publicKey)).Return(tt.balanceResponse, nil)
|
||||||
})
|
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
res, _ := h.FetchCommunityBalance(ctx, "fetch_community_balance", []byte(""))
|
res, _ := h.FetchCustodialBalances(ctx, "fetch_custodial_balances", []byte(""))
|
||||||
|
|
||||||
//Assert that the result set to content is what was expected
|
//Assert that the result set to content is what was expected
|
||||||
assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
|
assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
|
||||||
|
@ -1 +1 @@
|
|||||||
{{.fetch_community_balance}}
|
Salio la kikundi
|
@ -1 +1 @@
|
|||||||
{{.fetch_community_balance}}
|
{{.fetch_custodial_balances}}
|
@ -1,7 +1,7 @@
|
|||||||
LOAD reset_incorrect 6
|
LOAD reset_incorrect 6
|
||||||
LOAD fetch_community_balance 0
|
LOAD fetch_custodial_balances 0
|
||||||
CATCH api_failure flag_api_call_error 1
|
CATCH api_failure flag_api_call_error 1
|
||||||
MAP fetch_community_balance
|
MAP fetch_custodial_balances
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
CATCH pin_entry flag_account_authorized 0
|
CATCH pin_entry flag_account_authorized 0
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
|
@ -21,6 +21,3 @@ msgstr "Ombi lako la kumwalika %s kwa matandao wa Sarafu limetumwa."
|
|||||||
|
|
||||||
msgid "Your request failed. Please try again later."
|
msgid "Your request failed. Please try again later."
|
||||||
msgstr "Ombi lako halikufaulu. Tafadhali jaribu tena baadaye."
|
msgstr "Ombi lako halikufaulu. Tafadhali jaribu tena baadaye."
|
||||||
|
|
||||||
msgid "Community Balance: 0.00"
|
|
||||||
msgid "Salio la Kikundi: 0.00"
|
|
||||||
|
@ -1 +1 @@
|
|||||||
{{.check_balance}}
|
{{.fetch_custodial_balances}}
|
@ -1,7 +1,7 @@
|
|||||||
LOAD reset_incorrect 6
|
LOAD reset_incorrect 6
|
||||||
LOAD check_balance 0
|
LOAD fetch_custodial_balances 0
|
||||||
CATCH api_failure flag_api_call_error 1
|
CATCH api_failure flag_api_call_error 1
|
||||||
MAP check_balance
|
MAP fetch_custodial_balances
|
||||||
CATCH incorrect_pin flag_incorrect_pin 1
|
CATCH incorrect_pin flag_incorrect_pin 1
|
||||||
CATCH pin_entry flag_account_authorized 0
|
CATCH pin_entry flag_account_authorized 0
|
||||||
MOUT back 0
|
MOUT back 0
|
||||||
|
Loading…
Reference in New Issue
Block a user