Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TestGetPersonById To Use A Real Postgres DB For The Test #1710

Closed
8 tasks
elraphty opened this issue Jun 19, 2024 · 3 comments · Fixed by #1714
Closed
8 tasks

Refactor TestGetPersonById To Use A Real Postgres DB For The Test #1710

elraphty opened this issue Jun 19, 2024 · 3 comments · Fixed by #1714
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jun 19, 2024

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 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
    teardownSuite := SetupSuite(t)
    defer teardownSuite(t)

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

Here is an example Real DB Test

@AbdulWahab3181
Copy link
Contributor

AbdulWahab3181 commented Jun 19, 2024

@elraphty @fvalentiner Could you please assign me?

1 similar comment
@MahtabBukhari
Copy link
Contributor

@elraphty @fvalentiner Could you please assign me?

@elraphty
Copy link
Contributor Author

@elraphty @fvalentiner Could you please assign me?

@AbdulWahab3181 You can have this, please it is 1 day time bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants