Example #1
0
	"github.com/cloudfoundry-incubator/notifications/v2/queue"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Determiner", func() {
	var (
		determiner    strategy.Determiner
		userStrategy  *mocks.Strategy
		spaceStrategy *mocks.Strategy
		orgStrategy   *mocks.Strategy
		emailStrategy *mocks.Strategy
		database      *mocks.Database
	)
	BeforeEach(func() {
		userStrategy = mocks.NewStrategy()
		spaceStrategy = mocks.NewStrategy()
		orgStrategy = mocks.NewStrategy()
		emailStrategy = mocks.NewStrategy()
		database = mocks.NewDatabase()
		determiner = strategy.NewStrategyDeterminer(userStrategy, spaceStrategy, orgStrategy, emailStrategy)
	})

	Context("when dispatching to a user", func() {
		It("determines the strategy and calls it", func() {
			err := determiner.Determine(database.Connection(), "some-uaa-host", gobble.NewJob(queue.CampaignJob{
				Campaign: collections.Campaign{
					ID:             "some-id",
					SendTo:         map[string]string{"user": "******"},
					CampaignTypeID: "some-campaign-type-id",
					Text:           "some-text",
	Describe("ServeHTTP", func() {
		var (
			notifyObj   *mocks.Notify
			handler     notify.UAAScopeHandler
			writer      *httptest.ResponseRecorder
			request     *http.Request
			context     stack.Context
			connection  *mocks.Connection
			errorWriter *mocks.ErrorWriter
			strategy    *mocks.Strategy
		)

		BeforeEach(func() {
			writer = httptest.NewRecorder()
			request = &http.Request{URL: &url.URL{Path: "/uaa_scopes/great.scope"}}
			strategy = mocks.NewStrategy()
			errorWriter = mocks.NewErrorWriter()

			connection = mocks.NewConnection()
			database := mocks.NewDatabase()
			database.ConnectionCall.Returns.Connection = connection

			context = stack.NewContext()
			context.Set("database", database)
			context.Set(notify.VCAPRequestIDKey, "some-request-id")

			notifyObj = mocks.NewNotify()
			handler = notify.NewUAAScopeHandler(notifyObj, errorWriter, strategy)
		})

		Context("when the notifyObj.Execute returns a successful response", func() {
Example #3
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()
		notify.Routes{
			Notify:               mocks.NewNotify(),
			ErrorWriter:          mocks.NewErrorWriter(),
			UserStrategy:         mocks.NewStrategy(),
			SpaceStrategy:        mocks.NewStrategy(),
			OrganizationStrategy: mocks.NewStrategy(),
			EveryoneStrategy:     mocks.NewStrategy(),
			UAAScopeStrategy:     mocks.NewStrategy(),
			EmailStrategy:        mocks.NewStrategy(),

			RequestCounter:                  middleware.RequestCounter{},
			RequestLogging:                  middleware.RequestLogging{},
			DatabaseAllocator:               middleware.DatabaseAllocator{},
			NotificationsWriteAuthenticator: middleware.Authenticator{Scopes: []string{"notifications.write"}},
			EmailsWriteAuthenticator:        middleware.Authenticator{Scopes: []string{"emails.write"}},
		}.Register(muxer)
	})

	It("routes POST /users/{user_id}", func() {