mirror of
https://github.com/wahyd4/cash-code-test.git
synced 2026-08-09 05:16:05 +10:00
65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
package commands
|
|
|
|
import (
|
|
"github.com/wahyd4/cash/domains"
|
|
"testing"
|
|
)
|
|
|
|
func TestDepositCommand_Run(t *testing.T) {
|
|
bank := domains.InitBank()
|
|
bank.OpenAccount("Tom")
|
|
|
|
type fields struct {
|
|
Account string
|
|
Money float64
|
|
}
|
|
type args struct {
|
|
bank *domains.Bank
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
wantErr bool
|
|
}{
|
|
{
|
|
"can deposit some money",
|
|
fields{
|
|
Account: "Tom",
|
|
Money: 20.10,
|
|
},
|
|
args{bank: bank},
|
|
false,
|
|
},
|
|
{
|
|
"fail to deposit some money due to money is negative",
|
|
fields{
|
|
Account: "Tom",
|
|
Money: -20.10,
|
|
},
|
|
args{bank: bank},
|
|
true,
|
|
},
|
|
{
|
|
"fail to deposit some money due to the user is not exist",
|
|
fields{
|
|
Account: "NotExist",
|
|
Money: -20.10,
|
|
},
|
|
args{bank: bank},
|
|
true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
command := &DepositCommand{
|
|
Account: tt.fields.Account,
|
|
Money: tt.fields.Money,
|
|
}
|
|
if err := command.Run(tt.args.bank); (err != nil) != tt.wantErr {
|
|
t.Errorf("Run() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|