Skip to content

Commit

Permalink
solving gui comments :)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Sep 6, 2024
1 parent 232ab25 commit 9202146
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func testURL(path string) string {
return fmt.Sprintf("http://%s:%d%s", testHost, testPort, path)
}

// mustMarshall helper function marshalls the input interface into a byte slice.
// mustMarshal helper function marshalls the input interface into a byte slice.
// It panics if the marshalling fails.
func mustMarshall(i any) []byte {
func mustMarshal(i any) []byte {
b, err := json.Marshal(i)
if err != nil {
panic(err)
Expand Down
32 changes: 16 additions & 16 deletions api/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
qt "github.com/frankban/quicktest"
)

func Test_registerHandler(t *testing.T) {
func TestRegisterHandler(t *testing.T) {
c := qt.New(t)
defer func() {
if err := testDB.Reset(); err != nil {
Expand All @@ -25,12 +25,12 @@ func Test_registerHandler(t *testing.T) {
method: http.MethodPost,
body: []byte("invalid body"),
expectedStatus: http.StatusBadRequest,
expectedBody: mustMarshall(ErrMalformedBody),
expectedBody: mustMarshal(ErrMalformedBody),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "[email protected]",
Password: "password",
FirstName: "first",
Expand All @@ -41,79 +41,79 @@ func Test_registerHandler(t *testing.T) {
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "[email protected]",
Password: "password",
FirstName: "first",
LastName: "last",
}),
expectedStatus: http.StatusInternalServerError,
expectedBody: mustMarshall(ErrGenericInternalServerError),
expectedBody: mustMarshal(ErrGenericInternalServerError),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "[email protected]",
Password: "password",
FirstName: "first",
LastName: "",
}),
expectedStatus: http.StatusBadRequest,
expectedBody: mustMarshall(ErrMalformedBody.Withf("last name is empty")),
expectedBody: mustMarshal(ErrMalformedBody.Withf("last name is empty")),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "[email protected]",
Password: "password",
FirstName: "",
LastName: "last",
}),
expectedStatus: http.StatusBadRequest,
expectedBody: mustMarshall(ErrMalformedBody.Withf("first name is empty")),
expectedBody: mustMarshal(ErrMalformedBody.Withf("first name is empty")),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "invalid",
Password: "password",
FirstName: "first",
LastName: "last",
}),
expectedStatus: http.StatusBadRequest,
expectedBody: mustMarshall(ErrEmailMalformed),
expectedBody: mustMarshal(ErrEmailMalformed),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "",
Password: "password",
FirstName: "first",
LastName: "last",
}),
expectedStatus: http.StatusBadRequest,
expectedBody: mustMarshall(ErrEmailMalformed),
expectedBody: mustMarshal(ErrEmailMalformed),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "[email protected]",
Password: "short",
FirstName: "first",
LastName: "last",
}),
expectedStatus: http.StatusBadRequest,
expectedBody: mustMarshall(ErrPasswordTooShort),
expectedBody: mustMarshal(ErrPasswordTooShort),
},
{
uri: registerURL,
method: http.MethodPost,
body: mustMarshall(&UserInfo{
body: mustMarshal(&UserInfo{
Email: "[email protected]",
Password: "",
FirstName: "first",
Expand Down

0 comments on commit 9202146

Please sign in to comment.