Esempio n. 1
0
func createReceipt(conn db.ConnectionInterface, receipt models.Receipt) (models.Receipt, error) {
	err := conn.Insert(&receipt)
	if err != nil {
		return models.Receipt{}, err
	}

	return receipt, nil
}
Esempio n. 2
0
func findReceipt(conn db.ConnectionInterface, userGUID, clientID, kindID string) (models.Receipt, error) {
	receipt := models.Receipt{}
	err := conn.SelectOne(&receipt, "SELECT * FROM  `receipts` WHERE `user_guid` = ? AND `client_id` = ? AND `kind_id` = ?", userGUID, clientID, kindID)
	if err != nil {
		return models.Receipt{}, err
	}

	return receipt, nil
}
package models_test

import (
	"time"

	"github.com/cloudfoundry-incubator/notifications/db"
	"github.com/cloudfoundry-incubator/notifications/testing/helpers"
	"github.com/cloudfoundry-incubator/notifications/v1/models"

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

var _ = Describe("TemplatesRepo", func() {
	var repo models.TemplatesRepo
	var conn db.ConnectionInterface
	var template models.Template
	var createdAt time.Time

	BeforeEach(func() {
		repo = models.NewTemplatesRepo()
		database := db.NewDatabase(sqlDB, db.Config{})
		helpers.TruncateTables(database)
		conn = database.Connection()
		createdAt = time.Now().Add(-1 * time.Hour).Truncate(1 * time.Second).UTC()

		template = models.Template{
			ID:        "raptor_template",
			Name:      "Raptors On The Run",
			Text:      "run and hide",
			HTML:      "<h1>containment unit breached!</h1>",
Esempio n. 4
0
package db_test

import (
	"github.com/cloudfoundry-incubator/notifications/db"
	"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{