Beispiel #1
0
	. "github.com/onsi/gomega"
)

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{})
Beispiel #2
0
			BeforeEach(func() {
				client = models.Client{
					ID:          "mister-client",
					Description: "Health Monitor",
				}
				kind = models.Kind{
					ID:          "test_email",
					Description: "Instance Down",
					ClientID:    "mister-client",
					Critical:    true,
				}
				finder = mocks.NewNotificationsFinder()
				finder.ClientAndKindCall.Returns.Client = client
				finder.ClientAndKindCall.Returns.Kind = kind

				registrar = mocks.NewRegistrar()

				body, err := json.Marshal(map[string]string{
					"kind_id":  "test_email",
					"text":     "This is the plain text body of the email",
					"html":     "<!DOCTYPE html><html><head><script type='javascript'></script></head><body class='hello'><p>This is the HTML Body of the email</p><body></html>",
					"subject":  "Your instance is down",
					"reply_to": "*****@*****.**",
				})
				if err != nil {
					panic(err)
				}

				tokenHeader = map[string]interface{}{
					"alg": "FAST",
				}