update test
This commit is contained in:
parent
f2b17880ba
commit
01e75e9217
@ -2,7 +2,6 @@ package ussd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path"
|
"path"
|
||||||
@ -1773,58 +1772,43 @@ func TestConfirmPin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFetchCustodialBalances(t *testing.T) {
|
func TestFetchCommunityBalance(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
|
||||||
balanceResponse *models.BalanceResult
|
languageCode string
|
||||||
expectedResult resource.Result
|
expectedResult resource.Result
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test when fetch custodial balances is not a success",
|
name: "Test community balance content when language is english",
|
||||||
balanceResponse: &models.BalanceResult{
|
|
||||||
Balance: "0.003 CELO",
|
|
||||||
Nonce: json.Number("0"),
|
|
||||||
},
|
|
||||||
expectedResult: resource.Result{
|
expectedResult: resource.Result{
|
||||||
FlagReset: []uint32{flag_api_error},
|
Content: "Community Balance: 0.00",
|
||||||
},
|
},
|
||||||
|
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)
|
||||||
// Set up the expected behavior of the mock
|
ctx = context.WithValue(ctx, "Language", lang.Language{
|
||||||
mockAccountService.On("CheckBalance", string(publicKey)).Return(tt.balanceResponse, nil)
|
Code: tt.languageCode,
|
||||||
|
})
|
||||||
|
|
||||||
// Call the method
|
// 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 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")
|
||||||
|
Loading…
Reference in New Issue
Block a user