func (m *Mother) TemplateServiceObjects() (services.TemplateCreator, services.TemplateFinder, services.TemplateUpdater, services.TemplateDeleter, services.TemplateLister, services.TemplateAssigner, services.TemplateAssociationLister) { clientsRepo, kindsRepo := m.Repos() templatesRepo := m.TemplatesRepo() return services.NewTemplateCreator(templatesRepo), m.TemplateFinder(), services.NewTemplateUpdater(templatesRepo), services.NewTemplateDeleter(templatesRepo), services.NewTemplateLister(templatesRepo), services.NewTemplateAssigner(clientsRepo, kindsRepo, templatesRepo), services.NewTemplateAssociationLister(clientsRepo, kindsRepo, templatesRepo) }
) BeforeEach(func() { templatesRepo = mocks.NewTemplatesRepo() template = models.Template{ Name: "Big Hero 6 Template", Text: "Adorable robot.", HTML: "<p>Many heroes.</p>", Subject: "Robots and Heroes", } conn = mocks.NewConnection() database = mocks.NewDatabase() database.ConnectionCall.Returns.Connection = conn creator = services.NewTemplateCreator(templatesRepo) }) It("Creates a new template via the templates repo", func() { _, err := creator.Create(database, template) Expect(err).ToNot(HaveOccurred()) Expect(templatesRepo.CreateCall.Receives.Connection).To(Equal(conn)) Expect(templatesRepo.CreateCall.Receives.Template).To(Equal(template)) }) It("propagates errors from repo", func() { templatesRepo.CreateCall.Returns.Error = errors.New("Boom!") _, err := creator.Create(database, template) Expect(err).To(Equal(errors.New("Boom!")))