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 TestGetListedPeople To Use A Real Postgres DB For The Test #1719

Closed
6 tasks
elraphty opened this issue Jun 21, 2024 · 6 comments · Fixed by #1728
Closed
6 tasks

Refactor TestGetListedPeople To Use A Real Postgres DB For The Test #1719

elraphty opened this issue Jun 21, 2024 · 6 comments · Fixed by #1728
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

Context

Currently, we test the TestGetListedPeople 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 TestGetListedPeople 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 TestGetListedPeople 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 three persons, one with Unlisted: true, and the other with Unlisted: false using this db function db.TestDb.CreateOrEditPerson() e.g
person := db.Person{
     Uuid:        "perosn_101_uuid",
     OwnerAlias:  "person101",
     UniqueName:  "person101",
     OwnerPubKey: "person_101_pubkey",
     PriceToMeet: 0,
     Description: "this is test user 1",
     Unlisted: true,
     Extras:       db.PropertyMap{"conding_languages": "Typescript"},
}
person2 := db.Person{
     Uuid:        "perosn_101_uuid",
     OwnerAlias:  "person101",
     UniqueName:  "person101",
     OwnerPubKey: "person_101_pubkey",
     PriceToMeet: 0,
     Description: "This is test user 1",
     Unlisted: false,
     Extras:       db.PropertyMap{"conding_languages": "Golang"},
}
person3 := db.Person{
     Uuid:        "perosn_101_uuid",
     OwnerAlias:  "person101",
     UniqueName:  "person101",
     OwnerPubKey: "person_101_pubkey",
     PriceToMeet: 0,
     Description: "This is test user 1",
     Unlisted: false,
     Extras:   db.PropertyMap{"conding_languages": "Lightning"},
}

db.TestDb.CreateOrEditPerson(person)
db.TestDb.CreateOrEditPerson(person2)
db.TestDb.CreateOrEditPerson(person3)
  • Get the people created by using person := db.TestDb.GetPerson(person.ID)
  • Assert that the people created are returned
  • Update the URL search query to one of the listed person's OwnerAlias req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/?page=1&limit=10&search=John", nil)
  • Update the URL languages query to one of the listed person's coding languages OwnerAlias req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/?page=1&limit=10&languages=typescript", nil)

Assertions

  • Assert that all the test passes

Acceptance Criteria

  • Do not delete any of the existing test cases on the TestGetListedPeople
  • All test cases after the TestGetListedPeople refactor passes
  • The Refactoring of TestGetListedPeople 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

@aliraza556
Copy link
Contributor

aliraza556 commented Jun 21, 2024

@elraphty Please assign me?

@MuhammadUmer44
Copy link
Contributor

MuhammadUmer44 commented Jun 21, 2024

@elraphty assign me?

@elraphty
Copy link
Contributor Author

@elraphty Please assign me?

You have to finish this within a day

@MuhammadUmer44
Copy link
Contributor

@elraphty please next assign me?

@aliraza556
Copy link
Contributor

@elraphty Please assign me?

You have to finish this within a day

Sure

@MahtabBukhari
Copy link
Contributor

@elraphty please next assign me?

@elraphty it should be first comment person

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.

4 participants