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

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

Refactor Test For TestMakeBountyPayment To Use A Real Postgres DB For The Test #1855

elraphty opened this issue Jul 5, 2024 · 8 comments · Fixed by #1857
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jul 5, 2024

Context

Currently, we test the TestMakeBountyPayment 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 TestMakeBountyPayment 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)
  • Create a new bounty using the db.TestDb.CreateOrEditBounty() function e.g
bountyAmount := 3000
bounty := db.Bounty{
        OwnerId: ${owner_pubkey}
        Price:  bountyAmount,
        Created: &now,
        Type:          "coding",
	Title:         ${bountyTitle},
	Description:   ${bountyDescription},
	Assignee:    ${assigneePubkey},
	Show:          true,
        WorkspaceUuid: workspace.Uuid,
        Paid: false,
        Created: &now,
}
db.TestDb.CreateOrEditBounty(bounty)
  • Get the bounty created by using the dbBounty := db.TestDb.GetBountyDataByCreated(bounty.Created) function
  • 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/pay/{dbBounty.ID}", bountyHandler.MakeBountyPayment)
  • After the request is successful, get the bounty by using the db.TestDb.GetBountyByCreated(bounty.Created) function
  • Get the workspace budget by using the db.TestDb.GetWorkspaceBudget(workspace.Uuid) function
  • Assert that the bounty is Paid value is set to true
  • Assert that the bounty 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 TestMakeBountyPayment
  • All test cases after the TestMakeBountyPayment refactor passes
  • The Refactoring of TestMakeBountyPayment 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

@elraphty
Copy link
Contributor Author

elraphty commented Jul 5, 2024

@AbdulWahab3181

@aliraza556
Copy link
Contributor

aliraza556 commented Jul 5, 2024

@elraphty Please assign me next one?

@saithsab877
Copy link
Contributor

@elraphty Could you assign me next one?

@MirzaHanan
Copy link
Contributor

@elraphty Assign me?

@AbdulWahab3181
Copy link
Contributor

@elraphty Could you please assign me?

@aliraza556
Copy link
Contributor

@elraphty Please assign me next one?

Thanks

@AhsanFarooqDev
Copy link
Contributor

@elraphty Please assign next to next one please?

@saithsab877
Copy link
Contributor

saithsab877 commented Jul 5, 2024

@elraphty Could you please assign me next to next one please?

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