|
| 1 | +package messagebird |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +var balanceObject []byte = []byte(`{ |
| 6 | + "payment":"prepaid", |
| 7 | + "type":"credits", |
| 8 | + "amount":9 |
| 9 | +}`) |
| 10 | + |
| 11 | +func TestBalance(t *testing.T) { |
| 12 | + SetServerResponse(200, balanceObject) |
| 13 | + |
| 14 | + balance, err := mbClient.Balance() |
| 15 | + if err != nil { |
| 16 | + t.Fatalf("Didn't expect error while fetching the balance: %s", err) |
| 17 | + } |
| 18 | + |
| 19 | + if balance.Payment != "prepaid" { |
| 20 | + t.Errorf("Unexpected balance payment: %s", balance.Payment) |
| 21 | + } |
| 22 | + if balance.Type != "credits" { |
| 23 | + t.Errorf("Unexpected balance type: %s", balance.Type) |
| 24 | + } |
| 25 | + if balance.Amount != 9 { |
| 26 | + t.Errorf("Unexpected balance amount: %d", balance.Amount) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func TestBalanceError(t *testing.T) { |
| 31 | + SetServerResponse(405, accessKeyErrorObject) |
| 32 | + |
| 33 | + balance, err := mbClient.Balance() |
| 34 | + if err != ErrResponse { |
| 35 | + t.Fatalf("Expected ErrResponse to be returned, instead I got %s", err) |
| 36 | + } |
| 37 | + |
| 38 | + if len(balance.Errors) != 1 { |
| 39 | + t.Fatalf("Unexpected number of errors: %d", len(balance.Errors)) |
| 40 | + } |
| 41 | + |
| 42 | + if balance.Errors[0].Code != 2 { |
| 43 | + t.Errorf("Unexpected error code: %d", balance.Errors[0].Code) |
| 44 | + } |
| 45 | + |
| 46 | + if balance.Errors[0].Parameter != "access_key" { |
| 47 | + t.Errorf("Unexpected error parameter: %s", balance.Errors[0].Parameter) |
| 48 | + } |
| 49 | +} |
0 commit comments