. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("AssignTemplateHandler", func() { var ( handler notifications.AssignTemplateHandler templateAssigner *mocks.TemplateAssigner errorWriter *mocks.ErrorWriter context stack.Context database *mocks.Database ) BeforeEach(func() { templateAssigner = mocks.NewTemplateAssigner() errorWriter = mocks.NewErrorWriter() database = mocks.NewDatabase() context = stack.NewContext() context.Set("database", database) handler = notifications.NewAssignTemplateHandler(templateAssigner, errorWriter) }) It("associates a template with a notification", func() { body, err := json.Marshal(map[string]string{ "template": "my-template", }) if err != nil { panic(err) }
. "github.com/onsi/gomega" ) var _ = Describe("Routes", func() { var muxer web.Muxer BeforeEach(func() { muxer = web.NewMuxer() clients.Routes{ RequestCounter: middleware.RequestCounter{}, RequestLogging: middleware.RequestLogging{}, DatabaseAllocator: middleware.DatabaseAllocator{}, NotificationsManageAuthenticator: middleware.Authenticator{Scopes: []string{"notifications.manage"}}, ErrorWriter: mocks.NewErrorWriter(), TemplateAssigner: mocks.NewTemplateAssigner(), }.Register(muxer) }) It("routes PUT /clients/{client_id}/template", func() { request, err := http.NewRequest("PUT", "/clients/some-client-id/template", nil) Expect(err).NotTo(HaveOccurred()) s := muxer.Match(request).(stack.Stack) Expect(s.Handler).To(BeAssignableToTypeOf(clients.AssignTemplateHandler{})) ExpectToContainMiddlewareStack(s.Middleware, middleware.RequestLogging{}, middleware.RequestCounter{}, middleware.Authenticator{}, middleware.DatabaseAllocator{}) authenticator := s.Middleware[2].(middleware.Authenticator) Expect(authenticator.Scopes).To(Equal([]string{"notifications.manage"})) }) })