"github.com/cloudfoundry-incubator/notifications/v2/models"

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

var _ = Describe("Messages Repository", func() {
	var (
		repo  models.MessagesRepository
		conn  *db.Connection
		clock *mocks.Clock
	)

	BeforeEach(func() {
		database := models.NewDatabase(sqlDB, models.Config{})
		helpers.TruncateTables(db.NewDatabase(sqlDB, db.Config{}))
		conn = database.Connection().(*db.Connection)
		conn.AddTableWithName(models.Message{}, "messages")
		clock = mocks.NewClock()

		repo = models.NewMessagesRepository(clock)
	})

	Describe("CountByStatus", func() {
		BeforeEach(func() {
			err := conn.Insert(&models.Message{
				ID:         "message-id-123",
				CampaignID: "some-campaign-id",
				Status:     postal.StatusDelivered,
			})
			Expect(err).NotTo(HaveOccurred())
	"github.com/nu7hatch/gouuid"

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

var _ = Describe("TemplatesRepo", func() {
	var (
		repo          models.TemplatesRepository
		conn          db.ConnectionInterface
		guidGenerator *mocks.GUIDGenerator
	)

	BeforeEach(func() {
		database := db.NewDatabase(sqlDB, db.Config{})
		helpers.TruncateTables(database)

		guid1 := uuid.UUID([16]byte{0xDE, 0xAD, 0xBE, 0xEF, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55})
		guid2 := uuid.UUID([16]byte{0xDE, 0xAD, 0xBE, 0xEF, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x56})
		guidGenerator = mocks.NewGUIDGenerator()
		guidGenerator.GenerateCall.Returns.GUIDs = []*uuid.UUID{&guid1, &guid2}

		repo = models.NewTemplatesRepository(guidGenerator.Generate)
		conn = database.Connection()
	})

	Describe("Insert", func() {
		It("returns the data", func() {
			createdTemplate, err := repo.Insert(conn, models.Template{
				Name:     "some-template",
				ClientID: "some-client-id",
Esempio n. 3
0
	"github.com/cloudfoundry-incubator/notifications/testing/helpers"
	"github.com/cloudfoundry-incubator/notifications/v1/models"

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

var _ = Describe("Transaction", func() {
	var (
		transaction db.TransactionInterface
		conn        db.ConnectionInterface
	)

	BeforeEach(func() {
		db := db.NewDatabase(sqlDB, db.Config{})
		helpers.TruncateTables(db)
		conn = db.Connection()
		transaction = conn.Transaction()
	})

	Describe("Begin/Commit", func() {
		It("commits the transaction to the database", func() {
			err := transaction.Begin()
			Expect(err).NotTo(HaveOccurred())

			repo := models.NewClientsRepo()
			_, err = repo.Upsert(transaction, models.Client{
				ID:          "my-client",
				Description: "My Client",
			})
			Expect(err).NotTo(HaveOccurred())