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 TestMetricsBountiesCount 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 TestMetricsBountiesCount 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 TestMetricsBountiesCount test cases e.g. mockDb.On("GetBountiesByDateRangeCount", dateRange, req).Return(int64(100)).Once().
Change the database parameter in mh := NewMetricHandler(mockDb) to mh := NewMetricHandler(db.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 TestMetricsBountiesCount 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:
TestMetricsBountiesCount
to connect to the Test DBThe test will throw a dereference error if not connected to a DB.
TestMetricsBountiesCount
test cases e.g.mockDb.On("GetBountiesByDateRangeCount", dateRange, req).Return(int64(100)).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.GetBountiesByDateRangeCount
functionAssertions
Acceptance Criteria
TestMetricsBountiesCount
TestMetricsBountiesCount
refactor passesTestMetricsBountiesCount
should not break existing test flows.Here is an example Real DB Test
The text was updated successfully, but these errors were encountered: