示例#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)
}
		clientsRepo   *mocks.ClientsRepository
		templatesRepo *mocks.TemplatesRepo
		conn          *mocks.Connection
		database      *mocks.Database
	)

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

		clientsRepo = mocks.NewClientsRepository()
		kindsRepo = mocks.NewKindsRepo()
		templatesRepo = mocks.NewTemplatesRepo()

		assigner = services.NewTemplateAssigner(clientsRepo, kindsRepo, templatesRepo)
	})

	Describe("AssignToClient", func() {
		BeforeEach(func() {
			var err error

			clientsRepo.FindCall.Returns.Client = models.Client{
				ID: "my-client",
			}

			_, err = templatesRepo.Create(conn, models.Template{
				ID: "default",
			})
			Expect(err).NotTo(HaveOccurred())