diff --git a/go.mod b/go.mod index 465d32cd0..6e6876323 100644 --- a/go.mod +++ b/go.mod @@ -86,6 +86,7 @@ require ( go.mongodb.org/mongo-driver v1.7.5 // indirect golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect golang.org/x/oauth2 v0.15.0 + golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect google.golang.org/api v0.153.0 gopkg.in/go-playground/validator.v9 v9.31.0 // indirect gorm.io/driver/postgres v1.5.4 diff --git a/go.sum b/go.sum index bb54dfb8a..0278fc640 100644 --- a/go.sum +++ b/go.sum @@ -3033,12 +3033,15 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ= +golang.org/x/tools v0.5.1-0.20230111220935-a7f7db3f17fc/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4= golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg= golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM= +golang.org/x/tools/cmd/cover v0.1.0-deprecated h1:Rwy+mWYz6loAF+LnG1jHG/JWMHRMMC2/1XX3Ejkx9lA= +golang.org/x/tools/cmd/cover v0.1.0-deprecated/go.mod h1:hMDiIvlpN1NoVgmjLjUJE9tMHyxHjFX7RuQ+rW12mSA= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/handlers/people_test.go b/handlers/people_test.go index c0fe4d8c7..6fb59861f 100644 --- a/handlers/people_test.go +++ b/handlers/people_test.go @@ -11,6 +11,7 @@ import ( "github.com/go-chi/chi" "github.com/google/uuid" + "github.com/lib/pq" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" mocks "github.com/stakwork/sphinx-tribes/mocks" @@ -181,17 +182,25 @@ func TestCreateOrEditPerson(t *testing.T) { } func TestGetPersonById(t *testing.T) { - mockDb := mocks.NewDatabase(t) - pHandler := NewPeopleHandler(mockDb) + teardownSuite := SetupSuite(t) + defer teardownSuite(t) + + pHandler := NewPeopleHandler(db.TestDB) t.Run("successful retrieval", func(t *testing.T) { rr := httptest.NewRecorder() handler := http.HandlerFunc(pHandler.GetPersonById) person := db.Person{ - ID: 1, - Uuid: "test-uuid", - OwnerPubKey: "owner-pub-key", - OwnerAlias: "owner", + ID: 100, + Uuid: "perosn_1_uuid", + OwnerAlias: "person", + UniqueName: "person", + OwnerPubKey: "person_1_pubkey", + PriceToMeet: 0, + Description: "this is test user 1", + Tags: pq.StringArray{}, + Extras: db.PropertyMap{}, + GithubIssues: db.PropertyMap{}, } rctx := chi.NewRouteContext() @@ -199,7 +208,9 @@ func TestGetPersonById(t *testing.T) { req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/person", nil) assert.NoError(t, err) - mockDb.On("GetPerson", mock.Anything).Return(person).Once() + db.TestDB.CreateOrEditPerson(person) + fetchedPerson := db.TestDB.GetPerson(person.ID) + handler.ServeHTTP(rr, req) var returnedPerson db.Person @@ -207,7 +218,7 @@ func TestGetPersonById(t *testing.T) { assert.NoError(t, err) assert.Equal(t, http.StatusOK, rr.Code) assert.EqualValues(t, person, returnedPerson) - mockDb.AssertExpectations(t) + assert.EqualValues(t, person, fetchedPerson) }) t.Run("person not found", func(t *testing.T) { @@ -219,11 +230,9 @@ func TestGetPersonById(t *testing.T) { req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/person", nil) assert.NoError(t, err) - mockDb.On("GetPerson", mock.Anything).Return(db.Person{}).Once() handler.ServeHTTP(rr, req) assert.Equal(t, http.StatusOK, rr.Code) - mockDb.AssertExpectations(t) }) }