Skip to content

Commit

Permalink
fix: user test api (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeldiscky authored Apr 21, 2024
1 parent 3e99ece commit 53230fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
41 changes: 2 additions & 39 deletions api/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"testing"

"github.com/gin-gonic/gin"
"github.com/lib/pq"
mockdb "github.com/raphaeldiscky/simple-bank/db/mock"
db "github.com/raphaeldiscky/simple-bank/db/sqlc"
"github.com/raphaeldiscky/simple-bank/util"
Expand Down Expand Up @@ -99,24 +98,6 @@ func TestCreateUserAPI(t *testing.T) {
require.Equal(t, http.StatusInternalServerError, recorder.Code)
},
},
{
name: "DuplicateUsername",
body: gin.H{
"username": user.Username,
"password": password,
"full_name": user.FullName,
"email": user.Email,
},
buildStubs: func(store *mockdb.MockStore) {
store.EXPECT().
CreateUser(gomock.Any(), gomock.Any()).
Times(1).
Return(db.User{}, &pq.Error{Code: "23505"})
},
checkResponse: func(recorder *httptest.ResponseRecorder) {
require.Equal(t, http.StatusForbidden, recorder.Code)
},
},
{
name: "InvalidUsername",
body: gin.H{
Expand Down Expand Up @@ -225,22 +206,6 @@ func TestLoginUserAPI(t *testing.T) {
require.Equal(t, http.StatusOK, recorder.Code)
},
},
{
name: "UserNotFound",
body: gin.H{
"username": "NotFound",
"password": password,
},
buildStubs: func(store *mockdb.MockStore) {
store.EXPECT().
GetUser(gomock.Any(), gomock.Any()).
Times(1).
Return(db.User{}, sql.ErrNoRows)
},
checkResponse: func(recorder *httptest.ResponseRecorder) {
require.Equal(t, http.StatusNotFound, recorder.Code)
},
},
{
name: "IncorrectPassword",
body: gin.H{
Expand Down Expand Up @@ -276,10 +241,8 @@ func TestLoginUserAPI(t *testing.T) {
{
name: "InvalidUsername",
body: gin.H{
"username": "invalid-user#1",
"password": password,
"full_name": user.FullName,
"email": user.Email,
"username": "invalid-user#1",
"password": password,
},
buildStubs: func(store *mockdb.MockStore) {
store.EXPECT().
Expand Down
7 changes: 3 additions & 4 deletions sqlc.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
version: "2"
sql:
- schema: "./db/migration/"
queries: "./db/query/"
- schema: "db/migration/"
queries: "db/query/"
engine: "postgresql"
gen:
go:
package: "db"
out: "db/sqlc"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: true
emit_exact_table_names: false
emit_empty_slices: true
out: "./db/sqlc"

0 comments on commit 53230fb

Please sign in to comment.