// postUser201 validates a user can be created with the endpoint.
postUser201 validates a user can be created with the endpoint.
// postUser201 validates a user can be created with the endpoint .
func postUser201(t *testing.T) user.User {
	nu := user.NewUser{
		Name:            "Bill Kennedy",
		Email:           "bill@ardanlabs.com",
		Roles:           []string{auth.RoleAdmin},
		Password:        "gophers",
		PasswordConfirm: "gophers",
	}
	body, err := json.Marshal(&nu)
	if err != nil {
		t.Fatal(err)
	}
	r := httptest.NewRequest("POST", "/v1/users", bytes.NewBuffer(body))
	w := httptest.NewRecorder()
	r.Header.Set("Authorization", adminAuthorization)
	a.ServeHTTP(w, r)
	var u user.User
	t.Log("Given the need to create a new user with the users endpoint.")
	{
		t.Log("\tTest 0:\tWhen using the declared user 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(&u); err != nil {
				t.Fatalf("\t%s\tShould be able to unmarshal the response : %v", tests.Failed, err)
			}
			want := u
			want.Name = "Bill Kennedy"
			want.Email = "bill@ardanlabs.com"
			want.Roles = []string{auth.RoleAdmin}
			if diff := cmp.Diff(want, u); 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 u
}
func postUser201 ( t * testing . T ) user . User { nu := user . NewUser { Name : " " , Email : " " , Roles : [ ] string { auth . RoleAdmin } , Password : " " , PasswordConfirm : " " , } body , err := json . Marshal ( & nu ) if err != nil { t . Fatal ( err ) } r := httptest . NewRequest ( " " , " " , bytes . NewBuffer ( body ) ) w := httptest . NewRecorder ( ) r . Header . Set ( " " , adminAuthorization ) a . ServeHTTP ( w , r ) var u user . User 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 ( & u ) ; err != nil { t . Fatalf ( " \t \t " , tests . Failed , err ) } want := u want . Name = " " want . Email = " " want . Roles = [ ] string { auth . RoleAdmin } if diff := cmp . Diff ( want , u ) ; diff != " " { t . Fatalf ( " \t \t \n " , tests . Failed , diff ) } t . Logf ( " \t \t " , tests . Success ) } } return u }
postUser201 validates a user can be created with the endpoint.
postUser201 validates a user can be created with the endpoint .
// u 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 u.