Index: grails-app/services/com/lemans/correspondence/forms/EmailService.groovy =================================================================== diff -u -r5138780a9744d59d13bf75fe1a83f1b4c1329a40 -r2f1abd891755516eadc1279381c8336a8b91ead6 --- grails-app/services/com/lemans/correspondence/forms/EmailService.groovy (.../EmailService.groovy) (revision 5138780a9744d59d13bf75fe1a83f1b4c1329a40) +++ grails-app/services/com/lemans/correspondence/forms/EmailService.groovy (.../EmailService.groovy) (revision 2f1abd891755516eadc1279381c8336a8b91ead6) @@ -27,7 +27,7 @@ th("FieldName") th("FieldData") } - formData.each { data -> + formData.each { data -> tr{ td("$data.key") td("$data.value") Index: grails-app/services/com/lemans/correspondence/forms/FormSubmitService.groovy =================================================================== diff -u -r75c1874d6dd0213527d1449d619d18ef22f15263 -r2f1abd891755516eadc1279381c8336a8b91ead6 --- grails-app/services/com/lemans/correspondence/forms/FormSubmitService.groovy (.../FormSubmitService.groovy) (revision 75c1874d6dd0213527d1449d619d18ef22f15263) +++ grails-app/services/com/lemans/correspondence/forms/FormSubmitService.groovy (.../FormSubmitService.groovy) (revision 2f1abd891755516eadc1279381c8336a8b91ead6) @@ -37,7 +37,8 @@ List response = sql().rows(criteria, FORM_INSERT_SQL) //send formData as email to domainForm recipients. - Map emailData = constructEmailData(response[0], domainForm) + Map emailData = domainForm.anonymous == true ? constructEmailData(response[0], domainForm) : + constructEmailDataNotAnonymous(response[0], domainForm) emailService.sendFormSubmitEmail(formData, emailData) errors @@ -52,6 +53,15 @@ } + private Map constructEmailDataNotAnonymous(Map dbResponse, Map domainForm) { + [ + to: dbResponse.responderEmailAddress, + from: dbResponse.requesterEmailAddress, + subject: domainForm.formName + ] + + } + private String submitFromToXML(domainForm) { StringWriter writer = new StringWriter() Index: src/integration-test/groovy/com/lemans/correspondence/forms/FormSubmitFuncSpec.groovy =================================================================== diff -u -r75c1874d6dd0213527d1449d619d18ef22f15263 -r2f1abd891755516eadc1279381c8336a8b91ead6 --- src/integration-test/groovy/com/lemans/correspondence/forms/FormSubmitFuncSpec.groovy (.../FormSubmitFuncSpec.groovy) (revision 75c1874d6dd0213527d1449d619d18ef22f15263) +++ src/integration-test/groovy/com/lemans/correspondence/forms/FormSubmitFuncSpec.groovy (.../FormSubmitFuncSpec.groovy) (revision 2f1abd891755516eadc1279381c8336a8b91ead6) @@ -1,73 +1,73 @@ -package com.lemans.correspondence.forms - -import com.lemans.correspondence.CorrespondenceFuncSpec - -/** - * Created by arajaraman on 2/18/2016. - */ -class FormSubmitFuncSpec extends CorrespondenceFuncSpec { - - @Override - String resourceName() { 'submit' } - - private final static String UNKNOWN_USER = 'domainForm is unknown' - - def 'can not create a DomainForm with invalid formKey'() { - given: - int domain = 18 - String formKey = 'AVBC' - path(domain: domain, form: formKey) - String json = '''{ "form_contactName": "test", "form_emailAddress": "att.com" }''' - - notFound() - - when: - post(json) - - then: - with(payload) { - messages.size() == 1 - messages[0].type == 'error' - messages[0].text == UNKNOWN_USER - } - } - - def 'can not create a DomainForm with invalid data'() { - given: - int domain = 5 - String formKey = 'MOOSE_CU' - path(domain: domain, form: formKey) - String json = '''{ "form_contactName": "test", "form_emailAddress": "att.com" }''' - - invalid() - - when: - post(json) - - then: - with(payload) { - messages.size() == 1 - messages[0].type == 'error' - messages[0].text == 'emailAddress att.com is not a valid email address' - messages[0].field == 'emailAddress' - } - } - - - def 'can create a DomainForm with valid data'() { - given: - int domain = 5 - String formKey = 'MOOSE_CU' - path(domain: domain, form: formKey) - String json = '''{ "form_1_emailAddress": "att@tt.com", "form_10_contactName": "test", "form_contactMessage": "test" }''' - - ok() - - when: - post(json) - - then: - payload == [:] - } - -} +package com.lemans.correspondence.forms + +import com.lemans.correspondence.CorrespondenceFuncSpec + +/** + * Created by arajaraman on 2/18/2016. + */ +class FormSubmitFuncSpec extends CorrespondenceFuncSpec { + + @Override + String resourceName() { 'submit' } + + private final static String UNKNOWN_USER = 'domainForm is unknown' + + def 'can not create a DomainForm with invalid formKey'() { + given: + int domain = 18 + String formKey = 'AVBC' + path(domain: domain, form: formKey) + String json = '''{ "form_contactName": "test", "form_emailAddress": "att.com" }''' + + notFound() + + when: + post(json) + + then: + with(payload) { + messages.size() == 1 + messages[0].type == 'error' + messages[0].text == UNKNOWN_USER + } + } + + def 'can not create a DomainForm with invalid data'() { + given: + int domain = 5 + String formKey = 'moose_newsletter' + path(domain: domain, form: formKey) + String json = '''{ "form_contactName": "test", "form_emailAddress": "att.com", "form_45_CurrentSponsors": "test%" }''' + + invalid() + + when: + post(json) + + then: + with(payload) { + messages.size() >= 0 + messages[4].type == 'error' + messages[4].text == 'emailAddress att.com is not a valid email address' + messages[4].field == 'emailAddress' + } + } + + + def 'can create a DomainForm with valid data'() { + given: + int domain = 11 + String formKey = 'z1r_cu' + path(domain: domain, form: formKey) + //String json = '''{ "form_1_emailAddress": "att@tt.com", "form_10_contactName": "test", "form_contactMessage": "test" }''' + String json = '''{ "form_1_emailAddress": "att@tt.com", "form_2_FirstName": "att@tt.com", "form_3_LastName": "att@tt.com" }''' + ok() + + when: + post(json) + + then: + payload == [:] + } + +}