// postProduct201 validates a product can be created with the endpoint.
postProduct201 validates a product can be created with the endpoint.
// postProduct201 validates a product can be created with the endpoint .
func postProduct201(t *testing.T) product.Product {
	np := product.NewProduct{
		Name:      "Comic Books",
		Notes:     "Various conditions.",
		Family:    "Kennedy",
		UnitPrice: 25,
		Quantity:  60,
	}
	body, err := json.Marshal(&np)
	if err != nil {
		t.Fatal(err)
	}
	r := httptest.NewRequest("POST", "/v1/products", bytes.NewBuffer(body))
	w := httptest.NewRecorder()
	r.Header.Set("Authorization", userAuthorization)
	a.ServeHTTP(w, r)
	var p product.Product
	t.Log("Given the need to create a new product with the products endpoint.")
	{
		t.Log("\tTest 0:\tWhen using the declared product value.")
		{
			if w.Code != http.StatusCreated {
				t.Fatalf("\t%s\tShould receive a status code of 201 for the response : %v", tests.Failed, w.Code)
			}
			t.Logf("\t%s\tShould receive a status code of 201 for the response.", tests.Success)
			if err := json.NewDecoder(w.Body).Decode(&p); err != nil {
				t.Fatalf("\t%s\tShould be able to unmarshal the response : %v", tests.Failed, err)
			}
			want := p
			want.Name = "Comic Books"
			want.Notes = "Various conditions."
			want.Family = "Kennedy"
			want.UnitPrice = 25
			want.Quantity = 60
			if diff := cmp.Diff(want, p); diff != "" {
				t.Fatalf("\t%s\tShould get the expected result. Diff:\n%s", tests.Failed, diff)
			}
			t.Logf("\t%s\tShould get the expected result.", tests.Success)
		}
	}
	return p
}
func postProduct201 ( t * testing . T ) product . Product { np := product . NewProduct { Name : " " , Notes : " " , Family : " " , UnitPrice : 25 , Quantity : 60 , } body , err := json . Marshal ( & np ) if err != nil { t . Fatal ( err ) } r := httptest . NewRequest ( " " , " " , bytes . NewBuffer ( body ) ) w := httptest . NewRecorder ( ) r . Header . Set ( " " , userAuthorization ) a . ServeHTTP ( w , r ) var p product . Product t . Log ( " " ) { t . Log ( " \t \t " ) { if w . Code != http . StatusCreated { t . Fatalf ( " \t \t " , tests . Failed , w . Code ) } t . Logf ( " \t \t " , tests . Success ) if err := json . NewDecoder ( w . Body ) . Decode ( & p ) ; err != nil { t . Fatalf ( " \t \t " , tests . Failed , err ) } want := p want . Name = " " want . Notes = " " want . Family = " " want . UnitPrice = 25 want . Quantity = 60 if diff := cmp . Diff ( want , p ) ; diff != " " { t . Fatalf ( " \t \t \n " , tests . Failed , diff ) } t . Logf ( " \t \t " , tests . Success ) } } return p }
postProduct201 validates a product can be created with the endpoint.
postProduct201 validates a product can be created with the endpoint .
// p is the value we will return. // Define what we wanted to receive. We will just trust the generated // fields like ID and Dates so we copy p.