Skip to content

Commit

Permalink
adding change type actual received string from web hook for logging p…
Browse files Browse the repository at this point in the history
…urposes
  • Loading branch information
frets1700 committed Nov 13, 2024
1 parent a62c5a0 commit 733abc4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Entities/NotificationReaderEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class NotificationReaderEntity implements \JsonSerializable, NotificationReaderE
protected ?string $id = null;
protected ?string $tenantId = null;

protected ?string $changeTypeString = null;

/** @param array<string, mixed> $data */
public function __construct(array $data = [])
{
Expand Down Expand Up @@ -61,6 +63,7 @@ public function setSubscriptionId(?string $subscriptionId): NotificationReaderEn

public function setChangeType(?string $changeType = null): NotificationReaderEntityInterface
{
$this->setChangeTypeReceivedString($changeType);
$this->changeType = ChangeType::UNKNOWN;
if (isset($changeType) && ($value = ChangeType::tryFrom($changeType))) {
$this->changeType = $value;
Expand Down Expand Up @@ -126,4 +129,15 @@ public function getTenantId(): ?string
{
return $this->tenantId;
}

// MARK: Logging purpose only
public function getChangeTypeReceivedString(): ?string
{
return $this->changeTypeString;
}

protected function setChangeTypeReceivedString(?string $changeType = null): void
{
$this->changeTypeString = $changeType;
}
}
20 changes: 20 additions & 0 deletions tests/Notification/ReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function testExec()
$this->assertSame('#Microsoft.Graph.Event', $entity->getODataType());
$this->assertSame('2023-12-10T18:23:45+00:00', $entity->getSubscriptionExpirationDateTime());
$this->assertSame('tenant_id_1', $entity->getTenantId());
$this->assertSame(ChangeType::UPDATED->value, $entity->getChangeTypeReceivedString());

$this->receiverStub->hydrate([$entity]);
$this->receiverStub->exec(
Expand Down Expand Up @@ -121,6 +122,25 @@ public function testEntity(): void
$this->assertEquals(ChangeType::UPDATED, $entity->getChangeType());
}

public function testChangeTypeString(): void
{
$entity = new NotificationReaderEntity();
$entity->setResource('test.com')
->setId('123')
->setChangeType(ChangeType::CREATED->value)
->setSubscriptionId('ABC==');

$this->assertEquals(ChangeType::CREATED->value, $entity->getChangeTypeReceivedString());

$entity->setChangeType('Changed');
$this->assertEquals('Changed', $entity->getChangeTypeReceivedString());
$this->assertEquals(ChangeType::UNKNOWN, $entity->getChangeType());

$entity->setChangeType();
$this->assertEquals(null, $entity->getChangeTypeReceivedString());
$this->assertEquals(ChangeType::UNKNOWN, $entity->getChangeType());
}

protected function getOData(): array
{
return [
Expand Down

0 comments on commit 733abc4

Please sign in to comment.