"github.com/cloudfoundry-incubator/notifications/v2/collections"
	"github.com/cloudfoundry-incubator/notifications/v2/queue"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Enqueuer", func() {
	var (
		gobbleQueue *mocks.Queue
		enqueuer    queue.CampaignEnqueuer
		campaign    collections.Campaign
	)

	BeforeEach(func() {
		gobbleQueue = mocks.NewQueue()
		enqueuer = queue.NewCampaignEnqueuer(gobbleQueue)
		campaign = collections.Campaign{
			ID: "27",
		}
	})

	Context("Enqueue", func() {
		It("puts a campaign on the queue", func() {
			err := enqueuer.Enqueue(campaign, "campaign")
			Expect(err).NotTo(HaveOccurred())

			Expect(gobbleQueue.EnqueueCall.Receives.Jobs).To(HaveLen(1))
			Expect(gobbleQueue.EnqueueCall.Receives.Jobs[0]).To(Equal(gobble.NewJob(queue.CampaignJob{
				JobType:  "campaign",
				Campaign: campaign,
		buffer                 *bytes.Buffer
		delivery               postal.Delivery
		queue                  *mocks.Queue
		deliveryFailureHandler *mocks.DeliveryFailureHandler
		v1Workflow             *mocks.Process
		v2Workflow             *mocks.Workflow
		strategyDeterminer     *mocks.StrategyDeterminer
		connection             *mocks.Connection
		messageStatusUpdater   *mocks.MessageStatusUpdater
	)

	BeforeEach(func() {
		buffer = bytes.NewBuffer([]byte{})
		logger = lager.NewLogger("notifications")
		logger.RegisterSink(lager.NewWriterSink(buffer, lager.DEBUG))
		queue = mocks.NewQueue()
		deliveryFailureHandler = mocks.NewDeliveryFailureHandler()
		strategyDeterminer = mocks.NewStrategyDeterminer()
		connection = mocks.NewConnection()
		database := mocks.NewDatabase()
		database.ConnectionCall.Returns.Connection = connection
		messageStatusUpdater = mocks.NewMessageStatusUpdater()

		config := postal.DeliveryWorkerConfig{
			Logger: logger,
			Queue:  queue,
			DeliveryFailureHandler: deliveryFailureHandler,
			StrategyDeterminer:     strategyDeterminer,
			Database:               database,
			UAAHost:                "my-uaa-host",
			MessageStatusUpdater:   messageStatusUpdater,