Skip to content

Commit c8643b4

Browse files
authored
Merge pull request #7 from prep/master
The balance API call returns an amount of type float, not int
2 parents ccb5b32 + cffafa8 commit c8643b4

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

balance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package messagebird
33
type Balance struct {
44
Payment string
55
Type string
6-
Amount int
6+
Amount float32
77
Errors []Error
88
}

balance_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import "testing"
55
var balanceObject []byte = []byte(`{
66
"payment":"prepaid",
77
"type":"credits",
8-
"amount":9
8+
"amount":9.2
99
}`)
1010

11+
const Epsilon float32 = 0.001
12+
13+
func cmpFloat32(a, b float32) bool {
14+
return (a-b) < Epsilon && (b-a) < Epsilon
15+
}
16+
1117
func TestBalance(t *testing.T) {
1218
SetServerResponse(200, balanceObject)
1319

@@ -22,8 +28,8 @@ func TestBalance(t *testing.T) {
2228
if balance.Type != "credits" {
2329
t.Errorf("Unexpected balance type: %s", balance.Type)
2430
}
25-
if balance.Amount != 9 {
26-
t.Errorf("Unexpected balance amount: %d", balance.Amount)
31+
if !cmpFloat32(balance.Amount, 9.2) {
32+
t.Errorf("Unexpected balance amount: %.2f", balance.Amount)
2733
}
2834
}
2935

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
ClientVersion = "2.2.1"
21+
ClientVersion = "2.3.0"
2222
Endpoint = "https://rest.messagebird.com"
2323
)
2424

0 commit comments

Comments
 (0)