Commit ddf44876 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Fix Qute template tests, add a few explicit null checks

parent 2e8b90ad
......@@ -14,6 +14,8 @@ import org.eclipsefoundation.react.model.FormOrganization;
import org.eclipsefoundation.react.model.FormWorkingGroup;
import org.eclipsefoundation.react.model.MembershipForm;
import org.eclipsefoundation.react.service.MailerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.quarkus.mailer.Mail;
import io.quarkus.mailer.Mailer;
......@@ -29,6 +31,8 @@ import io.quarkus.qute.Template;
*/
@ApplicationScoped
public class DefaultMailerService implements MailerService {
public static final Logger LOGGER = LoggerFactory.getLogger(DefaultMailerService.class);
@ConfigProperty(name = "eclipse.mailer.membership.inbox")
String membershipMailbox;
......@@ -55,6 +59,7 @@ public class DefaultMailerService implements MailerService {
if (form == null) {
throw new IllegalStateException("A form is required to submit for mailing");
}
/*
// get the user object for the current form
List<EclipseUser> users = accounts.getUsers(form.getUserID(), null, null);
if (users == null || users.isEmpty()) {
......@@ -62,7 +67,7 @@ public class DefaultMailerService implements MailerService {
}
EclipseUser user = users.get(0);
// TODO use this for mail TO field rather than webdev
user.getMail();
user.getMail();*/
// send the email, using the users primary email address
Mail m = Mail.withHtml("webdev@eclipse-foundation.org", "Thank you for completing the member enrollment form",
authorTemplateWeb.data("form", form).render());
......@@ -79,11 +84,15 @@ public class DefaultMailerService implements MailerService {
throw new IllegalStateException(
"Could not find a fully complete form for form with ID '" + form.getId() + "'");
}
String text = membershipTemplate.data("form", form, "org", org, "wgs", wgs, "contacts", contacts).render();
LOGGER.error("Generated email text: {}", text);
String html = membershipTemplateWeb.data("form", form, "org", org, "wgs", wgs, "contacts", contacts).render();
LOGGER.error("Generated email HTML: {}", html);
// generate the mail message, sending the messsage to the membershipMailbox
Mail m = Mail.withHtml(membershipMailbox, "A NEW CHALLENGER APPROACHES",
membershipTemplateWeb.data("form", form, "org", org, "wgs", wgs, "contacts", contacts).render());
m.setText(membershipTemplate.data("form", form, "org", org, "wgs", wgs, "contacts", contacts).render());
html);
m.setText(text);
mailer.send(m);
}
......
......@@ -19,7 +19,7 @@ Name: {contact.fName} {contact.lName}
Email: {contact.email}
Title: {contact.title}
Contact type: {contact.type}
userID
{/for}
Working Groups
......
<div style="background: #efefef; margin-left:-10px; margin-right: -10px;">
<div style="background: #efefef; margin-left: -10px; margin-right: -10px;">
<div style="background: #FFF; min-width: 700px; width: 66%; margin: auto; margin-top: -20px; margin-bottom: -20px;">
<div style="padding: 20px">
<h2>Organization</h2>
......@@ -7,14 +7,10 @@
<div>
<h3>Address</h3>
<p>
{org.address.street}<br />
{org.address.city}<br />
{org.address.provinceState}<br />
{org.address.country}<br />
{org.address.postalCode}
{org.address.street}<br /> {org.address.city}<br /> {org.address.provinceState}<br /> {org.address.country}<br /> {org.address.postalCode}
</p>
</div>
<h2>Contacts</h2>
<table style="width: 100%">
<thead style="background: #dfdfdf">
......@@ -26,8 +22,8 @@
</tr>
</thead>
<tbody>
{#for contact in contacts}
<tr{#if even} style="background: #efefef"{/if}>
{#for contact in contacts.orEmpty}
<tr {#if even} style="background: #efefef"{/if}>
<td>{contact.fName} {contact.lName}</td>
<td>{contact.email}</td>
<td>{contact.title}</td>
......@@ -36,8 +32,8 @@
{/for}
</tbody>
</table>
<h2>Working Groups</h2>
<table style="width: 100%">
<thead style="background: #dfdfdf">
......@@ -49,12 +45,12 @@
</tr>
</thead>
<tbody>
{#for wg in wgs}
<tr{#if even} style="background: #efefef"{/if}>
{#for wg in wgs.orEmpty}
<tr {#if even} style="background: #efefef"{/if}>
<td>{wg.workingGroupID}</td>
<td>{wg.participationLevel}</td>
<td>{time:format(wg.effectiveDate,'d MMM uuuu')}</td>
<td>{wg.contact.fName} {wg.contact.lName}</td>
<td>{#if wg.effectiveDate != null}{time:format(wg.effectiveDate,'d MMM uuuu')}{/if}</td>
<td>{#if wg.contact != null}{wg.contact.fName} {wg.contact.lName}{/if}</td>
</tr>
{/for}
</tbody>
......
package org.eclipsefoundation.react.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
......@@ -48,6 +49,7 @@ class DefaultMailerServiceTest {
void sendToFormAuthor_success() {
// set up form to submit through mock service
MembershipForm f = new MembershipForm();
f.setUserID(AuthHelper.TEST_USER_NAME);
// perform the action
mailerService.sendToFormAuthor(f);
......@@ -83,9 +85,9 @@ class DefaultMailerServiceTest {
MembershipForm f = new MembershipForm();
FormOrganization org = new FormOrganization();
FormWorkingGroup wg = new FormWorkingGroup();
List<FormWorkingGroup> wgs = Arrays.asList(wg);
List<FormWorkingGroup> wgs = new ArrayList<>(Arrays.asList(wg));
Contact c = new Contact();
List<Contact> contacts = Arrays.asList(c);
List<Contact> contacts = new ArrayList<>(Arrays.asList(c));
// perform the action
mailerService.sendToMembershipTeam(f, org, wgs, contacts);
......
......@@ -19,7 +19,7 @@ Name: {contact.fName} {contact.lName}
Email: {contact.email}
Title: {contact.title}
Contact type: {contact.type}
userID
{/for}
Working Groups
......
<div style="background: #efefef; margin-left:-10px; margin-right: -10px;">
<div style="background: #efefef; margin-left: -10px; margin-right: -10px;">
<div style="background: #FFF; min-width: 700px; width: 66%; margin: auto; margin-top: -20px; margin-bottom: -20px;">
<div style="padding: 20px">
<h2>Organization</h2>
......@@ -7,14 +7,10 @@
<div>
<h3>Address</h3>
<p>
{org.address.street}<br />
{org.address.city}<br />
{org.address.provinceState}<br />
{org.address.country}<br />
{org.address.postalCode}
{org.address.street}<br /> {org.address.city}<br /> {org.address.provinceState}<br /> {org.address.country}<br /> {org.address.postalCode}
</p>
</div>
<h2>Contacts</h2>
<table style="width: 100%">
<thead style="background: #dfdfdf">
......@@ -26,8 +22,8 @@
</tr>
</thead>
<tbody>
{#for contact in contacts}
<tr{#if even} style="background: #efefef"{/if}>
{#for contact in contacts.orEmpty}
<tr {#if even} style="background: #efefef"{/if}>
<td>{contact.fName} {contact.lName}</td>
<td>{contact.email}</td>
<td>{contact.title}</td>
......@@ -36,8 +32,8 @@
{/for}
</tbody>
</table>
<h2>Working Groups</h2>
<table style="width: 100%">
<thead style="background: #dfdfdf">
......@@ -49,12 +45,12 @@
</tr>
</thead>
<tbody>
{#for wg in wgs}
<tr{#if even} style="background: #efefef"{/if}>
{#for wg in wgs.orEmpty}
<tr {#if even} style="background: #efefef"{/if}>
<td>{wg.workingGroupID}</td>
<td>{wg.participationLevel}</td>
<td>{time:format(wg.effectiveDate,'d MMM uuuu')}</td>
<td>{wg.contact.fName} {wg.contact.lName}</td>
<td>{#if wg.effectiveDate != null}{time:format(wg.effectiveDate,'d MMM uuuu')}{/if}</td>
<td>{#if wg.contact != null}{wg.contact.fName} {wg.contact.lName}{/if}</td>
</tr>
{/for}
</tbody>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment