From 3ae4fa3cd4ca898c139a78f6244dfe99eddddc3e Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 13 Sep 2024 19:14:12 +0100 Subject: [PATCH] Add test coverage for Notifications --- tests/Unit/Notifications/NotificationTest.php | 60 +++++++++++++++++++ .../notification_business_updated.json | 29 +++++++++ 2 files changed, 89 insertions(+) create mode 100644 tests/Unit/Notifications/NotificationTest.php create mode 100644 tests/Unit/Notifications/_fixtures/notification_business_updated.json diff --git a/tests/Unit/Notifications/NotificationTest.php b/tests/Unit/Notifications/NotificationTest.php new file mode 100644 index 0000000..1df1857 --- /dev/null +++ b/tests/Unit/Notifications/NotificationTest.php @@ -0,0 +1,60 @@ +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); + } +} diff --git a/tests/Unit/Notifications/_fixtures/notification_business_updated.json b/tests/Unit/Notifications/_fixtures/notification_business_updated.json new file mode 100644 index 0000000..c3c93c8 --- /dev/null +++ b/tests/Unit/Notifications/_fixtures/notification_business_updated.json @@ -0,0 +1,29 @@ +{ + "data": { + "id": "biz_01h84a7hr4pzhsajkm8tev89ev", + "name": "ChatApp Inc.", + "status": "active", + "contacts": [ + { + "name": "Parker Jones", + "email": "parker@example.com" + }, + { + "name": "Jo Riley", + "email": "jo@example.com" + }, + { + "name": "Jesse Garcia", + "email": "jo@example.com" + } + ], + "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" +}