Created
April 28, 2020 22:02
-
-
Save diegoholiveira/d4758b609be4d3dcf03e8518b070cccc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestPurchase_success(t *testing.T) { | |
input := `{ | |
"user_id": 1, | |
"books": [ | |
{ | |
"id": 1, | |
"quantity": 2, | |
"price": 19.9 | |
} | |
] | |
}` | |
purchase := purchases.Purchase{ | |
UserID: 1, | |
Books: purchases.Books{ | |
{ | |
ID: 1, | |
Quantity: 2, | |
Price: 19.9, | |
}, | |
}, | |
} | |
r := httptest.NewRequest("POST", "/purchases", strings.NewReader(input)) | |
w := httptest.NewRecorder() | |
persister := new(mocks.PurchasePersister) | |
persister. | |
On("Persist", mock.Anything, purchase). | |
Return(nil) | |
h := NewPurchaseHandler(persister) | |
h.ServeHTTP(w, r) | |
resp := w.Result() | |
defer resp.Body.Close() | |
if assert.Equal(t, http.StatusCreated, resp.StatusCode) { | |
persister.AssertExpectations(t) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment