feat: create ClickUp task after confirming accommodation booking

This commit is contained in:
Björn Fromme
2026-08-20 17:56:29 +02:00
parent 0a1683667f
commit 7c5f6dd5ef
18 changed files with 535 additions and 48 deletions
-197
View File
@@ -1,197 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\Service\MailjetApiClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class MailjetApiClientTest extends TestCase
{
public function testChecksSubscriptionAgainstSuppliedListId(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
if (true === str_contains($url, '/Contact?')) {
return new MockResponse(json_encode([
'Data' => [
['ID' => 99],
],
], JSON_THROW_ON_ERROR));
}
return new MockResponse(json_encode([
'Data' => [
[
'ContactID' => 99,
'IsActive' => true,
'IsUnsubscribed' => false,
],
],
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$subscribed = $mailjet->isSubscribed(' [email protected] ', 123);
self::assertTrue($subscribed);
self::assertSame('123', (string) $requests[1][2]['query']['ContactsList']);
}
public function testUpsertContactCreatesContactAndUpdatesProperties(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
if (true === str_contains($url, '/Contact?')) {
return new MockResponse(json_encode([
'Data' => [],
], JSON_THROW_ON_ERROR));
}
if (true === str_contains($url, '/Contact')) {
return new MockResponse(json_encode([
'Data' => [
['ID' => 99],
],
], JSON_THROW_ON_ERROR));
}
return new MockResponse(json_encode([
'Data' => [],
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient(
$client,
new NullLogger(),
'key',
'secret',
'https://mailjet.test',
'111',
[
'firstName' => 'vorname',
'lastName' => 'nachname',
],
);
$mailjet->upsertContact(' [email protected] ', ' Mia ', ' Muster ');
self::assertCount(3, $requests);
self::assertSame('GET', $requests[0][0]);
self::assertSame('https://mailjet.test/[email protected]&Limit=1', $requests[0][1]);
self::assertSame('[email protected]', (string) $requests[0][2]['query']['Email']);
self::assertSame('POST', $requests[1][0]);
self::assertSame('https://mailjet.test/Contact', $requests[1][1]);
self::assertSame([
'Email' => '[email protected]',
], json_decode((string) $requests[1][2]['body'], true, 512, JSON_THROW_ON_ERROR));
self::assertSame('POST', $requests[2][0]);
self::assertSame('https://mailjet.test/contactdata', $requests[2][1]);
self::assertSame([
'ContactID' => 99,
'Data' => [
[
'Name' => 'vorname',
'Value' => 'Mia',
],
[
'Name' => 'nachname',
'Value' => 'Muster',
],
],
], json_decode((string) $requests[2][2]['body'], true, 512, JSON_THROW_ON_ERROR));
}
public function testUpsertContactTruncatesLongNamesBeforeSending(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
if (true === str_contains($url, '/Contact?')) {
return new MockResponse(json_encode([
'Data' => [
['ID' => 99],
],
], JSON_THROW_ON_ERROR));
}
if (true === str_contains($url, '/Contact')) {
return new MockResponse(json_encode([
'Data' => [],
], JSON_THROW_ON_ERROR));
}
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient(
$client,
new NullLogger(),
'key',
'secret',
'https://mailjet.test',
'111',
[
'firstName' => 'vorname',
'lastName' => 'nachname',
],
);
$mailjet->upsertContact('[email protected]', str_repeat('A', 300), str_repeat('B', 300));
$payload = json_decode((string) $requests[1][2]['body'], true, 512, JSON_THROW_ON_ERROR);
self::assertSame(255, strlen($payload['Data'][0]['Value']));
self::assertSame(255, strlen($payload['Data'][1]['Value']));
self::assertSame(str_repeat('A', 255), $payload['Data'][0]['Value']);
self::assertSame(str_repeat('B', 255), $payload['Data'][1]['Value']);
}
public function testUpsertContactDoesNothingWithoutNames(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->upsertContact(' [email protected] ');
self::assertSame([], $requests);
}
public function testEnsureSubscribedUsesSuppliedListId(): void
{
$requests = [];
$client = new MockHttpClient(function (string $method, string $url, array $options) use (&$requests): MockResponse {
$requests[] = [$method, $url, $options];
return new MockResponse(json_encode(['Data' => []], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->ensureSubscribed(' [email protected] ', 456);
self::assertCount(1, $requests);
self::assertSame('POST', $requests[0][0]);
self::assertSame('https://mailjet.test/Contactslist/456/managecontact', $requests[0][1]);
self::assertSame([
'Email' => '[email protected]',
'Action' => 'addforce',
], json_decode((string) $requests[0][2]['body'], true, 512, JSON_THROW_ON_ERROR));
}
}
@@ -1,54 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\Service\MailjetApiClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class MailjetNewsletterWebhookClientTest extends TestCase
{
public function testCreatesEventCallbackUrl(): void
{
$client = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse {
self::assertSame('POST', $method);
self::assertSame('https://mailjet.test/eventcallbackurl', $url);
self::assertSame([
'EventType' => 'unsub',
'Url' => 'https://my.ep-reisen.de/webhooks/mailjet/newsletter',
'Version' => 2,
'isBackup' => false,
], json_decode((string) $options['body'], true, 512, JSON_THROW_ON_ERROR));
return new MockResponse(json_encode([
'Data' => [
[
'ID' => 456,
],
],
], JSON_THROW_ON_ERROR));
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$response = $mailjet->createEventCallbackUrl('unsub', 'https://my.ep-reisen.de/webhooks/mailjet/newsletter');
self::assertSame(456, $response['Data'][0]['ID']);
}
public function testDeletesEventCallbackUrl(): void
{
$client = new MockHttpClient(static function (string $method, string $url, array $options): MockResponse {
self::assertSame('DELETE', $method);
self::assertSame('https://mailjet.test/eventcallbackurl/456', $url);
return new MockResponse('', ['http_code' => 204]);
});
$mailjet = new MailjetApiClient($client, new NullLogger(), 'key', 'secret', 'https://mailjet.test', '111');
$mailjet->deleteEventCallbackUrl(456);
}
}
+18 -18
View File
@@ -8,11 +8,11 @@ use App\Email\Mailer;
use App\Entity\NewsletterConsent;
use App\Entity\NewsletterOptInRequest;
use App\Exception\NewsletterListNotAllowedException;
use App\Mailjet\ApiClient;
use App\Model\NewsletterConfirmationResult;
use App\Model\NewsletterSubscriptionRequestResult;
use App\Repository\NewsletterConsentRepository;
use App\Repository\NewsletterOptInRequestRepository;
use App\Service\MailjetApiClient;
use App\Service\NewsletterManager;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\MockObject\MockObject;
@@ -26,7 +26,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -83,7 +83,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -114,7 +114,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -147,7 +147,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -191,7 +191,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -219,7 +219,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -251,7 +251,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('isSubscribed');
@@ -276,7 +276,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('ensureSubscribed');
@@ -303,7 +303,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$mailjet->expects(self::never())->method('ensureSubscribed');
@@ -339,7 +339,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
@@ -370,7 +370,7 @@ class NewsletterManagerTest extends TestCase
$repository = $this->createMock(NewsletterOptInRequestRepository::class);
$consents = $this->createMock(NewsletterConsentRepository::class);
$entityManager = $this->createMock(EntityManagerInterface::class);
$mailjet = $this->createMock(MailjetApiClient::class);
$mailjet = $this->createMock(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->expects(self::once())->method('findByTokenHash')->with(hash('sha256', $token))->willReturn($confirmation);
@@ -434,17 +434,17 @@ class NewsletterManagerTest extends TestCase
/**
* @param MockObject&NewsletterOptInRequestRepository $repository
* @param MockObject&NewsletterConsentRepository $consents
* @param MockObject&EntityManagerInterface $entityManager
* @param MockObject&MailjetApiClient $mailjet
* @param MockObject&Mailer $mailer
* @param array<int, string> $mailjetLists
* @param MockObject&NewsletterConsentRepository $consents
* @param MockObject&EntityManagerInterface $entityManager
* @param MockObject&ApiClient $mailjet
* @param MockObject&Mailer $mailer
* @param array<int, string> $mailjetLists
*/
private function createManager(
NewsletterOptInRequestRepository $repository,
NewsletterConsentRepository $consents,
EntityManagerInterface $entityManager,
MailjetApiClient $mailjet,
ApiClient $mailjet,
Mailer $mailer,
array $mailjetLists = [
10321569 => 'E&P Newsletter',