Example #1
0
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)
}
var _ = Describe("TemplateLister", func() {
	var (
		lister        services.TemplateLister
		templatesRepo *mocks.TemplatesRepo
		database      *mocks.Database
		conn          *mocks.Connection
	)

	BeforeEach(func() {
		templatesRepo = mocks.NewTemplatesRepo()
		conn = mocks.NewConnection()
		database = mocks.NewDatabase()
		database.ConnectionCall.Returns.Connection = conn

		lister = services.NewTemplateLister(templatesRepo)
	})

	Describe("List", func() {
		Context("when the templates exists in the database", func() {
			BeforeEach(func() {
				templatesRepo.ListIDsAndNamesCall.Returns.Templates = []models.Template{
					{
						ID:      "starwarr-guid",
						Name:    "Star Wars",
						Subject: "Awesomeness",
						HTML:    "<p>Millenium Falcon</p>",
						Text:    "Millenium Falcon",
					},
					{
						ID:      models.DefaultTemplateID,