Refactor TestGetWorkspaceBudgetHistory To Use A Real Postgres DB For The Test
Closed this issue · 3 comments
elraphty commented
Context
Currently, we test the TestGetWorkspaceBudgetHistory 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
TestGetWorkspaceBudgetHistory
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
TestGetWorkspaceBudgetHistory
test cases e.g.mockDb.On("ProcessDeleteWorkspace", workspaceUUID).Return(nil).Once()
. - Change the database parameter in
oHandler := NewWorkspaceHandler(mockDb)
tooHandler := NewWorkspaceHandler(db.TestDb)
- Create a workspace by using the
db.TestDb.CreateOrEditWorkspace()
function e.g
workspace := db.Workspace{
Uuid: "workspace_uuid_history",
Name: "Workspace History Name"
OwnerPubKey: "workspace_owner_history_pubkey",
Github: "https://github.com/history"
Website: "https://www.historywebsite.com",
Description: "Workspace History Description",
}
db.TestDB.CreateOrEditWorkspace(workspace)
- Add Workspace budget linked to the workspace with the
db.TestDB.CreateWorkspaceBudget()
function e.g
budgetAmount := 5000;
bounty := db.NewBountyBudget{
WorkspaceUuid: workspace.Uuid,
TotalBudget: budgetAmount
}
db.TestDB.CreateWorkspaceBudget((bounty)
- Add a payment history using the
db.TestDB.AddPaymentHistory()
function e.g
now := time.Now()
paymentHistory := NewPaymentHistory{
WorkspaceUuid: workspace.Uuid,
Amount: budgetAmount,
Status: true,
PaymentType: "budget",
Created: &now,
Updated: &now,
SenderPubKey: workspace.OwnerPubkey,
ReceiverPubKey: "",
BountyId: 0,
}
db.TestDB.AddPaymentHistory(paymentHistory)
- Get the workspace created by using
workspace:= db.TestDb.GetWorkspaceByUuid(workspace.Uuid)
- Change the workspaceUUID
workspaceUUID := "org-uuid"
toworkspaceUUID := workspace.Uuid
- Assert that the workspace is returned and the length is equal to 1
- Assert that the workspace returned is equal to the one created
- Change
workspaceUUID
value to the workspace UuidworkspaceUUID := workspace.Uuid
- Assert that the workspace payment history array length is equal to 1.
- Assert that the payment in history is equal to the one created.
Assertions
- Assert that all the test passes
Acceptance Criteria
- Do not delete any of the existing test cases on the
TestGetWorkspaceBudgetHistory
- All test cases after the
TestGetWorkspaceBudgetHistory
refactor passes - The Refactoring of
TestGetWorkspaceBudgetHistory
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
saithsab877 commented
@elraphty assign me?
AbdulWahab3181 commented
@elraphty Could you please assign me?
AbdulWahab3181 commented
@elraphty Could you please assign me the next one?