1+ <?php
2+
3+ use Carbon \Carbon ;
4+ use Dotenv \Dotenv ;
5+ use FiveamCode \LaravelNotionApi \Entities \Collections \CommentCollection ;
6+ use FiveamCode \LaravelNotionApi \Entities \Comment ;
7+ use FiveamCode \LaravelNotionApi \Entities \PropertyItems \RichText ;
8+ use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
9+ use Illuminate \Support \Facades \Config ;
10+ use Illuminate \Support \Facades \Http ;
11+ use YourVendor \YourPackage \Middleware \InterceptRequestesForRecording ;
12+
13+ beforeEach (function () {
14+ Http::recordAndFakeLater ('https://api.notion.com/v1/comments* ' )
15+ ->storeIn ('__recorded__/comments ' );
16+ });
17+
18+ it ('should fetch list of comments with an accurate representation of attributes ' , function () {
19+ $ commentCollection = \Notion::comments ()->ofBlock ('cb588bcbcbdb4f2eac3db05446b8f5d9 ' );
20+
21+ $ collection = $ commentCollection ->asCollection ();
22+ $ json = $ commentCollection ->asJson ();
23+
24+ expect ($ commentCollection )->toBeInstanceOf (CommentCollection::class);
25+ expect ($ collection )->toBeInstanceOf (\Illuminate \Support \Collection::class);
26+ expect ($ json )->toBeString ();
27+
28+ expect ($ collection ->count ())->toBe (1 );
29+ expect ($ collection ->first ())->toBeInstanceOf (Comment::class);
30+ expect ($ collection ->first ()->getObjectType ())->toBe ('comment ' );
31+ expect ($ collection ->first ()->getId ())->toBe ('99457ae4-8262-413a-b224-0bd82346d885 ' );
32+ expect ($ collection ->first ()->getCreatedTime ())->toEqual (Carbon::parse ('2023-02-18T10:53:00.000000+0000 ' )->toDateTime ());
33+ expect ($ collection ->first ()->getLastEditedTime ())->toEqual (Carbon::parse ('2023-02-18T10:53:00.000000+0000 ' )->toDateTime ());
34+ expect ($ collection ->first ()->getCreatedBy ()->getId ())->toBe ('04536682-603a-4531-a18f-4fa89fdfb4a8 ' );
35+ expect ($ collection ->first ()->getLastEditedBy ())->toBe (null );
36+ expect ($ collection ->first ()->getText ())->toBe ('This is a Test Comment for Laravel ' );
37+ expect ($ collection ->first ()->getRichText ()->getPlainText ())->toBe ('This is a Test Comment for Laravel ' );
38+ expect ($ collection ->first ()->getRichText ())->toBeInstanceOf (RichText::class);
39+ expect ($ collection ->first ()->getParentId ())->toBe ('cb588bcb-cbdb-4f2e-ac3d-b05446b8f5d9 ' );
40+ expect ($ collection ->first ()->getParentType ())->toBe ('page_id ' );
41+ expect ($ collection ->first ()->getDiscussionId ())->toBe ('f203fa27-fe02-40c9-be9f-fb35e2e956ba ' );
42+
43+ expect ($ json )->toBeJson ();
44+ });
45+
46+ it ('should throw correct exception if block_id has not been found when listing comments ' , function () {
47+ $ this ->expectException (NotionException::class);
48+ $ this ->expectExceptionMessage ('Not Found ' );
49+ $ this ->expectExceptionCode (404 );
50+
51+ \Notion::comments ()->ofBlock ('cbf6b0af-6eaa-45ca-9715-9fa147ef6b17 ' )->list ();
52+ });
0 commit comments