Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Sep 17, 2024
1 parent 4665523 commit 15057a3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RENAISSANCE_HOST=test.renaissance.code
APP_RENAISSANCE_HOST=test.renaissance.code
USER_VOX_HOST=test.renaissance.code
WEBHOOK_RENAISSANCE_HOST=test.renaissance.code
PRODUCTION_WEBHOOK_HOST=test.renaissance.code
PROCURATION_HOST=test.enmarche.code
SSL_KEY_PERMISSIONS_CHECK=false
SYMFONY_DEPRECATIONS_HELPER=weak
Expand Down
5 changes: 5 additions & 0 deletions config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ app_webhook_renaissance:
resource: "../src/Controller/Webhook"
type: "annotation"

app_webhook_template:
host: "%production_webhook_host%"
resource: "../src/Controller/Webhook/UpdateTransactionalEmailTemplateController.php"
type: "annotation"

app_renaissance:
host: "%user_vox_host%"
resource: "../src/Controller/Renaissance"
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parameters:
app_renaissance_host: "%env(APP_RENAISSANCE_HOST)%"
admin_renaissance_host: "%env(ADMIN_RENAISSANCE_HOST)%"
webhook_renaissance_host: "%env(WEBHOOK_RENAISSANCE_HOST)%"
production_webhook_host: "%env(PRODUCTION_WEBHOOK_HOST)%"
api_renaissance_host: "%env(API_RENAISSANCE_HOST)%"
renaissance_qrcode_host: "%env(RENAISSANCE_QRCODE_HOST)%"
mooc_base_url: "%env(MOOC_BASE_URL)%"
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Admin/AdminEmailCRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function sendToProdAction(TransactionalEmailTemplate $template, HttpClien
{
$this->admin->checkAccess('content', $template);

$response = $templateWebhookClient->request('POST', '/templates', [
$response = $templateWebhookClient->request('POST', $this->generateUrl('app_webhook_template_update'), [
'json' => [
'identifier' => $template->identifier,
'subject' => $template->subject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;

#[Route('/templates', name: 'app_webhook_template_update', methods: ['POST', 'GET'])]
#[Route('/templates', name: 'app_webhook_template_update', methods: ['POST'])]
class UpdateTransactionalEmailTemplateController extends AbstractController
{
public function __construct(private readonly string $templateWebhookKey)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tests\App\Controller\Webhook;

use App\Entity\Email\TransactionalEmailTemplate;
use Tests\App\AbstractWebTestCase;
use Tests\App\Controller\ControllerTestTrait;

class UpdateTransactionalEmailTemplateControllerTest extends AbstractWebTestCase
{
use ControllerTestTrait;

public function testTemplateUpdateEndpoint(): void
{
$this->client->jsonRequest('POST', '/templates', [
'identifier' => 'test-email-a',
'subject' => 'Test will be green !',
'content' => 'Hello, this is a test email',
'jsonContent' => '{"blocks":[{"type":"text","data":{"text":"Hello, this is a test email"}}]}',
'parent' => null,
], server: ['HTTP_AUTHORIZATION' => 'Bearer abc']);

$this->assertResponseIsSuccessful();

$template = $this->getRepository(TransactionalEmailTemplate::class)->findOneBy(['identifier' => 'test-email-a']);
$this->assertNotNull($template);
$this->assertSame('Test will be green !', $template->subject);
$this->assertSame('Hello, this is a test email', $template->getContent());
$this->assertSame('{"blocks":[{"type":"text","data":{"text":"Hello, this is a test email"}}]}', $template->getJsonContent());

$this->client->jsonRequest('POST', '/templates', [
'identifier' => 'test-email-a',
'subject' => 'Test will be green again !',
'content' => 'Hello, juste a test email',
'jsonContent' => '{"blocks":[{"type":"text","data":{"text":"Hello, this is a test email"}}]}',
'parent' => null,
], server: ['HTTP_AUTHORIZATION' => 'Bearer abc']);

$this->assertResponseIsSuccessful();

$template = $this->getRepository(TransactionalEmailTemplate::class)->findOneBy(['identifier' => 'test-email-a']);
$this->assertNotNull($template);
$this->assertSame('Test will be green again !', $template->subject);
$this->assertSame('Hello, juste a test email', $template->getContent());
}

protected function setUp(): void
{
parent::setUp();

$this->client->setServerParameter('HTTP_HOST', static::getContainer()->getParameter('production_webhook_host'));
}
}

0 comments on commit 15057a3

Please sign in to comment.