}

			rawToken := helpers.BuildToken(tokenHeader, tokenClaims)
			request.Header.Set("Authorization", "Bearer "+rawToken)

			token, err := jwt.Parse(rawToken, func(*jwt.Token) (interface{}, error) {
				return []byte(application.UAAPublicKey), nil
			})
			Expect(err).NotTo(HaveOccurred())

			context = stack.NewContext()
			context.Set("token", token)
			context.Set("database", database)

			errorWriter = mocks.NewErrorWriter()
			updater = mocks.NewPreferenceUpdater()
			writer = httptest.NewRecorder()

			handler = preferences.NewUpdatePreferencesHandler(updater, errorWriter)
		})

		It("Passes The Correct Arguments to PreferenceUpdater Execute", func() {
			handler.ServeHTTP(writer, request, context)
			Expect(reflect.ValueOf(updater.ExecuteCall.Receives.Connection).Pointer()).To(Equal(reflect.ValueOf(transaction).Pointer()))

			preferencesArguments := updater.ExecuteCall.Receives.Preferences

			Expect(preferencesArguments).To(ContainElement(models.Preference{
				ClientID: "raptors",
				KindID:   "door-opening",
				Email:    false,
Beispiel #2
0
	"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)
			Expect(err).NotTo(HaveOccurred())