Refactor `TestGetListedTribes` To Use A Real Postgres DB For The Test
Closed this issue · 6 comments
elraphty commented
Context
Currently, we test the TestGetListedTribes
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
TestGetListedTribes
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
TestGetListedTribes
test cases e.g.mockDb.On("GetListedTribes", req).Return(expectedTribes)
. - Change the database parameter in
tHandler := NewTribeHandler(mockDb)
totHandler := NewTribeHandler(db.TestDb)
- Create two tribes, one with
Unlisted: true
, and the other withUnlisted: false
using the db.TestDb.CreateOrEditTribe() function e.g
tribe := db.Tribe{
UUID: ${tribe_uuid},
OwnerPubKey: person.OwnerPubkey,
Name: ${name},
Description: ${description}
Tags: []string{"tag3", "tag4"}
AppUrl: ${AppURl}
Unlisted: true,
}
tribe2 := db.Tribe{
UUID: ${tribe_uuid},
OwnerPubKey: person.OwnerPubkey,
Name: ${name},
Description: ${description}
Tags: []string{"tag3", "tag4"}
AppUrl: ${AppURl}
Unlisted: false,
}
db.TestDb.CreateOrEditTribe(tribe)
db.TestDb.CreateOrEditTribe(tribe2)
- Assert that only tribes with
Unlisted: false
are returned from the API request
Assertions
- Assert that all the test passes
Acceptance Criteria
- Do not delete any of the existing test cases on the
TestGetListedTribes
- All test cases after the
TestGetListedTribes
refactor passes - The Refactoring of
TestGetListedTribes
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
AhsanFarooqDev commented
@elraphty please assign
AbdulWahab3181 commented
@elraphty Could you please assign me?
MuhammadUmer44 commented
@elraphty assign me
MirzaHanan commented
@elraphty PLease assign me?
aliraza556 commented
@elraphty Assign me next one?
AbdulWahab3181 commented
@elraphty Could you please assign me the next issue?