context.Set("database", database) builder = services.NewPreferencesBuilder() builder.Add(models.Preference{ ClientID: "raptorClient", KindID: "hungry-kind", Email: false, }) builder.Add(models.Preference{ ClientID: "starWarsClient", KindID: "vader-kind", Email: true, }) builder.GlobalUnsubscribe = true preferencesFinder = mocks.NewPreferencesFinder() preferencesFinder.FindCall.Returns.PreferencesBuilder = builder handler = preferences.NewGetPreferencesHandler(preferencesFinder, errorWriter) }) It("passes the proper user guid into execute", func() { handler.ServeHTTP(writer, request, context) Expect(preferencesFinder.FindCall.Receives.Database).To(Equal(database)) Expect(preferencesFinder.FindCall.Receives.UserGUID).To(Equal("correct-user")) }) It("returns a proper JSON response when the Preference object does not error", func() { handler.ServeHTTP(writer, request, context)
"github.com/cloudfoundry-incubator/notifications/v1/web/preferences" "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() preferences.Routes{ ErrorWriter: mocks.NewErrorWriter(), PreferencesFinder: mocks.NewPreferencesFinder(), PreferenceUpdater: mocks.NewPreferenceUpdater(), CORS: middleware.CORS{}, RequestCounter: middleware.RequestCounter{}, RequestLogging: middleware.RequestLogging{}, DatabaseAllocator: middleware.DatabaseAllocator{}, NotificationPreferencesReadAuthenticator: middleware.Authenticator{Scopes: []string{"notification_preferences.read"}}, NotificationPreferencesAdminAuthenticator: middleware.Authenticator{Scopes: []string{"notification_preferences.admin"}}, NotificationPreferencesWriteAuthenticator: middleware.Authenticator{Scopes: []string{"notification_preferences.write"}}, }.Register(muxer) }) Describe("/user_preferences", func() { It("routes GET /user_preferences", func() { request, err := http.NewRequest("GET", "/user_preferences", nil)