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

Add DELETE for org in a Service Plan Visibility #3650

Merged
merged 4 commits into from
Jan 10, 2025

Conversation

klapkov
Copy link
Contributor

@klapkov klapkov commented Dec 3, 2024

Is there a related GitHub Issue?

#3645

What is this change about?

Here we add the ability to remove an organization from a service plan visibility

Does this PR introduce a breaking change?

No

Acceptance Steps

Tag your pair, your PM, and/or team

@klapkov klapkov changed the title Add DELETE v3/service_plans/:guid/visibility/:org_guid Add DELETE for org in a Service Plan Visibility Dec 3, 2024
@klapkov klapkov force-pushed the delete_plan_visibility branch from 804fba2 to 2922cb8 Compare December 3, 2024 12:12
Copy link
Member

@georgethebeatle georgethebeatle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments inline

@@ -350,4 +351,46 @@ var _ = Describe("ServicePlan", func() {
})
})
})

Describe("DELETE /v3/service_plans/{guid}/visibility/{org-guid}", func() {
BeforeEach(func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This BeforeEach is unnecessary as the service plan repository fake will return nil by default

ServicePlanVisivilityPath = "/v3/service_plans/{guid}/visibility"
ServicePlansPath = "/v3/service_plans"
ServicePlanVisibilityPath = "/v3/service_plans/{guid}/visibility"
ServicePlanVisibilityOrgPath = ServicePlanVisibilityPath + "/{org-guid}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion it would be more readable if the path is a plain single string:

ServicePlanVisibilityOrgPath = "/v3/service_plans/{guid}/visibility/{org-guid}"

Having it plain makes it easier to get what endpoints are implemented with a single glance. It also makes it easier to extract this information with a script

Expect(rr).To(HaveHTTPStatus(http.StatusNoContent))
})

When("deleting the visibility fails with not found", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handler does not process not found any differently than a generic error, so this test does not add more value then the one below.


When("the user is not authorized", func() {
BeforeEach(func() {
visibilityErr = repo.DeletePlanVisibility(ctx, authInfo, repositories.DeleteServicePlanVisibilityMessage{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could go to a Describe-global JustBeforeEach as it is invoking the code under test. This will also reduce duplication

},
}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(servicePlan), servicePlan)).To(Succeed())
Expect(servicePlan.Spec.Visibility.Organizations).To(Equal([]string{cfOrg.Name}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we could conveniently use gomega's ConsistOf matcher

Expect(servicePlan.Spec.Visibility.Organizations).To(ConsistOf(cfOrg.Name))

},
}
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(servicePlan), servicePlan)).To(Succeed())
Expect(servicePlan.Spec.Visibility.Organizations).To(Equal([]string{cfOrg.Name, anotherOrg.Name}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment about usingConsistsOf

@danail-branekov
Copy link
Member

danail-branekov commented Dec 9, 2024

In addition to @georgethebeatle's comments, as this is a new endpoint, I would also like to have an e2e test that excercises deleting orgs from plan visibility

PS: In the spirit of e2e tests, the new test should cover the very basic happy path, i.e. don't bother testing error cases (not authorised, or org not found)

@klapkov klapkov force-pushed the delete_plan_visibility branch from a31e6c6 to f5df5f7 Compare December 10, 2024 11:04
@klapkov
Copy link
Contributor Author

klapkov commented Dec 10, 2024

@danail-branekov @georgethebeatle Did some changes, let me know if all is good so I can fix the conflicts.

Copy link
Member

@danail-branekov danail-branekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some comments on the tests sctrucuture, looks all right otherwise.

})

When("the plan does not exist", func() {
JustBeforeEach(func() {
Copy link
Member

@danail-branekov danail-branekov Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you create a variable for the delete message and default it to the value you use in the describe's JustBeforeEach in the BeforeEach, then in each context's BeforeEach you could just override the message and not invoke the method under test (DeleteServicePlanVisibility) over and over again.

I.e.

Describe("DeletePlanVisibility", func() {
  var deleteMessage repositories.DeleteServicePlanVisibilityMessage
  BeforeEach(func(){
    deleteMessage = repositories.DeleteServicePlanVisibilityMessage{
					PlanGUID: planGUID,
					OrgGUID:  anotherOrg.Name,
				}

  })

  JustBeforeEach(func(){
     visibilityErr = repo.DeletePlanVisibility(ctx, authInfo,  deleteMessage)
  })

  .........
  
  When("the plan does not exist", func() {
    BeforeEach(func(){
      deleteMessage.PlanGUID = "i-do-not-exist"
    })

    It(......)
  })

  When("the org does not exist", func() {
    BeforeEach(func(){
      deleteMessage.OrgGUID = "i-do-not-exist"
    })

    It(......)
  })
})

tests/e2e/service_plans_test.go Show resolved Hide resolved
@klapkov klapkov force-pushed the delete_plan_visibility branch from ff64585 to 776ae08 Compare December 12, 2024 14:58
@klapkov
Copy link
Contributor Author

klapkov commented Dec 12, 2024

@danail-branekov Done with the changes

danail-branekov
danail-branekov previously approved these changes Jan 6, 2025
Copy link
Member

@danail-branekov danail-branekov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good, you would unfortunately have to resolve the conflicts

@klapkov klapkov force-pushed the delete_plan_visibility branch 2 times, most recently from 6fba7f0 to 55cdc5e Compare January 8, 2025 16:35
@klapkov klapkov force-pushed the delete_plan_visibility branch from 55cdc5e to c771132 Compare January 8, 2025 17:13
@georgethebeatle georgethebeatle enabled auto-merge (squash) January 10, 2025 12:46
@georgethebeatle georgethebeatle merged commit 6586d45 into cloudfoundry:main Jan 10, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants