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 TestDeleteTribe 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 TestDeleteTribe 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 TestDeleteTribe test cases e.g. mockDb.On("UpdateTribe", mock.Anything, map[string]interface{}{"deleted": true}).Return(true).
Change the database parameter in tHandler := NewTribeHandler(mockDb) to tHandler := NewTribeHandler(db.TestDb)
Create a user using the db.TestDb.CreateOrEditPerson() function e.g.
person := db.Person{
Uuid: ${person_uuid},
OwnerAlias: ${person_alias},
UniqueName: ${person_unique_name},
OwnerPubKey: ${person_pubkey},
PriceToMeet: 0,
Description: "this is test user 1",
}
db.TestDb.CreateOrEditPerson(person)
Create a tribe using the db.TestDb.CreateOrEditTribe() function e.g
Context
Currently, we test the TestDeleteTribe 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:
TestDeleteTribe
to connect to the Test DBThe test will throw a dereference error if not connected to a DB.
TestDeleteTribe
test cases e.g.mockDb.On("UpdateTribe", mock.Anything, map[string]interface{}{"deleted": true}).Return(true)
.tHandler := NewTribeHandler(mockDb)
totHandler := NewTribeHandler(db.TestDb)
db.TestDb.CreateOrEditPerson()
function e.g.db.TestDB.Get(tribe.UUID)
functionmockUUID
values frommockUUID:= "valid_uuid"
tomockUUID := tribe.AppURL
mockOwnerPubKey
values frommockOwnerPubKey= "valid_uuid"
tomockOwnerPubKey:= person.OwnerPubkey
db.TestDB.GetTribe(tribe.UUID)
functionAssertions
Acceptance Criteria
TestDeleteTribe
TestDeleteTribe
refactor passesTestDeleteTribe
should not break existing test flows.Here is an example Real DB Test
The text was updated successfully, but these errors were encountered: