Exemple #1
0
func TestInvoiceCreate(t *testing.T) {
	invoice := path.Join(templateDir, webinvoice.Template)

	i := newInvoice()
	pdf, err := i.Create(templateDir, invoice)
	if err != nil {
		t.Fatal(err)
	}
	if len(pdf) == 0 {
		t.Fatal("no pdf produced")
	}
	ioutil.WriteFile("/tmp/test.pdf", pdf, 0644)

	body, err := i.MailBody()
	if err != nil {
		t.Fatal(err)
	}
	mail := email.NewInvoice(i.MailSubject(), body, i.FileName, pdf)
	if mail.Subject != "[NLgids] Formulier \"Christel Achternaam\"" {
		t.Fatal("wrong email Subject")
	}
	if mail.From != "" { // Set in mail.Do()
		t.Fatal("wrong email From")
	}
	if len(mail.Cc) != 0 {
		t.Fatal("wrong email Cc")
	}
	if len(mail.Attachments) != 1 {
		t.Fatal("wrong email attachment number")
	}
}
Exemple #2
0
func sendInvoice(i *webinvoice.Invoice, pdf []byte, rcpts []string) (int, error) {
	subject := i.MailSubject()
	body, err := i.MailBody()
	if err != nil {
		return http.StatusInternalServerError, err
	}

	mail := email.NewInvoice(subject, body, i.FileName, pdf)
	if err := mail.Do(rcpts); err != nil {
		return http.StatusInternalServerError, err
	}
	return http.StatusOK, nil
}