Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Throw exception when template id don't exist on Brevo #6

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.1", "8.2"]
laravel: ["^9.0", "^10.0", "^11"]
dependency-version: [ prefer-lowest, prefer-stable ]
php: [8.1, 8.2]
laravel: [9.*, 10.*, 11.*]
dependency-version: [prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
exclude:
- laravel: 11
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -36,12 +43,13 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, exif
tools: composer:v2
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --dev --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --dev --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"require-dev": {
"ciareis/bypass": "^1.0",
"laravel/pint": "^1.16",
"orchestra/testbench": "^7.22|^8.1",
"orchestra/testbench": "^7.44|^8.25|^9.0",
"pestphp/pest": "^2.34",
"phpunit/phpunit": "^9.5|^10.5"
},
Expand Down
1 change: 1 addition & 0 deletions src/BrevoEmailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Notifications\Notification;
use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException;

class BrevoEmailChannel
{
Expand Down
8 changes: 8 additions & 0 deletions src/BrevoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException;

class BrevoService
{
Expand Down Expand Up @@ -45,6 +46,13 @@ public function sendEmail(BrevoEmailMessage $email, array $options = []): ?array
} elseif (array_key_exists('emailFrom', $options)) {
$email->from($options['emailFrom']);
}

$templateResponse = $this->http->get('/smtp/templates/' . $email->templateId);

if (! $templateResponse->successful()) {
throw new BrevoException($templateResponse->toPsrResponse());
}
Comment on lines +50 to +54
Copy link
Member

@JamesHemery JamesHemery Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: mettre en place du cache pour cette requête ? Qui ne soit pas activé en dev.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question : l'erreur n'est pas remontée directement par l'endpoint send ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non. En gros y'a 2 éléments que je voulais tester. Savoir déjà si le template existe et savoir s'il est actif. Actuellement nous avons aucun retour quand il y'a un souci


$response = $this->http->post('/smtp/email', $email->toArray());

if (! $response->successful()) {
Expand Down
1 change: 1 addition & 0 deletions src/BrevoSmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Notifications\Notification;
use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException;

class BrevoSmsChannel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace YieldStudio\LaravelBrevoNotifier;
namespace YieldStudio\LaravelBrevoNotifier\Exceptions;

use Exception;
use Psr\Http\Message\ResponseInterface;
Expand Down
4 changes: 2 additions & 2 deletions tests/BrevoEmailChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$mock = $this->mock(BrevoService::class)->shouldReceive('sendEmail')->once();
$channel = new BrevoEmailChannel($mock->getMock());

$channel->send(new User(), new class extends Notification
$channel->send(new User, new class extends Notification
{
public function via()
{
Expand All @@ -21,7 +21,7 @@ public function via()

public function toBrevoEmail(User $notifiable): BrevoEmailMessage
{
return new BrevoEmailMessage();
return new BrevoEmailMessage;
}
});
});
4 changes: 2 additions & 2 deletions tests/BrevoSmsChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it('send notification via BrevoChannel should call BrevoService sendSms method', function () {
$mock = $this->mock(BrevoService::class)->shouldReceive('sendSms')->once();
$channel = new BrevoSmsChannel($mock->getMock());
$channel->send(new User(), new class extends Notification
$channel->send(new User, new class extends Notification
{
public function via()
{
Expand All @@ -21,7 +21,7 @@ public function via()

public function toBrevoSms(Model $notifiable): BrevoSmsMessage
{
return new BrevoSmsMessage();
return new BrevoSmsMessage;
}
});
});
Loading