Additional checks when validating sendemailrequest

This commit is contained in:
David Bomba 2024-11-19 06:53:02 +11:00
parent 30b4ed191f
commit 9619c65900
3 changed files with 27 additions and 2 deletions

View File

@ -85,7 +85,7 @@ class SendEmailRequest extends Request
$input['template'] = ''; $input['template'] = '';
} }
if (! property_exists($settings, $input['template'])) { if (is_string($input['template']) && ! property_exists($settings, $input['template'])) {
unset($input['template']); unset($input['template']);
} }

View File

@ -119,7 +119,7 @@ class QuoteReminderJob implements ShouldQueue
$t->replace(Ninja::transformTranslations($quote->client->getMergedSettings())); $t->replace(Ninja::transformTranslations($quote->client->getMergedSettings()));
App::setLocale($quote->client->locale()); App::setLocale($quote->client->locale());
if ($quote->isPayable()) { if ($quote->canRemind()) {
//Attempts to prevent duplicates from sending //Attempts to prevent duplicates from sending
if ($quote->reminder_last_sent && Carbon::parse($quote->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())) { if ($quote->reminder_last_sent && Carbon::parse($quote->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())) {
nrlog("caught a duplicate reminder for quote {$quote->number}"); nrlog("caught a duplicate reminder for quote {$quote->number}");

View File

@ -57,6 +57,31 @@ class InvoiceEmailTest extends TestCase
$this->assertTrue(strpos($email, '@example.com') !== false); $this->assertTrue(strpos($email, '@example.com') !== false);
} }
public function testTemplateValidationWhenArray()
{
$data = [
"body" => "hey what's up",
"entity" => 'blergen',
"entity_id" => $this->invoice->hashed_id,
"subject" => 'Reminder $number',
"template" => [
"email_template_invoice","noo",
],
];
$response = false;
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/emails', $data);
$response->assertStatus(422);
}
public function testEntityValidation() public function testEntityValidation()
{ {
$data = [ $data = [