-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallettransaction_test.go
76 lines (72 loc) · 1.68 KB
/
wallettransaction_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package monta
import (
"encoding/json"
"strings"
"testing"
"gotest.tools/v3/assert"
)
func TestWalletTransaction_MarshalJSON(t *testing.T) {
expected := strings.TrimSpace(`
{
"id": 1,
"fromAmount": 13.77,
"fromCurrency": {
"identifier": "DKK",
"name": "Danish krone",
"decimals": 2
},
"fromType": "team",
"from": {
"id": 14,
"publicName": "Monta",
"partnerExternalId": "abcd"
},
"toAmount": 13.77,
"toCurrency": {
"identifier": "DKK",
"name": "Danish krone",
"decimals": 2
},
"toType": "operator",
"to": {
"id": 14,
"name": "Monta",
"identifier": "monta",
"vatNumber": "FOO-123-ABC",
"partnerId": 423
},
"exchangeRate": 1,
"createdAt": "2022-04-22T09:47:05Z",
"updatedAt": "2022-04-22T09:47:06Z",
"referenceType": "SubscriptionPurchase",
"referenceId": "4908086",
"group": "withdraw",
"state": "complete",
"note": "Test transaction."
}
`)
var walletTransaction WalletTransaction
assert.NilError(t, json.Unmarshal([]byte(expected), &walletTransaction))
expectedFromTeam := &PayingTeam{
ID: 14,
PublicName: "Monta",
PartnerExternalID: toPointer("abcd"),
}
assert.DeepEqual(t, expectedFromTeam, walletTransaction.FromTeam)
walletTransaction.From = nil
expectedToOperator := &Operator{
ID: 14,
Name: "Monta",
Identifier: "monta",
VATNumber: "FOO-123-ABC",
PartnerID: 423,
}
assert.DeepEqual(t, expectedToOperator, walletTransaction.ToOperator)
walletTransaction.To = nil
actual, err := json.MarshalIndent(&walletTransaction, "", " ")
assert.NilError(t, err)
assert.Equal(t, expected, string(actual))
}
func toPointer[T any](v T) *T {
return &v
}