digits-2023-10-15/digits-work-sample-go-bree-.../transaction_test.go

56 lines
1.4 KiB
Go

package analyzer
import (
"testing"
)
// - Note: The JSON data contains the person's name who made the transaction.
// Let's pipe that through so it's available.
//
// - Note: Pay attention to how we want negative transactions handled.
func TestTransaction_String(t *testing.T) {
tests := []struct {
name string
trn Transaction
want string
}{
{
name: "MCCOLLOMS INC",
trn: Transaction{
CardholderFirstInitial: "R",
CardholderLastName: "Bowers",
Amount: 3831.20,
Vendor: "MCCOLLOMS INC",
},
want: "R. Bowers spent $3,831.20 at MCCOLLOMS INC",
},
{
name: "QUANTUM ELECTRIC INC",
trn: Transaction{
CardholderFirstInitial: "B",
CardholderLastName: "Adams",
Amount: 89.00,
Vendor: "QUANTUM ELECTRIC INC",
},
want: "B. Adams spent $89.00 at QUANTUM ELECTRIC INC",
},
{
name: "MARRIOTT 33716 NEW ORLEAN",
trn: Transaction{
CardholderFirstInitial: "J",
CardholderLastName: "Golliver",
Amount: -514.11,
Vendor: "MARRIOTT 33716 NEW ORLEAN",
},
want: "MARRIOTT 33716 NEW ORLEAN refunded J. Golliver $514.11",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.trn.String(); got != tt.want {
t.Errorf("Transaction.String() = %q, want %q", got, tt.want)
}
})
}
}