Fix email notification reply to (#603)

This commit is contained in:
Chirag Chhatrala
2024-10-28 14:47:01 +05:30
committed by GitHub
parent 6bdce23967
commit 08837e6a29
2 changed files with 73 additions and 32 deletions

View File

@@ -26,6 +26,7 @@ it('send email with the submitted data', function () {
$notifiable->route('mail', 'test@test.com');
$renderedMail = $mailable->toMail($notifiable);
expect($renderedMail->subject)->toBe('New form submission');
expect($renderedMail->replyTo[0][0])->toBe('reply@example.com');
expect(trim($renderedMail->render()))->toContain('Test body');
});
@@ -163,3 +164,65 @@ it('does not use custom sender email in non-self-hosted mode', function () {
expect($renderedMail->subject)->toBe('Custom Subject');
expect(trim($renderedMail->render()))->toContain('Custom content');
});
it('send email with mention as reply to', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
$emailProperty = collect($form->properties)->first(function ($property) {
return $property['type'] == 'email';
});
$integrationData = $this->createFormIntegration('email', $form->id, [
'send_to' => 'test@test.com',
'sender_name' => 'OpnForm',
'subject' => 'New form submission',
'email_content' => 'Hello there 👋 <br>Test body',
'include_submission_data' => true,
'include_hidden_fields_submission_data' => false,
'reply_to' => '<span mention-field-id="' . $emailProperty['id'] . '" mention-field-name="' . $emailProperty['name'] . '" mention-fallback="" contenteditable="false" mention="true">' . $emailProperty['name'] . '</span>'
]);
$formData = [
$emailProperty['id'] => 'reply@example.com',
];
$event = new \App\Events\Forms\FormSubmitted($form, $formData);
$mailable = new FormEmailNotification($event, $integrationData, 'mail');
$notifiable = new AnonymousNotifiable();
$notifiable->route('mail', 'test@test.com');
$renderedMail = $mailable->toMail($notifiable);
expect($renderedMail->replyTo[0][0])->toBe('reply@example.com');
});
it('send email with empty reply to', function () {
$user = $this->actingAsUser();
$workspace = $this->createUserWorkspace($user);
$form = $this->createForm($user, $workspace);
$emailProperty = collect($form->properties)->first(function ($property) {
return $property['type'] == 'email';
});
$integrationData = $this->createFormIntegration('email', $form->id, [
'send_to' => 'test@test.com',
'sender_name' => 'OpnForm',
'subject' => 'New form submission',
'email_content' => 'Hello there 👋 <br>Test body',
'include_submission_data' => true,
'include_hidden_fields_submission_data' => false,
'reply_to' => null,
]);
$formData = [
$emailProperty['id'] => 'reply@example.com',
];
$event = new \App\Events\Forms\FormSubmitted($form, $formData);
$mailable = new FormEmailNotification($event, $integrationData, 'mail');
$notifiable = new AnonymousNotifiable();
$notifiable->route('mail', 'test@test.com');
$renderedMail = $mailable->toMail($notifiable);
expect($renderedMail->replyTo[0][0])->toBe($form->creator->email);
});