mirror of
https://github.com/wahyd4/cash-code-test.git
synced 2026-08-09 05:16:05 +10:00
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"github.com/wahyd4/cash/domains"
|
|
"testing"
|
|
)
|
|
|
|
func TestBalanceCommand_Run(t *testing.T) {
|
|
bank := domains.InitBank()
|
|
bank.OpenAccount("Tom")
|
|
bank.OpenAccount("Lily")
|
|
|
|
account, _ := bank.AccountFromName("Tom")
|
|
account2, _ := bank.AccountFromName("Lily")
|
|
|
|
bank.DepositFor(account, 500)
|
|
bank.DepositFor(account2, 29.10)
|
|
|
|
type fields struct {
|
|
Account string
|
|
}
|
|
type args struct {
|
|
bank *domains.Bank
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"can print balance for user",
|
|
fields{Account: "Tom"},
|
|
args{bank: bank},
|
|
false,
|
|
},
|
|
{
|
|
"can print balance for user",
|
|
fields{Account: "Lily"},
|
|
args{bank: bank},
|
|
false,
|
|
},
|
|
{
|
|
"cannot print the user du to the user is not exist",
|
|
fields{Account: "NotExist"},
|
|
args{bank: bank},
|
|
true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
command := &UserBalanceCommand{
|
|
Account: tt.fields.Account,
|
|
}
|
|
if err := command.Run(tt.args.bank); (err != nil) != tt.wantErr {
|
|
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|