Skip to content

Commit

Permalink
Fixing API error caused by the strict type mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
escopecz committed Dec 11, 2023
1 parent e19db51 commit 96c48f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/bundles/LeadBundle/EventListener/LeadSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private function addTimelineDoNotContactEntries(Events\LeadTimelineEvent $event,

if (!$event->isEngagementCount()) {
foreach ($rows['results'] as $row) {
$row['reason'] = $this->dncReasonHelper->toText($row['reason']);
$row['reason'] = $this->dncReasonHelper->toText((int) $row['reason']);

$template = '@MauticLead/SubscribedEvents/Timeline/donotcontact.html.twig';
$icon = 'fa-ban';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public function testDisabledApi(): void
);
}

public function testActivityApi(): void
{
$this->client->request('GET', '/api/contacts/activity');
Assert::assertTrue($this->client->getResponse()->isOk(), $this->client->getResponse()->getContent());
Assert::assertArrayHasKey('events', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('filters', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('order', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('types', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('total', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('page', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('limit', json_decode($this->client->getResponse()->getContent(), true));
Assert::assertArrayHasKey('maxPages', json_decode($this->client->getResponse()->getContent(), true));
}

public function testBatchNewEndpointDoesNotCreateDuplicates(): void
{
$payload = [
Expand Down Expand Up @@ -825,6 +839,17 @@ public function testAddAndRemoveDncToExistingContact(): void
$this->assertSame(DoNotContact::MANUAL, $dncResponse['contact']['doNotContact'][0]['reason']);
$this->assertSame($dncChannel, $dncResponse['contact']['doNotContact'][0]['channel']);

// Check DNC is recorded in the contact activity.
$this->client->request('GET', "/api/contacts/{$contactId}/activity");
$clientResponse = $this->client->getResponse();
self::assertSame(Response::HTTP_OK, $clientResponse->getStatusCode(), $clientResponse->getContent());
$activityResponse = json_decode($clientResponse->getContent(), true);
Assert::assertCount(2, $activityResponse['events']); // identified and dnc added events
$dncEvents = array_values(array_filter($activityResponse['events'], fn ($event) => $event['event'] === 'lead.donotcontact'));
Assert::assertCount(1, $dncEvents);
Assert::assertSame('Email', $dncEvents[0]['eventLabel']);
Assert::assertSame('Contact was manually set as do not contact for this channel.', $dncEvents[0]['details']['dnc']['reason']);

// Remove DNC from the contact.
$this->client->request('POST', "/api/contacts/$contactId/dnc/$dncChannel/remove");
$clientResponse = $this->client->getResponse();
Expand Down
6 changes: 1 addition & 5 deletions app/bundles/LeadBundle/Twig/Helper/DncReasonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ public function __construct(private TranslatorInterface $translator)
/**
* Convert DNC reason ID to text.
*
* @param int $reasonId
*
* @return string
*
* @throws UnknownDncReasonException
*/
public function toText($reasonId)
public function toText(int $reasonId): string
{
$reasonKey = match ($reasonId) {
DoNotContact::IS_CONTACTABLE => 'mautic.lead.event.donotcontact_contactable',
Expand Down

0 comments on commit 96c48f0

Please sign in to comment.