}) It("Does not try to update service plans if the org already did not have visibility", func() { serviceBuilder.GetServiceByNameWithPlansReturns(privateService, nil) err := actor.UpdateOrgForService("my-private-service", "org-1", false) Expect(err).ToNot(HaveOccurred()) Expect(servicePlanVisibilityRepo.DeleteCallCount()).To(Equal(0)) }) }) }) Describe(".UpdateSinglePlanForService", func() { It("Returns an error if the service cannot be found", func() { serviceBuilder.GetServiceByNameWithPlansReturns(models.ServiceOffering{}, errors.New("service was not found")) err := actor.UpdateSinglePlanForService("not-a-service", "public-service-plan", true) Expect(err.Error()).To(Equal("service was not found")) }) It("Returns an error if the plan cannot be found", func() { serviceBuilder.GetServiceByNameWithPlansReturns(mixedService, nil) err := actor.UpdateSinglePlanForService("my-mixed-service", "not-a-service-plan", true) Expect(err.Error()).To(Equal("The plan not-a-service-plan could not be found for service my-mixed-service")) }) Context("when setting a public service plan to public", func() { It("Does not try to update the service plan", func() { serviceBuilder.GetServiceByNameWithPlansReturns(mixedService, nil) err := actor.UpdateSinglePlanForService("my-mixed-service", "public-service-plan", true) Expect(err).ToNot(HaveOccurred()) Expect(servicePlanRepo.UpdateCallCount()).To(Equal(0))
It("Does not try to update service plans if the org already did not have visibility", func() { serviceBuilder.GetServiceByNameForOrgReturns(privateService, nil) allPlansWereSet, err := actor.UpdateOrgForService("my-private-service", "org-1", false) Expect(err).ToNot(HaveOccurred()) Expect(servicePlanVisibilityRepo.DeleteCallCount()).To(Equal(0)) Expect(allPlansWereSet).To(BeTrue()) }) }) }) Describe(".UpdateSinglePlanForService", func() { It("Returns an error if the service cannot be found", func() { serviceBuilder.GetServiceByNameWithPlansReturns(models.ServiceOffering{}, errors.New("service was not found")) _, err := actor.UpdateSinglePlanForService("not-a-service", "public-service-plan", true) Expect(err.Error()).To(Equal("service was not found")) }) It("Returns None if the original plan was private", func() { serviceBuilder.GetServiceByNameWithPlansReturns(privateService, nil) originalAccessValue, err := actor.UpdateSinglePlanForService("my-mixed-service", "private-service-plan", true) Expect(err).NotTo(HaveOccurred()) Expect(originalAccessValue).To(Equal(actors.None)) }) It("Returns All if the original plan was public", func() { serviceBuilder.GetServiceByNameWithPlansReturns(mixedService, nil) originalAccessValue, err := actor.UpdateSinglePlanForService("my-mixed-service", "public-service-plan", true) Expect(err).NotTo(HaveOccurred()) Expect(originalAccessValue).To(Equal(actors.All))