Пример #1
0
		err                 error
		database            *mocks.Database
		context             stack.Context
	)

	BeforeEach(func() {
		errorWriter = mocks.NewErrorWriter()
		writer = httptest.NewRecorder()
		database = mocks.NewDatabase()
		context = stack.NewContext()
		context.Set("database", database)

		request, err = http.NewRequest("GET", "/notifications", nil)
		Expect(err).NotTo(HaveOccurred())

		notificationsFinder = mocks.NewNotificationsFinder()
		handler = notifications.NewListHandler(notificationsFinder, errorWriter)
	})

	Describe("ServeHTTP", func() {
		It("receives the clients/notifications from the finder", func() {
			notificationsFinder.AllClientsAndNotificationsCall.Returns.Clients = []models.Client{
				{
					ID:          "client-123",
					Description: "Jurassic Park",
				},
				{
					ID:          "client-456",
					Description: "Jurassic Park Ride",
				},
			}
Пример #2
0
var _ = Describe("Routes", func() {
	var muxer web.Muxer

	BeforeEach(func() {
		muxer = web.NewMuxer()
		notifications.Routes{
			RequestCounter:                   middleware.RequestCounter{},
			RequestLogging:                   middleware.RequestLogging{},
			DatabaseAllocator:                middleware.DatabaseAllocator{},
			NotificationsWriteAuthenticator:  middleware.Authenticator{Scopes: []string{"notifications.write"}},
			NotificationsManageAuthenticator: middleware.Authenticator{Scopes: []string{"notifications.manage"}},

			Registrar:            mocks.NewRegistrar(),
			ErrorWriter:          mocks.NewErrorWriter(),
			NotificationsFinder:  mocks.NewNotificationsFinder(),
			NotificationsUpdater: &mocks.NotificationUpdater{},
		}.Register(muxer)
	})

	Describe("/notifications", func() {
		It("routes PUT /notifications", func() {
			request, err := http.NewRequest("PUT", "/notifications", nil)
			Expect(err).NotTo(HaveOccurred())

			s := muxer.Match(request).(stack.Stack)
			Expect(s.Handler).To(BeAssignableToTypeOf(notifications.PutHandler{}))
			ExpectToContainMiddlewareStack(s.Middleware, middleware.RequestLogging{}, middleware.RequestCounter{}, middleware.Authenticator{}, middleware.DatabaseAllocator{})

			authenticator := s.Middleware[2].(middleware.Authenticator)
			Expect(authenticator.Scopes).To(Equal([]string{"notifications.write"}))