func TestSendMail(t *testing.T) {
	e := eventbus.New()
	counter := 0
	var sendMail SendMail = func(mail *booking_mail.Mail, config booking_mail_config.Config) error {
		counter++
		return nil
	}
	mailConfig := booking_mail_config.New(nil, nil)
	userList := createUserList([]booking_user.User{{Email: "*****@*****.**"}, {Email: "*****@*****.**"}}, nil)
	getModel := createGetModel(&booking_model.Model{Email: "*****@*****.**"}, nil)
	getDate := createGetDate(&booking_date.Date{}, nil)
	formatDate := createFormatDate("today", nil)
	b := New(sendMail, mailConfig, userList, getModel, getDate, formatDate, createProtocol())
	if err := e.RegisterHandler(b.HandleBookedEvent); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(counter, Is(0)); err != nil {
		t.Fatal(err)
	}
	if err := e.Publish(*booking_booked_event.New(booking_shooting.Shooting{DateId: null.NewInt(1, true), ModelId: null.NewInt(1, true)})); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(counter, Is(3)); err != nil {
		t.Fatal(err)
	}
}
Beispiel #2
0
func createServer() (*http.Server, error) {
	port := model.Port(*portPtr)
	documentRoot := *documentRootPtr
	databaseHost := *databaseHostPtr
	databaseName := *databaseNamePtr
	databaseUser := *databaseUserPtr
	databasePassword := *databasePasswordPtr
	databaseLogging := *databaseLoggingPtr
	migrationPath := *databaseMigrationPathPtr
	database := booking_database_postgres.New(databaseHost, databaseName, databaseUser, databasePassword, databaseLogging, migrationPath)
	dateStorage := booking_date_storage.New(database)
	tokengenerator := booking_tokengenerator.New()
	modelService := booking_model_service.New(booking_model_storage.New(database), tokengenerator)
	shootingStorage := booking_shooting_storage.New(database)
	shootingValidator := booking_shooting_validator.New()
	shootingService := booking_shooting_service.New(shootingStorage, shootingValidator.ValidateShooting)
	configService := booking_config_service.New(booking_config_storage.New(database))
	userService := booking_user_service.New(booking_user_storage.New(database))
	authenticationService := booking_authentication_service.New(userService, modelService)
	authorizationService := booking_authorization_service.New()
	authenticationConverter := booking_authentication_converter.New()
	eventBus := eventbus.New()
	shootingBookService := booking_shooting_service_book.New(shootingStorage, eventBus, dateStorage)
	shootingRefuseService := booking_shooting_service_refuse.New(shootingStorage, eventBus)
	mailService := booking_mail_service.New()
	mailConfig := booking_mail_config.New(configService.GetString, configService.GetInt)
	dateFormatter := booking_date_formatter.New()
	protocolBuilderProvider := booking_protocol_builder.New(authenticationConverter.HttpRequestToAuthentication, userService.FindUserByAuthentication, modelService.FindModelByAuthentication)
	protocolStorage := booking_protocol_storage.New(database)
	protocolService := booking_protocol_service.New(protocolStorage)
	protocolEventHandler := booking_protocol_event_handler.New(protocolService.Create)
	protocoller := booking_protocol_protocoller.New(protocolBuilderProvider.NewBuilder, eventBus.Publish)
	dateUserService := booking_date_user_service.New(booking_date_user_storage.New(database))
	shootingUserService := booking_shooting_user_service.New(booking_shooting_user_storage.New(database))
	dateService := booking_date_service.New(dateStorage, shootingService.Get, shootingUserService.GetUserIdsForShooting, dateUserService.GetUserIdsForDate)
	bookedEventHander := booking_booked_event_handler.New(mailService.SendMail, mailConfig, userService.List, modelService.Get, dateService.Get, dateFormatter.FormatDate, protocoller.AddProtocolSystem)
	calendarWriter := booking_calendar_writer.New(dateService.List, shootingService.GetShootingByDateId, configService.GetStringDefault, userService.ListUserOfDate)
	modelToVCard := booking_model_vcard.New()
	// register event handler
	if err := eventBus.RegisterHandler(bookedEventHander.HandleBookedEvent); err != nil {
		return nil, err
	}
	if err := eventBus.RegisterHandler(protocolEventHandler.HandleProtocolEvent); err != nil {
		return nil, err
	}
	handlerConfiguration := booking_handler_configuration.New(documentRoot, dateService, modelService, shootingService, userService, authenticationService, authorizationService, authenticationConverter, shootingBookService, shootingRefuseService, configService, calendarWriter, protocoller, dateUserService, shootingUserService, modelToVCard)
	handler := handlerConfiguration.GetHandler()
	if glog.V(4) {
		handler = debug_handler.New(handler)
	}
	glog.V(2).Infof("create http server on %s", port.Address())
	return &http.Server{Addr: port.Address(), Handler: handler}, nil
}
func TestBuildModelConfirmationMail(t *testing.T) {

	expectedContent := `Hallo model_firstname model_lastname,

Du hast gerade erfolgreich einen Termin für dein Shooting "shooting_name" gebucht.

Termin: shooting_date
Ort: shooting_location
shooting_location_url
Thema: shooting_theme
shooting_theme_url


Bis bald

--
Benjamin Borbe Fotografie
Mobil: 0178-1970808, Web https://www.benjamin-borbe.de
`
	getModel := createGetModel(&booking_model.Model{FirstName: "model_firstname", LastName: "model_lastname", Email: "*****@*****.**"}, nil)
	getDate := createGetDate(&booking_date.Date{}, nil)
	userList := createUserList([]booking_user.User{}, nil)
	sendMail := createSendMail(nil)
	mailConfig := booking_mail_config.New(nil, nil)
	formatDate := createFormatDate("shooting_date", nil)
	b := New(sendMail, mailConfig, userList, getModel, getDate, formatDate, createProtocol())
	recipient := "*****@*****.**"
	mail, err := b.buildModelConfirmationMail(&booking_shooting.Shooting{Theme: "shooting_theme", ThemeUrl: "shooting_theme_url", Location: "shooting_location", LocationUrl: "shooting_location_url", Name: "shooting_name", DateId: null.NewInt(1, true), ModelId: null.NewInt(1, true)}, recipient)
	if err := AssertThat(err, NilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(mail, NotNilValue()); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(mail.Recipient, Is(recipient)); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(mail.Subject, Is("Bestätigung Deiner Shooting Buchung")); err != nil {
		t.Fatal(err)
	}
	if err := AssertThat(mail.Content, Is(expectedContent)); err != nil {
		t.Fatal(err)
	}

}