-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcharge_test.go
78 lines (75 loc) · 1.76 KB
/
charge_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
77
78
package monta
import (
"encoding/json"
"strings"
"testing"
"gotest.tools/v3/assert"
)
func TestCharge_MarshalJSON(t *testing.T) {
expected := strings.TrimSpace(`
{
"id": 1,
"chargePointId": 21,
"createdAt": "2022-05-12T15:56:45.999189Z",
"updatedAt": "2022-05-17T15:56:45.999189Z",
"cablePluggedInAt": "2022-05-12T15:56:45.999189Z",
"startedAt": "2022-05-12T15:56:45.999189Z",
"stoppedAt": "2022-05-12T15:56:45.999189Z",
"fullyChargedAt": "2022-05-12T15:56:45.999189Z",
"failedAt": "2022-05-12T15:56:45.999189Z",
"timeoutAt": "2022-05-12T15:56:45.999189Z",
"state": "charging",
"consumedKwh": 20.4,
"kwhPerHour": [
{
"time": "2022-05-12T15:00:00Z",
"value": 1.2
}
],
"startMeterKwh": 123.45,
"endMeterKwh": 163.85,
"price": 122.4,
"priceLimit": 212,
"averagePricePerKwh": 6,
"averageCo2PerKwh": 100,
"averageRenewablePerKwh": 72.5,
"failureReason": "Some reason why we couldn't charge.",
"stopReason": "Some reason why the charge stopped.",
"paymentMethod": "free",
"note": "Lorem Ipsum",
"chargePointKw": 138.56,
"kwhLimit": 21,
"currency": {
"identifier": "DKK",
"name": "Danish krone",
"decimals": 2
},
"payingTeam": {
"id": 14,
"publicName": "Monta HQ",
"partnerExternalId": "abc"
},
"chargeAuth": {
"type": "vehicleId",
"id": "2C:54:91:88:C9:E3"
},
"soc": {
"percentage": 42.2,
"source": "vehicle"
},
"socLimit": 80,
"operator": {
"id": 445,
"name": "Einride",
"identifier": "einride",
"vatNumber": "123",
"partnerId": 423
}
}
`)
var charge Charge
assert.NilError(t, json.Unmarshal([]byte(expected), &charge))
actual, err := json.MarshalIndent(&charge, "", " ")
assert.NilError(t, err)
assert.Equal(t, expected, string(actual))
}