Skip to content

Commit

Permalink
Add test for Brand
Browse files Browse the repository at this point in the history
  • Loading branch information
nukosuke committed Mar 19, 2019
1 parent ec062e1 commit 1224f39
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions zendesk/brand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package zendesk

import (
"net/http"
"net/http/httptest"
"testing"
)

Expand All @@ -15,3 +16,48 @@ func TestCreateBrand(t *testing.T) {
t.Fatalf("Failed to send request to create brand: %s", err)
}
}

func TestGetBrand(t *testing.T) {
mockAPI := newMockAPI(http.MethodGet, "brand.json")
client := newTestClient(mockAPI)
defer mockAPI.Close()

brand, err := client.GetBrand(123)
if err != nil {
t.Fatalf("Failed to get brand: %s", err)
}

expectedID := int64(360002143133)
if brand.ID != expectedID {
t.Fatalf("Returned brand does not have the expected ID %d. Brand ID is %d", expectedID, brand.ID)
}
}

func TestUpdateBrand(t *testing.T) {
mockAPI := newMockAPIWithStatus(http.MethodPut, "brands.json", http.StatusOK)
client := newTestClient(mockAPI)
defer mockAPI.Close()

updatedBrand, err := client.UpdateBrand(int64(1234), Brand{})
if err != nil {
t.Fatalf("Failed to send request to create brand: %s", err)
}

expectedID := int64(360002143133)
if updatedBrand.ID != expectedID {
t.Fatalf("Updated brand %v did not have expected id %d", updatedBrand, expectedID)
}
}

func TestDeleteBrand(t *testing.T) {
mockAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
w.Write(nil)
}))

c := newTestClient(mockAPI)
err := c.DeleteBrand(1234)
if err != nil {
t.Fatalf("Failed to delete brand: %s", err)
}
}

0 comments on commit 1224f39

Please sign in to comment.