)

		BeforeEach(func() {
			params = &notify.NotifyParams{
				Text: "my silly text",
				To:   "*****@*****.**",
			}
			validator = notify.EmailValidator{}
		})

		Describe("Validate", func() {
			It("validates the email fields on Notify", func() {
				Expect(validator.Validate(params)).To(BeTrue())
				Expect(len(params.Errors)).To(Equal(0))

				params.To = ""

				Expect(validator.Validate(params)).To(BeFalse())
				Expect(len(params.Errors)).To(Equal(1))
				Expect(params.Errors).To(ContainElement(`"to" is a required field`))

				params.Text = ""

				Expect(validator.Validate(params)).To(BeFalse())
				Expect(len(params.Errors)).To(Equal(2))
				Expect(params.Errors).To(ContainElement(`"to" is a required field`))
				Expect(params.Errors).To(ContainElement(`"text" or "html" fields must be supplied`))

				params.To = "*****@*****.**"
				params.ParsedHTML = notify.HTML{BodyContent: "<p>Contents of this email message</p>"}
示例#2
0
func (d Determiner) Determine(conn services.ConnectionInterface, uaaHost string, job gobble.Job) error {
	var campaignJob queue.CampaignJob

	err := job.Unmarshal(&campaignJob)
	if err != nil {
		return err
	}

	var audience string
	for key, _ := range campaignJob.Campaign.SendTo {
		audience = key
	}

	params := notify.NotifyParams{
		ReplyTo: campaignJob.Campaign.ReplyTo,
		Subject: campaignJob.Campaign.Subject,
		Text:    campaignJob.Campaign.Text,
		RawHTML: campaignJob.Campaign.HTML,
	}
	if audience == "email" {
		params.To = campaignJob.Campaign.SendTo[audience]
	}

	params.FormatEmailAndExtractHTML()

	strategy, err := d.findStrategy(audience)
	if err != nil {
		return err
	}

	var guid string
	if audience != "email" {
		guid = campaignJob.Campaign.SendTo[audience]
	}

	_, err = strategy.Dispatch(services.Dispatch{
		JobType:    "v2",
		UAAHost:    uaaHost,
		GUID:       guid,
		Connection: conn,
		TemplateID: campaignJob.Campaign.TemplateID,
		CampaignID: campaignJob.Campaign.ID,
		Client: services.DispatchClient{
			ID: campaignJob.Campaign.ClientID,
		},
		Message: services.DispatchMessage{
			To:      params.To,
			ReplyTo: params.ReplyTo,
			Subject: params.Subject,
			Text:    params.Text,
			HTML: services.HTML{
				BodyContent:    params.ParsedHTML.BodyContent,
				BodyAttributes: params.ParsedHTML.BodyAttributes,
				Head:           params.ParsedHTML.Head,
				Doctype:        params.ParsedHTML.Doctype,
			},
		},
	})
	if err != nil {
		return err
	}

	return nil
}