BeforeEach(func() { writer = httptest.NewRecorder() request = &http.Request{URL: &url.URL{Path: "/uaa_scopes/great.scope"}} strategy = mocks.NewStrategy() errorWriter = mocks.NewErrorWriter() connection = mocks.NewConnection() database := mocks.NewDatabase() database.ConnectionCall.Returns.Connection = connection context = stack.NewContext() context.Set("database", database) context.Set(notify.VCAPRequestIDKey, "some-request-id") notifyObj = mocks.NewNotify() handler = notify.NewUAAScopeHandler(notifyObj, errorWriter, strategy) }) Context("when the notifyObj.Execute returns a successful response", func() { It("returns the JSON representation of the response", func() { notifyObj.ExecuteCall.Returns.Response = []byte("whatever") handler.ServeHTTP(writer, request, context) Expect(writer.Code).To(Equal(http.StatusOK)) Expect(writer.Body.String()).To(Equal("whatever")) }) It("delegates to the notifyObj object with the correct arguments", func() { handler.ServeHTTP(writer, request, context)
"github.com/cloudfoundry-incubator/notifications/v1/web/middleware" "github.com/cloudfoundry-incubator/notifications/v1/web/notify" "github.com/cloudfoundry-incubator/notifications/web" "github.com/ryanmoran/stack" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Routes", func() { var muxer web.Muxer BeforeEach(func() { muxer = web.NewMuxer() notify.Routes{ Notify: mocks.NewNotify(), ErrorWriter: mocks.NewErrorWriter(), UserStrategy: mocks.NewStrategy(), SpaceStrategy: mocks.NewStrategy(), OrganizationStrategy: mocks.NewStrategy(), EveryoneStrategy: mocks.NewStrategy(), UAAScopeStrategy: mocks.NewStrategy(), EmailStrategy: mocks.NewStrategy(), RequestCounter: middleware.RequestCounter{}, RequestLogging: middleware.RequestLogging{}, DatabaseAllocator: middleware.DatabaseAllocator{}, NotificationsWriteAuthenticator: middleware.Authenticator{Scopes: []string{"notifications.write"}}, EmailsWriteAuthenticator: middleware.Authenticator{Scopes: []string{"emails.write"}}, }.Register(muxer) })