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

Closed
6 tasks
elraphty opened this issue Jun 28, 2024 · 6 comments · Fixed by #1801
Closed
6 tasks

Refactor TestBountyMetrics To Use A Real Postgres DB For The Test #1792

elraphty opened this issue Jun 28, 2024 · 6 comments · Fixed by #1801
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jun 28, 2024

Context

Currently, we test the TestBountyMetrics 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 TestBountyMetrics 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 TestBountyMetrics test cases e.g. mockDb.On("TotalBountiesPosted", dateRange, workspace).Return(int64(1)).Once().
  • Change the database parameter in mh := NewMetricHandler(mockDb) to mh := NewMetricHandler(db.TestDb)
  • Delete all bounties in the TestDB
  • Create 4 bounties 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,
        Paid: true
}
db.TestDb.CreateOrEditBounty(bounty)
bounty2  :=  db.NewBounty{
	Type:          "coding",
	Title:         "Bounty With ID",
	Description:   "Bounty ID Description",
	WorkspaceUuid: "",
	Assignee:      "",
	OwnerID:       bountyOwner.OwnerPubKey,
	Show:          true,
        Created: &now,
}
db.TestDb.CreateOrEditBounty(bounty2)

2 Bounties, should be set to Paid: true, while the Other 2 should be set as Paid: false, and the Created time value of the 4 bounties should be within 30 days i.e, the first bounty and the last bounties should be 30 days apart, use Golang date manipulation to achieve this.

  • Change the dateRange StartDate and EndDate values to be the Created date of the first bounty and the Created date of the last bounty e.g.
dateRange := db.PaymentDateRange{
   StartDate:  bounty.Created,
   EndDate:   bounty4.Created,
}
  • Create a variable expectedMetricRes, the value should be
expectedMetricRes := db.BountyMetrics{
	BountiesPosted:         4,
	BountiesPaid:           2,
	BountiesAssigned:     4,
	BountiesPaidPercentage: 50,
	SatsPosted:          ${Sum of posted bounties amount} ,
	SatsPaid:               ${Sum of paid bounties amount},
	SatsPaidPercentage:    ${Sum of paid bounties amount * 100 / Sum of bounties amount Posted},
        AveragePaid:            0,
	AverageCompleted:       0,
	UniqueHuntersPaid:      ${number of unique bounties assignees},
	NewHuntersPaid:         ${number of new bounties assignees},
}

Assertions

  • Assert that the data returned from the API request matches expectedMetricRes.

Acceptance Criteria

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

@elraphty
Copy link
Contributor Author

@aliraza556

@aliraza556
Copy link
Contributor

@elraphty assign me?

@MirzaHanan
Copy link
Contributor

@elraphty assign me next issue?

@saithsab877
Copy link
Contributor

@elraphty Could you assign me next issue?

@AbdulWahab3181
Copy link
Contributor

AbdulWahab3181 commented Jun 28, 2024

@elraphty Could you please assign me?

@AbdulWahab3181
Copy link
Contributor

@elraphty Can I take this one Incase @aliraza556 is unable to complete it?

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