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 CreateOrEditFeaturePhase #1832

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

Write Test For CreateOrEditFeaturePhase #1832

elraphty opened this issue Jul 3, 2024 · 6 comments · Fixed by #1842
Assignees
Labels

Comments

@elraphty
Copy link
Contributor

elraphty commented Jul 3, 2024

Context

Currently, we do not have a test for CreateOrEditFeaturePhase

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

    fHandler := NewFeatureHandler(db.TestDb)

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

  • 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)
  • Create a new feature using the db.TestDB.CreateOrEditFeature() function e.g
feature := db.WorkspaceFeatures {
	Uuid: ${uuid}
	WorkspaceUuid: workspace.UUid,
	Name: ${name},          
	Url: ${url},
        Priority: 0,         
}
db.TestDB.CreateOrEditFeature(feature)
  • Create a variable featurePhase e.g
featurePhase := db.FeaturePhase {
	Uuid: ${uuid}
        FeatureUuid: feature.Uuid,
	Name: ${name},          
        Priority: 0,         
}
  • Create a test route using r.Post("features/phase", featureHandlers.CreateOrEditFeaturePhase) as a reference, the test route
  • JSON marshal featurePhase and pass it as a body to the Endpoint
  • Assert that it throws a 401 error if a user is not authenticated
  • Assert that a 406 error is returned if the wrong body data is sent to the APi endpoint
  • Assert that a 401 is returned if a Feature UUID that does not exist Is passed to the API body
  • Assert that the user can add a feature phase when the right conditions are met.

Assertions

  • Assert that the feature phase is created by using the db.TestDb.GetFeaturePhaseByUuid(featurePhase.Uuid) function
  • Assert that the feature phase Name, Prioty, and FeatureUuid returned matches what was sent in the API body.
  • 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

@AhsanFarooqDev
Copy link
Contributor

AhsanFarooqDev commented Jul 3, 2024

@elraphty please assign please

@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Jul 3, 2024

@elraphty Could you please assign me?

@aliraza556
Copy link
Contributor

aliraza556 commented Jul 3, 2024

@elraphty Please assign me?

@AbdulWahab3181
Copy link
Contributor

AbdulWahab3181 commented Jul 3, 2024

@elraphty Could you please assign me?

@saithsab877
Copy link
Contributor

@elraphty Please assign me the next one?

@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Jul 3, 2024

@elraphty Could you please assign me?

@elraphty Could you please assign 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
Development

Successfully merging a pull request may close this issue.

6 participants