示例#1
0
package models_test

import (
	"github.com/cloudfoundry-incubator/notifications/v1/models"

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

var _ = Describe("Client", func() {
	var client models.Client

	Describe("TemplateToUse", func() {
		Context("when the template is set", func() {
			BeforeEach(func() {
				client.TemplateID = "template-id"
			})

			It("returns the template value", func() {
				Expect(client.TemplateToUse()).To(Equal("template-id"))
			})
		})

		Context("when the template is not set", func() {
			BeforeEach(func() {
				client.TemplateID = ""
			})

			It("returns the default template value", func() {
				Expect(client.TemplateToUse()).To(Equal(models.DefaultTemplateID))
			})
			}

			clients, err := repo.FindAll(conn)
			if err != nil {
				panic(err)
			}

			Expect(clients).To(Equal([]models.Client{firstClient, secondClient}))
		})
	})

	Describe("Update", func() {
		Context("when the template id is meant to be updated", func() {
			It("updates the record in the database", func() {
				client := models.Client{
					ID:         "my-client",
					TemplateID: "my-template",
				}

				client, err := repo.Upsert(conn, client)
				if err != nil {
					panic(err)
				}

				client.ID = "my-client"
				client.Description = "My Client"
				client.TemplateID = "new-template"

				client, err = repo.Update(conn, client)
				Expect(err).NotTo(HaveOccurred())

				client, err = repo.Find(conn, "my-client")