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

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

Refactor TestGetBountyById To Use A Real Postgres DB For The Test #1721

elraphty opened this issue Jun 21, 2024 · 7 comments · Fixed by #1726
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

Context

Currently, we test the TestGetBountyById 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 TestGetBountyById 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 TestGetBountyById 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 bounty using this db function db.TestDb.CreateOrEditBounty() e.g
now := time.Now()
bounty  :=  db.NewBounty{
	Type:          "coding",
	Title:         "Bounty With ID",
	Description:   "Bounty ID description",
	WorkspaceUuid: "",
	Assignee:      "",
	OwnerID:       bountyOwner.OwnerPubKey,
	Show:          true,
        Created: &now
}
db.TestDb.CreateOrEditBounty(bounty)
  • Get the bounty created by using bountyInDb := db.TestDb.GetBountyByCreated(bounty.Created)
  • Assert that the bounty is returned
  • Update the URL id param to the bounty's ID bountyInDb.Id req, err := http.NewRequestWithContext(context.WithValue(context.Background(), chi.RouteCtxKey, rctx), http.MethodGet, "/bounty/1", nil) assert.NoError(t, err)
  • Update the string bountyId value rctx.URLParams.Add("bountyId", strconv.Itoa(int(bounty.ID))) to rctx.URLParams.Add("bountyId", strconv.Itoa(int(bountyInDb.ID)))

Assertions

  • Assert that all the test passes

Acceptance Criteria

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

@MirzaHanan
Copy link
Contributor

MirzaHanan commented Jun 21, 2024

@elraphty Assign

@saithsab877
Copy link
Contributor

saithsab877 commented Jun 21, 2024

@elraphty Please assign me

@AbdulWahab3181
Copy link
Contributor

@elraphty Could you please assign me?

@elraphty
Copy link
Contributor Author

@elraphty Could you please assign me?

@AbdulWahab3181 You get the next one, just comment on it.

@AbdulWahab3181
Copy link
Contributor

@elraphty Could you please assign me?

@AbdulWahab3181 You get the next one, just comment on it.

Ok Thanks

@Shoaibdev7
Copy link
Contributor

@elraphty Please assign me

@elraphty Please assign the next task to me after @AbdulWahab3181.

@AbdulWahab3181
Copy link
Contributor

@elraphty Can I take this one if Mirza is unable to complete it?

@github-project-automation github-project-automation bot moved this from 🆕 New to ✅ Done in Bounties Platform Jun 24, 2024
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.

5 participants