Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TestGetWorkspaceBudgetHistory To Use A Real Postgres DB For The Test #1755

Closed
6 tasks
elraphty opened this issue Jun 25, 2024 · 3 comments · Fixed by #1762
Closed
6 tasks

Refactor TestGetWorkspaceBudgetHistory To Use A Real Postgres DB For The Test #1755

elraphty opened this issue Jun 25, 2024 · 3 comments · Fixed by #1762
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

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) to oHandler := 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" to workspaceUUID := 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 Uuid workspaceUUID := 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
Copy link
Contributor

saithsab877 commented Jun 25, 2024

@elraphty assign me?

@AbdulWahab3181
Copy link
Contributor

AbdulWahab3181 commented Jun 25, 2024

@elraphty Could you please assign me?

@AbdulWahab3181
Copy link
Contributor

@elraphty Could you please assign me the next one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
3 participants