-
Notifications
You must be signed in to change notification settings - Fork 462
/
transfer_test.go
53 lines (43 loc) · 1.26 KB
/
transfer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package stripe
import (
"encoding/json"
"testing"
)
func TestTransferUnmarshal(t *testing.T) {
transferData := map[string]interface{}{
"id": "tr_1234",
"object": "transfer",
"source_transaction": map[string]interface{}{
"id": "ch_1234",
"object": "charge",
},
}
bytes, err := json.Marshal(&transferData)
if err != nil {
t.Error(err)
}
var transfer Transfer
err = json.Unmarshal(bytes, &transfer)
if err != nil {
t.Error(err)
}
if transfer.ID != "tr_1234" {
t.Errorf("Problem deserializing transfer, got ID %v", transfer.ID)
}
source_transaction := transfer.SourceTransaction
if source_transaction == nil {
t.Errorf("Problem deserializing transfer, didn't get a SourceTransaction")
}
if source_transaction.ID != "ch_1234" {
t.Errorf("Problem deserializing transfer.source_transaction, wrong value for ID")
}
if source_transaction.Type != BalanceTransactionSourceTypeCharge {
t.Errorf("Problem deserializing transfer.source_transaction, wrong value for Type")
}
if source_transaction.Charge == nil {
t.Errorf("Problem deserializing transfer.source_transaction, didn't get a Charge")
}
if source_transaction.Charge.ID != "ch_1234" {
t.Errorf("Problem deserializing transfer.source_transaction, wrong value for Charge.ID")
}
}