From 95e4cc7afc4b615aee774a9e90ba6e0f3ddb8abf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 5 Aug 2023 09:31:16 +1000 Subject: [PATCH] Fixes for email templates --- app/Http/Requests/Email/SendEmailRequest.php | 9 ++++--- tests/Feature/InvoiceEmailTest.php | 26 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/Email/SendEmailRequest.php b/app/Http/Requests/Email/SendEmailRequest.php index 4b9a1b2098..b0264eac2b 100644 --- a/app/Http/Requests/Email/SendEmailRequest.php +++ b/app/Http/Requests/Email/SendEmailRequest.php @@ -65,7 +65,7 @@ class SendEmailRequest extends Request $input['entity_id'] = $this->decodePrimaryKey($input['entity_id']); } - if (array_key_exists('entity', $input)) { + if (isset($input['entity'])) { $input['entity'] = "App\Models\\".ucfirst(Str::camel($input['entity'])); } @@ -83,15 +83,13 @@ class SendEmailRequest extends Request { $input = $this->all(); - if (Ninja::isHosted() && !auth()->user()->account->account_sms_verified) { $this->error_message = ctrans('texts.authorization_sms_failure'); - return false; } /*Make sure we have all the require ingredients to send a template*/ - if (array_key_exists('entity', $input) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) { + if (isset($input['entity']) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) { /** @var \App\Models\User $user */ $user = auth()->user(); @@ -108,6 +106,9 @@ class SendEmailRequest extends Request return true; } } + else { + $this->error_message = "Invalid entity or entity_id"; + } return false; } diff --git a/tests/Feature/InvoiceEmailTest.php b/tests/Feature/InvoiceEmailTest.php index 13fc696189..8196c2ccce 100644 --- a/tests/Feature/InvoiceEmailTest.php +++ b/tests/Feature/InvoiceEmailTest.php @@ -46,6 +46,32 @@ class InvoiceEmailTest extends TestCase } + public function testTemplateValidation() + { + $data = [ + "body" => "hey what's up", + "entity" => 'invoice', + "entity_id"=> $this->invoice->hashed_id, + "subject"=> 'Reminder $number', + "template"=> "first_custom" + ]; + + $response = false; + + // try { + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->postJson('/api/v1/emails', $data); + // } catch (ValidationException $e) { + // $message = json_decode($e->validator->getMessageBag(), 1); + // nlog($message); + // } + + $response->assertStatus(200); + + } + public function test_cc_email_implementation() { $data = [