Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/Lox24/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
CHANGELOG
=========

7.4
---

* Add support for building SmsEvent by dlr_code and RemoteEvent for other LOX24 webhook event types

7.1
---

* Add the bridge
* Add the bridge
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Notifier\Bridge\Lox24\Webhook\Lox24RequestParser;
use Symfony\Component\RemoteEvent\Event\Sms\SmsEvent;
use Symfony\Component\RemoteEvent\RemoteEvent;
use Symfony\Component\Webhook\Exception\RejectWebhookException;

/**
Expand All @@ -29,80 +30,284 @@ protected function setUp(): void
$this->parser = new Lox24RequestParser();
}

public function testInvalidNotificationName()
public function testMissingBasicPayloadStructure()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('Notification name is not \'sms.delivery\'');
$request = $this->getRequest(['name' => 'invalid_name', 'data' => ['status_code' => 100]]);
$this->expectExceptionMessage('The required fields "id", "data" are missing from the payload.');

$request = $this->getRequest(['name' => 'sms.delivery']);
$this->parser->parse($request, '');
}

public function testMissingMsgId()
public function testSmsDeliveryMissingMsgId()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('Payload is malformed.');
$request = $this->getRequest(['name' => 'sms.delivery', 'data' => ['status_code' => 100]]);
$this->expectExceptionMessage('The required field "id" is missing from the delivery event payload.');

$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => ['status_code' => 100],
]);
$this->parser->parse($request, '');
}

public function testMissingMsgStatusCode()
public function testSmsDeliveryMissingBothCodes()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('Payload is malformed.');
$request = $this->getRequest(['name' => 'sms.delivery', 'data' => ['id' => '123']]);
$this->expectExceptionMessage('The required field "status_code" or "dlr_code" is missing from the delivery event payload.');

$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => ['id' => '123'],
]);
$this->parser->parse($request, '');
}

public function testStatusCode100()
public function testSmsDeliveryStatusCode100()
{
$payload = [
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'status_code' => 100,
],
];
$request = $this->getRequest($payload);

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(SmsEvent::class, $event);
$this->assertSame('123', $event->getId());
$this->assertSame(SmsEvent::DELIVERED, $event->getName());
$this->assertSame($payload, $event->getPayload());
}

public function testStatusCode0()
public function testSmsDeliveryStatusCode0()
{
$request = $this->getRequest(
[
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'status_code' => 0,
],
]
);
$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'status_code' => 0,
],
]);

$event = $this->parser->parse($request, '');
$this->assertNull($event);
}

public function testStatusCodeUnknown()
public function testSmsDeliveryWithDlrCodeDelivered()
{
$payload = [
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'status_code' => 410,
'dlr_code' => 1,
'callback_data' => 'test-callback',
],
];

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(SmsEvent::class, $event);
$this->assertSame('123', $event->getId());
$this->assertSame(SmsEvent::DELIVERED, $event->getName());
$this->assertSame($payload, $event->getPayload());
}

public function testSmsDeliveryWithDlrCodeFailed()
{
$payload = [
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'dlr_code' => 16,
],
];

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(SmsEvent::class, $event);
$this->assertSame('123', $event->getId());
$this->assertSame(SmsEvent::FAILED, $event->getName());
}

public function testSmsDeliveryWithDlrCodePending()
{
$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'dlr_code' => 2,
],
]);

$event = $this->parser->parse($request, '');
$this->assertNull($event);
}

public function testSmsDeliveryDryrun()
{
$payload = [
'id' => 'webhook-id',
'name' => 'sms.delivery.dryrun',
'data' => [
'id' => '123',
'status_code' => 100,
],
];

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(SmsEvent::class, $event);
$this->assertSame('123', $event->getId());
$this->assertSame(SmsEvent::DELIVERED, $event->getName());
}

public function testMissingIdField()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('The required fields "id" are missing from the payload.');

$request = $this->getRequest([
'name' => 'sms.delivery',
'data' => ['id' => '123'],
]);
$this->parser->parse($request, '');
}

public function testMissingNameField()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('The required fields "name" are missing from the payload.');

$request = $this->getRequest([
'id' => 'webhook-id',
'data' => ['id' => '123'],
]);
$this->parser->parse($request, '');
}

public function testMissingDataField()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('The required fields "data" are missing from the payload.');

$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
]);
$this->parser->parse($request, '');
}

public function testInvalidDataFieldNotArray()
{
$this->expectException(RejectWebhookException::class);
$this->expectExceptionMessage('The "data" field must be an array.');

$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => 'invalid-data',
]);
$this->parser->parse($request, '');
}

public function testRemoteEventForUnknownEventType()
{
$payload = [
'id' => 'webhook-id',
'name' => 'custom.event',
'data' => ['some' => 'data'],
];

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(RemoteEvent::class, $event);
$this->assertSame('webhook-id', $event->getId());
$this->assertSame('custom.event', $event->getName());
$this->assertSame($payload, $event->getPayload());
}

public function testSmsDeliveryStatusCodeFailed()
{
$payload = [
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'status_code' => 500,
],
];

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(SmsEvent::class, $event);
$this->assertSame('123', $event->getId());
$this->assertSame(SmsEvent::FAILED, $event->getName());
$this->assertSame($payload, $event->getPayload());
}

public function testSmsDeliveryWithDlrCode0()
{
$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'dlr_code' => 0,
],
]);

$event = $this->parser->parse($request, '');
$this->assertNull($event);
}

public function testSmsDeliveryWithDlrCode4()
{
$request = $this->getRequest([
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'dlr_code' => 4,
],
]);

$event = $this->parser->parse($request, '');
$this->assertNull($event);
}

public function testSmsDeliveryDlrCodePriorityOverStatusCode()
{
$payload = [
'id' => 'webhook-id',
'name' => 'sms.delivery',
'data' => [
'id' => '123',
'dlr_code' => 1,
'status_code' => 500,
],
];

$request = $this->getRequest($payload);
$event = $this->parser->parse($request, '');

$this->assertInstanceOf(SmsEvent::class, $event);
$this->assertSame('123', $event->getId());
$this->assertSame(SmsEvent::DELIVERED, $event->getName());
$this->assertSame($payload, $event->getPayload());
}

Expand Down
Loading
Loading