Skip to content

Commit

Permalink
Add test coverage for Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston-paddle committed Sep 13, 2024
1 parent b3bf7e8 commit 626dec4
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Unit/Notifications/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Paddle\SDK\Tests\Unit\Notifications;

use Paddle\SDK\Notifications\Entities\Business;
use Paddle\SDK\Notifications\Entities\Entity;
use Paddle\SDK\Notifications\Events\BusinessUpdated;
use Paddle\SDK\Notifications\Notification;
use Paddle\SDK\Tests\Utils\ReadsFixtures;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;

class NotificationTest extends TestCase
{
use ReadsFixtures;

/** @test */
public function it_creates_from_data(): void
{
$data = self::readJsonFixture('notification_business_updated');

$notification = Notification::from($data);

self::assertSame('ntf_01h8bzam1z32agrxjwhjgqk8w6', $notification->id);

$event = $notification->event;
self::assertInstanceOf(BusinessUpdated::class, $event);
self::assertInstanceOf(Entity::class, $event->data);
self::assertSame('evt_01h8bzakzx3hm2fmen703n5q45', $event->eventId);
self::assertSame('2023-08-21T11:57:47.390+00:00', $event->occurredAt->format(DATE_RFC3339_EXTENDED));
self::assertSame('business.updated', $event->eventType->getValue());

$business = $event->business;
self::assertInstanceOf(Business::class, $business);
self::assertSame('biz_01h84a7hr4pzhsajkm8tev89ev', $business->id);
self::assertSame('ChatApp Inc.', $business->name);
self::assertSame('active', $business->status->getValue());
}

/** @test */
public function it_creates_from_request(): void
{
$requestStream = $this->createMock(StreamInterface::class);
$requestStream
->method('__toString')
->willReturn(self::readRawJsonFixture('notification_business_updated'));

$request = $this->createMock(ServerRequestInterface::class);
$request
->method('getBody')
->willReturn($requestStream);

$notification = Notification::fromRequest($request);

self::assertSame('ntf_01h8bzam1z32agrxjwhjgqk8w6', $notification->id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"data": {
"id": "biz_01h84a7hr4pzhsajkm8tev89ev",
"name": "ChatApp Inc.",
"status": "active",
"contacts": [
{
"name": "Parker Jones",
"email": "[email protected]"
},
{
"name": "Jo Riley",
"email": "[email protected]"
},
{
"name": "Jesse Garcia",
"email": "[email protected]"
}
],
"created_at": "2023-08-18T12:34:25.668Z",
"updated_at": "2023-08-21T11:57:47.03542Z",
"company_number": "555775291485",
"tax_identifier": null
},
"event_id": "evt_01h8bzakzx3hm2fmen703n5q45",
"event_type": "business.updated",
"occurred_at": "2023-08-21T11:57:47.390028Z",
"notification_id": "ntf_01h8bzam1z32agrxjwhjgqk8w6"
}

0 comments on commit 626dec4

Please sign in to comment.