Skip to content

Commit

Permalink
savannah api service
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-kores committed Feb 23, 2024
1 parent fa923c6 commit 56799db
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
File renamed without changes.
23 changes: 1 addition & 22 deletions cmd/api/customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,21 @@ func newTestApplication(t *testing.T) *Application {
}

func TestCreateCustomer(t *testing.T) {
// Create a new instance of our application struct which contains the dependencies
// needed by the handler.

app := newTestApplication(t)

// Create a new instance of a http.Request, setting the method to POST, the target
// URL to the /v1/customers path, and the request body to a JSON string containing a
// valid customer.
body := `{"name": "Test User", "email": "test@mail.com", "password": "password123"}`
r, err := http.NewRequest("POST", "/v1/customers", strings.NewReader(body))
if err != nil {
t.Fatal(err)
}

// Create a new httptest.ResponseRecorder.
w := httptest.NewRecorder()

// Call the createCustomer handler method, passing in the http.ResponseRecorder and
// http.Request as the response and request respectively.
app.SignUpCustomer(w, r)

// Call the Result() method on the http.ResponseRecorder to get the http.Response
// generated by the handler.
rs := w.Result()

// Check the response status code is 201.
if rs.StatusCode != http.StatusCreated {
t.Errorf("expected status 201; got %d", rs.StatusCode)
}
Expand All @@ -99,29 +89,18 @@ func TestCreateCustomer(t *testing.T) {
}

func TestGetCustomer(t *testing.T) {
// Create a new instance of our application struct which contains the dependencies
// needed by the handler.
app := newTestApplication(t)

// Create a new instance of a http.Request, setting the method to GET, the target
// URL to the /v1/customers/1 path, and the request body to nil.
r, err := http.NewRequest("GET", "/v1/customers/1", nil)
if err != nil {
t.Fatal(err)
}

// Create a new httptest.ResponseRecorder.
w := httptest.NewRecorder()

// Call the getCustomer handler method, passing in the http.ResponseRecorder and
// http.Request as the response and request respectively.
app.handle_getSingleCustomer(w, r)

// Call the Result() method on the http.ResponseRecorder to get the http.Response
// generated by the handler.
rs := w.Result()

// Check the response status code is 200.
if rs.StatusCode != http.StatusOK {
t.Errorf("expected status 200; got %d", rs.StatusCode)
}
Expand Down

0 comments on commit 56799db

Please sign in to comment.