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)) })
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") if err != nil { panic(err) } Expect(client.ID).To(Equal("my-client")) Expect(client.Description).To(Equal("My Client")) Expect(client.CreatedAt).To(BeTemporally("~", time.Now(), 2*time.Second)) Expect(client.TemplateID).To(Equal("new-template")) })