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 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
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
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.
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 thetest_config.go
configuration.After spinning up the Postgres DB container:
TestBountyMetrics
to connect to the Test DBThe test will throw a dereference error if not connected to a DB.
TestBountyMetrics
test cases e.g.mockDb.On("TotalBountiesPosted", dateRange, workspace).Return(int64(1)).Once()
.mh := NewMetricHandler(mockDb)
tomh := NewMetricHandler(db.TestDb)
db.TestDb.CreateOrEditBounty()
e.g2 Bounties, should be set to
Paid: true
, while the Other 2 should be set asPaid: false
, and theCreated
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.dateRange
StartDate and EndDate values to be theCreated
date of the first bounty and theCreated
date of the last bounty e.g.expectedMetricRes
, the value should beAssertions
Acceptance Criteria
TestBountyMetrics
TestBountyMetrics
refactor passesTestBountyMetrics
should not break existing test flows.Here is an example Real DB Test
The text was updated successfully, but these errors were encountered: