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

Write Test For GetUserDropdownWorkspaces #1805

Closed
4 tasks
elraphty opened this issue Jul 1, 2024 · 6 comments · Fixed by #1852
Closed
4 tasks

Write Test For GetUserDropdownWorkspaces #1805

elraphty opened this issue Jul 1, 2024 · 6 comments · Fixed by #1852
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jul 1, 2024

Context

Currently, we do not have a test for GetUserDropdownWorkspaces

Design

We want to write 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 TestGetUserDropdownWorkspaces to connect to the Test DB
    teardownSuite := SetupSuite(t)
    defer teardownSuite(t)

    oHandler := NewWorkspaceHandler(mockDb)` to `oHandler := NewWorkspaceHandler(db.TestDb)

The test will throw a dereference error if not connected to a DB.

  • Create 2 persons using the db.TestDb.CreateOrPerson() function e.g
person := db.Person{
     Uuid:        ${uuid},
     OwnerAlias:  ${alias},
     UniqueName:  ${unique_name},
     OwnerPubKey:  ${pubkey},
     PriceToMeet: 0,
     Description:  ${description},
}

person2 := db.Person{
     Uuid:        ${uuid},
     OwnerAlias:  ${alias},
     UniqueName:  ${unique_name},
     OwnerPubKey:  ${pubkey},
     PriceToMeet: 0,
     Description:  ${description},
}
db.TestDb.CreateOrEditPerson(person)
db.TestDb.CreateOrEditPerson(person2)
  • 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)
  • Create a variable roles e.g
roles := []db.WorkspaceUserRoles{
	db.WorkspaceUserRoles{
		WorkspaceUuid: ${uuid},
		OwnerPubKey:  ${pubkey},
		Role:          "ADD BOUNTY",
	},
	db.WorkspaceUserRoles{
		WorkspaceUuid: ${uuid},
		OwnerPubKey:  ${pubkey},
		Role:          "UPDATE BOUNTY",
	},
	db.WorkspaceUserRoles{
		WorkspaceUuid: ${uuid},
		OwnerPubKey:  ${pubkey},
		Role:          "DELETE BOUNTY",
	},
	db.WorkspaceUserRoles{
		WorkspaceUuid: ${uuid},
		OwnerPubKey:  ${pubkey},
		Role:          "PAY BOUNTY",
	},
}
  • Add the roles to person2 using the db.TestDb.CreateUserRoles(roles, workspace.Uuid, person2.OwnerPubkey) function
  • Get person2 details by using the db function dbPerson := db.TestDb.GetPersonByUuid(person2.Uuid)
  • Create a test route using r.Get("/user/dropdown/{userId}", workspaceHandlers.GetUserDropdownWorkspaces) as a reference, the test route
  • The {userId} parameter in the route should be dbPerson.ID

Assertions

  • Assert that the workspace created is returned from the GetUserDropdownWorkspaces API request
  • Assert that all the test passes

Acceptance Criteria

  • 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

@AbdulWahab3181
Copy link
Contributor

@elraphty Could you please assign me?

@elraphty
Copy link
Contributor Author

elraphty commented Jul 1, 2024

@MuhammadUmer44 you can have this

@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Jul 1, 2024

@elraphty Could you please assign me next one?

@MuhammadUmer44
Copy link
Contributor

MuhammadUmer44 commented Jul 1, 2024

@elraphty assign me?

@elraphty
Copy link
Contributor Author

elraphty commented Jul 1, 2024

@elraphty Could you please assign me?

@AbdulWahab3181 you have one already

@saithsab877
Copy link
Contributor

@elraphty Please assign me next one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants