Skip to content

Commit

Permalink
Add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atmnk committed Nov 9, 2023
1 parent eac007d commit 56fd86c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/gofiber/fiber/v2 v2.50.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/samber/lo v1.38.1
github.com/stretchr/testify v1.8.4
gorm.io/driver/postgres v1.5.4
Expand All @@ -14,7 +15,6 @@ require (
require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
Expand Down
15 changes: 15 additions & 0 deletions tests/routes/api/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ func TestUsersRoute_GetUserInfo(t *testing.T) {
resp := lo.Must(app.Test(req))
assert.Equal(t, 200, resp.StatusCode)
}
func TestUsersRoute_ShouldNotRegisterUserWhenNoPassword(t *testing.T) {
reqBody := []byte(`{"email": "arnav@mail.com"}`)
req := httptest.NewRequest("POST", "/api/v1/users", bytes.NewBuffer(reqBody))
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
resp := lo.Must(app.Test(req))
assert.Equal(t, 400, resp.StatusCode)
}
func TestUsersRoute_ShouldNotRegisterUserWhenNoEmail(t *testing.T) {
reqBody := []byte(`{"password": "12345"}`)
req := httptest.NewRequest("POST", "/api/v1/users", bytes.NewBuffer(reqBody))
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
resp := lo.Must(app.Test(req))
assert.Equal(t, 400, resp.StatusCode)
}

0 comments on commit 56fd86c

Please sign in to comment.