menu-voucherlist #101

Merged
lash merged 63 commits from menu-voucherlist into master 2024-10-25 15:59:47 +02:00
Showing only changes of commit b6d24bf929 - Show all commits

View File

@ -1560,33 +1560,72 @@ func TestValidateRecipient(t *testing.T) {
} }
func TestCheckBalance(t *testing.T) { func TestCheckBalance(t *testing.T) {
tests := []struct {
mockDataStore := new(mocks.MockUserDataStore) name string
sessionId := "session123" sessionId string
publicKey := "0X13242618721" publicKey string
balance := "0.003 CELO" activeSym string
activeBal string
expectedResult := resource.Result{ expectedResult resource.Result
Content: "0.003 CELO", expectError bool
}{
{
name: "User with active sym",
sessionId: "session456",
publicKey: "0X98765432109",
activeSym: "ETH",
activeBal: "1.5",
expectedResult: resource.Result{Content: "1.5 ETH"},
expectError: false,
},
{
name: "User without active sym",
sessionId: "session123",
publicKey: "0X13242618721",
activeSym: "",
activeBal: "",
expectedResult: resource.Result{Content: "0.003 CELO"},
expectError: false,
},
} }
mockCreateAccountService := new(mocks.MockAccountService) for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mockDataStore := new(mocks.MockUserDataStore)
mockAccountService := new(mocks.MockAccountService)
ctx := context.WithValue(context.Background(), "SessionId", tt.sessionId)
ctx := context.WithValue(context.Background(), "SessionId", sessionId) h := &Handlers{
userdataStore: mockDataStore,
accountService: mockAccountService,
}
h := &Handlers{ // Mock calls for public key
userdataStore: mockDataStore, mockDataStore.On("ReadEntry", ctx, tt.sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(tt.publicKey), nil)
accountService: mockCreateAccountService,
//flagManager: fm.parser, if tt.activeSym == "" {
// Mock for user without active sym
mockDataStore.On("ReadEntry", ctx, tt.sessionId, utils.DATA_ACTIVE_SYM).Return([]byte{}, db.ErrNotFound{})
mockAccountService.On("CheckBalance", tt.publicKey).Return("0.003 CELO", nil)
} else {
// Mock for user with active sym
mockDataStore.On("ReadEntry", ctx, tt.sessionId, utils.DATA_ACTIVE_SYM).Return([]byte(tt.activeSym), nil)
mockDataStore.On("ReadEntry", ctx, tt.sessionId, utils.DATA_ACTIVE_BAL).Return([]byte(tt.activeBal), nil)
}
res, err := h.CheckBalance(ctx, "check_balance", []byte("123456"))
if tt.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expectedResult, res, "Result should match expected output")
}
mockDataStore.AssertExpectations(t)
mockAccountService.AssertExpectations(t)
})
} }
//mock call operations
mockDataStore.On("ReadEntry", ctx, sessionId, utils.DATA_PUBLIC_KEY).Return([]byte(publicKey), nil)
mockCreateAccountService.On("CheckBalance", string(publicKey)).Return(balance, nil)
res, _ := h.CheckBalance(ctx, "check_balance", []byte("123456"))
assert.Equal(t, res, expectedResult, "Result should contain flag(s) that have been reset")
} }
func TestGetProfile(t *testing.T) { func TestGetProfile(t *testing.T) {