Exemplo n.º 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)
}
	Describe("List", func() {
		BeforeEach(func() {
			clientsRepo = mocks.NewClientsRepository()
			kindsRepo = mocks.NewKindsRepo()
			templatesRepo = mocks.NewTemplatesRepo()
			conn = mocks.NewConnection()
			database = mocks.NewDatabase()
			database.ConnectionCall.Returns.Connection = conn

			templateID = "a-template-id"
			_, err := templatesRepo.Create(conn, models.Template{
				ID: templateID,
			})
			Expect(err).NotTo(HaveOccurred())
			lister = services.NewTemplateAssociationLister(clientsRepo, kindsRepo, templatesRepo)
		})

		Context("when a template has been associated to some clients and notifications", func() {
			BeforeEach(func() {
				expectedAssociations = []services.TemplateAssociation{
					{
						ClientID: "some-client",
					},
					{
						ClientID:       "some-client",
						NotificationID: "some-notification",
					},
					{
						ClientID:       "another-client",
						NotificationID: "another-notification",