fix failing test

This commit is contained in:
Carlosokumu 2025-04-01 12:38:57 +03:00
parent a7e8c184f5
commit 0458ac9498
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -201,6 +201,8 @@ func TestCreateAccount(t *testing.T) {
} }
flag_account_created, err := fm.GetFlag("flag_account_created") flag_account_created, err := fm.GetFlag("flag_account_created")
flag_account_creation_failed, _ := fm.GetFlag("flag_account_creation_failed")
if err != nil { if err != nil {
t.Logf(err.Error()) t.Logf(err.Error())
} }
@ -218,6 +220,7 @@ func TestCreateAccount(t *testing.T) {
}, },
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{flag_account_created}, FlagSet: []uint32{flag_account_created},
FlagReset: []uint32{flag_account_creation_failed},
}, },
}, },
} }
@ -2000,6 +2003,11 @@ func TestSetDefaultVoucher(t *testing.T) {
t.Logf(err.Error()) t.Logf(err.Error())
} }
flag_no_active_voucher, err := fm.GetFlag("flag_no_active_voucher") flag_no_active_voucher, err := fm.GetFlag("flag_no_active_voucher")
if err != nil {
t.Logf(err.Error())
}
flag_api_error, err := fm.GetFlag("flag_api_call_error")
if err != nil { if err != nil {
t.Logf(err.Error()) t.Logf(err.Error())
} }
@ -2016,6 +2024,7 @@ func TestSetDefaultVoucher(t *testing.T) {
vouchersResp: []dataserviceapi.TokenHoldings{}, vouchersResp: []dataserviceapi.TokenHoldings{},
expectedResult: resource.Result{ expectedResult: resource.Result{
FlagSet: []uint32{flag_no_active_voucher}, FlagSet: []uint32{flag_no_active_voucher},
FlagReset: []uint32{flag_api_error},
}, },
}, },
{ {
@ -2028,7 +2037,9 @@ func TestSetDefaultVoucher(t *testing.T) {
Balance: "100", Balance: "100",
}, },
}, },
expectedResult: resource.Result{}, expectedResult: resource.Result{
FlagReset: []uint32{flag_api_error},
},
}, },
} }
@ -2068,12 +2079,18 @@ func TestCheckVouchers(t *testing.T) {
ctx, store := InitializeTestStore(t) ctx, store := InitializeTestStore(t)
ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "SessionId", sessionId)
fm, err := NewFlagManager(flagsPath)
if err != nil {
t.Logf(err.Error())
}
h := &MenuHandlers{ h := &MenuHandlers{
userdataStore: store, userdataStore: store,
accountService: mockAccountService, accountService: mockAccountService,
flagManager: fm,
} }
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey)) err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -2222,6 +2239,8 @@ func TestGetVoucherDetails(t *testing.T) {
if err != nil { if err != nil {
t.Logf(err.Error()) t.Logf(err.Error())
} }
flag_api_error, _ := fm.GetFlag("flag_api_call_error")
mockAccountService := new(mocks.MockAccountService) mockAccountService := new(mocks.MockAccountService)
sessionId := "session123" sessionId := "session123"
@ -2249,8 +2268,8 @@ func TestGetVoucherDetails(t *testing.T) {
"Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation, "Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation,
) )
mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil) mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil)
res, err := h.GetVoucherDetails(ctx, "SessionId", []byte("")) res, err := h.GetVoucherDetails(ctx, "SessionId", []byte(""))
expectedResult.FlagReset = append(expectedResult.FlagReset, flag_api_error)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedResult, res) assert.Equal(t, expectedResult, res)
} }