var _ = Describe("CreateHandler", func() {
	var (
		err         error
		handler     templates.CreateHandler
		writer      *httptest.ResponseRecorder
		request     *http.Request
		context     stack.Context
		creator     *mocks.TemplateCreator
		errorWriter *mocks.ErrorWriter
		database    *mocks.Database
	)

	Describe("ServeHTTP", func() {
		BeforeEach(func() {
			creator = mocks.NewTemplateCreator()
			creator.CreateCall.Returns.TemplateGUID = "template-guid"
			errorWriter = mocks.NewErrorWriter()
			writer = httptest.NewRecorder()
			body := bytes.NewBuffer([]byte{})
			err := json.NewEncoder(body).Encode(map[string]interface{}{
				"name":    "Emergency Template",
				"text":    "Message to: {{.To}}. Raptor Alert.",
				"html":    "<p>{{.ClientID}} you should run.</p>",
				"subject": "Raptor Containment Unit Breached",
			})
			Expect(err).NotTo(HaveOccurred())

			database = mocks.NewDatabase()
			context = stack.NewContext()
			context.Set("database", database)
Esempio n. 2
0
	"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()
		templates.Routes{
			ErrorWriter:               mocks.NewErrorWriter(),
			TemplateFinder:            mocks.NewTemplateFinder(),
			TemplateUpdater:           mocks.NewTemplateUpdater(),
			TemplateCreator:           mocks.NewTemplateCreator(),
			TemplateDeleter:           mocks.NewTemplateDeleter(),
			TemplateLister:            mocks.NewTemplateLister(),
			TemplateAssociationLister: mocks.NewTemplateAssociationLister(),

			RequestCounter:                          middleware.RequestCounter{},
			RequestLogging:                          middleware.RequestLogging{},
			DatabaseAllocator:                       middleware.DatabaseAllocator{},
			NotificationsManageAuthenticator:        middleware.Authenticator{Scopes: []string{"notifications.manage"}},
			NotificationTemplatesReadAuthenticator:  middleware.Authenticator{Scopes: []string{"notification_templates.read"}},
			NotificationTemplatesWriteAuthenticator: middleware.Authenticator{Scopes: []string{"notification_templates.write"}},
		}.Register(muxer)
	})

	Describe("/templates", func() {
		It("routes GET /templates", func() {