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 Test For TestBountyBudgetWithdraw To Use A Real Postgres DB For The Test #1856

Closed
6 tasks
elraphty opened this issue Jul 5, 2024 · 7 comments · Fixed by #1858
Closed
6 tasks

Refactor Test For TestBountyBudgetWithdraw To Use A Real Postgres DB For The Test #1856

elraphty opened this issue Jul 5, 2024 · 7 comments · Fixed by #1858
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jul 5, 2024

Context

Currently, we test the TestBountyBudgetWithdraw 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 TestBountyBudgetWithdraw 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 TTestPollInvoice test cases e.g. mockDb.On("ProcessBountyPayment", mock.AnythingOfType("db.NewPaymentHistory"), mock.AnythingOfType("db.NewBounty")).Return(nil).
  • Change the database parameter in bHandler := NewBountyHandler(mockHttpClient, mockDb) to bHandler := NewBountyHandler(mockHttpClient, db.TestDb)
  • Create a person using the db.TestDb.CreateOrPerson() function e.g
person := db.Person{
     Uuid:        ${uuid},
     OwnerAlias:  ${alias},
     UniqueName:  ${unique_name},
     OwnerPubKey:  ${pubkey},
     PriceToMeet: 0,
     Description:  ${description},
}

db.TestDb.CreateOrEditPerson(person)
  • Create a workspace by using the db.TestDb.CreateOrEditWorkspace() function e.g
workspace := db.Workspace{
   Uuid:   ${workspace_uuid},
   Name:   ${workspace_name},
   OwnerPubKey:  ${person.OwnerPubkey},
   Github: ${gtihub},
   Website: ${website},
   Description: ${description},
}
db.TestDB.CreateOrEditWorkspace(workspace)
  • Get the workspace created by using workspace:= db.TestDb.GetWorkspaceByUuid(workspace.Uuid)
  • 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)
  • Change the withdrawRequest OrgUuid value to wokspace.Uuid e.g
withdrawRequest := db.WithdrawBudgetRequest{
	PaymentRequest: invoice,
	OrgUuid:        workspace.Uuid,
}
  • Change the authorizedCtx value from authorizedCtx := context.WithValue(ctx, auth.ContextKey, "valid-key") to authorizedCtx := context.WithValue(ctx, auth.ContextKey, person.OwnerPubkey)
  • Change the route payment request param to the bounty Id e.g. r.Post("gobounties/budget/withdraw", bountyHandler.BountyBudgetWithdraw)
  • After the request is successful, Get the workspace budget by using the db.TestDb.GetWorkspaceBudget(workspace.Uuid) function
  • Assert that the invoice amount is deducted from the Workspace budget

Assertions

  • Assert that all the test passes

Acceptance Criteria

  • Do not delete any of the existing test cases on the TestBountyBudgetWithdraw
  • All test cases after the TestBountyBudgetWithdraw refactor passes
  • The Refactoring of TestBountyBudgetWithdraw 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

@elraphty Could you please assign me?

@AhsanFarooqDev
Copy link
Contributor

AhsanFarooqDev commented Jul 5, 2024

@elraphty please assign next one please

@elraphty
Copy link
Contributor Author

elraphty commented Jul 5, 2024

@aliraza556

@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Jul 5, 2024

@elraphty Could you please assign me?

@aliraza556
Copy link
Contributor

aliraza556 commented Jul 5, 2024

@elraphty Please assign me?

@MahtabBukhari
Copy link
Contributor

@aliraza556

@elraphty Could you please assign next bounty?

@saithsab877
Copy link
Contributor

@elraphty Could you please assign me?

@elraphty Could you please assign next bounty?

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