You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we test the TestGetPersonById with a mock database.
Design
We want to refactor the tests to use a real Postgres DB spun up on docker, follow the instructions in the Unit Testing section of README.md to run spin up a database in docker, and change the test_config.go configuration.
After spinning up the Postgres DB container:
Add this line of code on the first line and second of the test function TestGetPersonById to connect to the Test DB
The test will throw a dereference error if not connected to a DB.
Remove all mock database functions in the TestGetPersonById test cases e.g. mockDb.On("GetPersonByPubkey", "test-key").Return(db.Person{}).Once().
Change the database parameter in pHandler := NewPeopleHandler(mockDb) to pHandler := NewPeopleHandler(db.TestDB)
Create a new person by passing person data to the create person db function db.TestDb.CreateOrEditPerson() e.g
person := db.Person{
ID: 100,
Uuid: "perosn_1_uuid",
OwnerAlias: "person",
UniqueName: "person",
OwnerPubKey: "person_1_pubkey",
PriceToMeet: 0,
Description: "this is test user 1",
}
db.TestDb.CreateOrEditPerson(person)
Update the id URL param rctx.URLParams.Add("id", strconv.Itoa(int(person.ID))) to the created person id rctx.URLParams.Add("id", strconv.Itoa(int(person.ID)))
Assertions
Assert that all the test passes
Asert that the new user created is available in the DB by getting the user from the DB with db.TestDB.GetPerson(person.ID)
Assert that the user created is equal to the data sent from the test request
Acceptance Criteria
Do not delete any of the existing test cases on the TestGetPersonById
All test cases after the TestGetPersonById refactor passes
The Refactoring of TestGetPersonById should not break existing test flows.
I have rebased and tested locally before submitting my PR
I can submit a PR within 1 day of taking the bounty
Context
Currently, we test the TestGetPersonById with a mock database.
Design
We want to refactor the tests to use a real Postgres DB spun up on docker, follow the instructions in the
Unit Testing
section of README.md to run spin up a database in docker, and change thetest_config.go
configuration.After spinning up the Postgres DB container:
TestGetPersonById
to connect to the Test DBThe test will throw a dereference error if not connected to a DB.
TestGetPersonById
test cases e.g.mockDb.On("GetPersonByPubkey", "test-key").Return(db.Person{}).Once()
.pHandler := NewPeopleHandler(mockDb)
topHandler := NewPeopleHandler(db.TestDB)
db.TestDb.CreateOrEditPerson()
e.grctx.URLParams.Add("id", strconv.Itoa(int(person.ID)))
to the created person idrctx.URLParams.Add("id", strconv.Itoa(int(person.ID)))
Assertions
db.TestDB.GetPerson(person.ID)
Acceptance Criteria
TestGetPersonById
TestGetPersonById
refactor passesTestGetPersonById
should not break existing test flows.Here is an example Real DB Test
The text was updated successfully, but these errors were encountered: