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

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

Refactor TestDeleteTribe To Use A Real Postgres DB For The Test #1767

elraphty opened this issue Jun 26, 2024 · 3 comments · Fixed by #1769
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jun 26, 2024

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 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
    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 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
tribe := db.Tribe{
    UUID: ${tribe_uuid}, 
    OwnerPubKey:  ${pubkey},
    Name:  ${name},
    Description: ${description}
    Tags: []string{"tag3", "tag4"}
    AppUrl: ${AppURl}
}
db.TestDb.CreateOrEditTribe(tribe)
  • Get the created tribe using the db.TestDB.Get(tribe.UUID) function
  • Assert that the tribe created is equals to the one returned
  • Update the mockUUID values from mockUUID:= "valid_uuid" to mockUUID := tribe.AppURL
  • Update the mockOwnerPubKey values from mockOwnerPubKey= "valid_uuid" to mockOwnerPubKey:= person.OwnerPubkey
  • Assert that Deletion, get the created tribe using the db.TestDB.GetTribe(tribe.UUID) function
  • Assert that an empty object is returned
  • Assert that the response response is equal to true

Assertions

  • Assert that all the test passes

Acceptance Criteria

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

@aliraza556
Copy link
Contributor

@elraphty Please assign me?

@saithsab877
Copy link
Contributor

HI @elraphty assign me next one?

@MirzaHanan
Copy link
Contributor

Hi @elraphty Next assign me?

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

Successfully merging a pull request may close this issue.

4 participants