-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5bc39dc
commit 3ae4fa3
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Unit/Notifications/_fixtures/notification_business_updated.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |