|
6 | 6 | use CodebarAg\LaravelBeekeeper\Data\Streams\Post; |
7 | 7 | use CodebarAg\LaravelBeekeeper\Requests\CreateAPostInAGivenStream; |
8 | 8 | use Illuminate\Support\Collection; |
| 9 | +use Saloon\Http\Faking\MockResponse; |
| 10 | +use Saloon\Laravel\Facades\Saloon; |
9 | 11 |
|
10 | 12 | test('can create a post in a given stream with minimal data', closure: function () { |
11 | | - $connector = new BeekeeperConnector; |
| 13 | + Saloon::fake([ |
| 14 | + CreateAPostInAGivenStream::class => MockResponse::make([ |
| 15 | + 'id' => 12345, |
| 16 | + 'text' => 'Please indicate your preferred dates for next team event in the poll below. Thanks!', |
| 17 | + 'title' => null, |
| 18 | + 'labels' => [], |
| 19 | + 'sticky' => false, |
| 20 | + 'like_count' => 0, |
| 21 | + 'streamid' => 6002, |
| 22 | + 'digest' => 1, |
| 23 | + 'user_id' => 'user-123', |
| 24 | + 'uuid' => 'post-uuid-123', |
| 25 | + 'comment_count' => 0, |
| 26 | + 'report_count' => 0, |
| 27 | + 'source' => 'web', |
| 28 | + 'vote_count' => 0, |
| 29 | + 'moderated' => false, |
| 30 | + 'photo' => null, |
| 31 | + 'language_confidence' => null, |
| 32 | + 'type' => 'post', |
| 33 | + 'metadata' => null, |
| 34 | + 'profile' => null, |
| 35 | + 'edited' => false, |
| 36 | + 'display_name_extension' => null, |
| 37 | + 'subscribed_by_user' => false, |
| 38 | + 'reportable' => true, |
| 39 | + 'anonymous' => false, |
| 40 | + 'display_name' => null, |
| 41 | + 'unread' => false, |
| 42 | + 'locked' => false, |
| 43 | + 'reactions_disabled' => false, |
| 44 | + 'name' => null, |
| 45 | + 'language' => null, |
| 46 | + 'language_information' => null, |
| 47 | + 'created' => '2023-01-01T00:00:00Z', |
| 48 | + 'posted_by_user' => true, |
| 49 | + 'avatar' => null, |
| 50 | + 'reported_by_user' => false, |
| 51 | + 'liked_by_user' => false, |
| 52 | + 'mentions' => [], |
| 53 | + 'mentions_details' => null, |
| 54 | + 'scheduled_at' => null, |
| 55 | + 'status' => null, |
| 56 | + 'files' => [], |
| 57 | + 'photos' => [], |
| 58 | + 'videos' => [], |
| 59 | + 'media' => [], |
| 60 | + 'options' => [], |
| 61 | + 'state_id' => null, |
| 62 | + ], 200), |
| 63 | + ]); |
12 | 64 |
|
| 65 | + $connector = new BeekeeperConnector; |
13 | 66 | $response = $connector->send(new CreateAPostInAGivenStream( |
14 | 67 | streamId: '6002', |
15 | 68 | text: 'Please indicate your preferred dates for next team event in the poll below. Thanks!' |
|
33 | 86 | })->group('streams'); |
34 | 87 |
|
35 | 88 | test('can create a post in a given stream with all optional parameters', closure: function () { |
36 | | - $connector = new BeekeeperConnector; |
37 | | - |
38 | 89 | $fileData = [ |
39 | 90 | 'updated' => '2016-10-07T12:49:21', |
40 | 91 | 'name' => 'fair_play_rules.pdf', |
|
51 | 102 | 'size' => 85, |
52 | 103 | ]; |
53 | 104 |
|
| 105 | + Saloon::fake([ |
| 106 | + CreateAPostInAGivenStream::class => MockResponse::make([ |
| 107 | + 'id' => 12345, |
| 108 | + 'text' => 'Please indicate your preferred dates for next team event in the poll below. Thanks!', |
| 109 | + 'title' => 'Hello guys!', |
| 110 | + 'labels' => ['food', 'poll', 'events'], |
| 111 | + 'sticky' => true, |
| 112 | + 'like_count' => 0, |
| 113 | + 'streamid' => 6002, |
| 114 | + 'digest' => 1, |
| 115 | + 'user_id' => 'user-123', |
| 116 | + 'uuid' => 'post-uuid-123', |
| 117 | + 'comment_count' => 0, |
| 118 | + 'report_count' => 0, |
| 119 | + 'source' => 'web', |
| 120 | + 'vote_count' => 0, |
| 121 | + 'moderated' => false, |
| 122 | + 'photo' => null, |
| 123 | + 'language_confidence' => null, |
| 124 | + 'type' => 'post', |
| 125 | + 'metadata' => null, |
| 126 | + 'profile' => null, |
| 127 | + 'edited' => false, |
| 128 | + 'display_name_extension' => null, |
| 129 | + 'subscribed_by_user' => false, |
| 130 | + 'reportable' => true, |
| 131 | + 'anonymous' => false, |
| 132 | + 'display_name' => null, |
| 133 | + 'unread' => false, |
| 134 | + 'locked' => true, |
| 135 | + 'reactions_disabled' => true, |
| 136 | + 'name' => null, |
| 137 | + 'language' => null, |
| 138 | + 'language_information' => null, |
| 139 | + 'created' => '2023-01-01T00:00:00Z', |
| 140 | + 'posted_by_user' => true, |
| 141 | + 'avatar' => null, |
| 142 | + 'reported_by_user' => false, |
| 143 | + 'liked_by_user' => false, |
| 144 | + 'mentions' => [], |
| 145 | + 'mentions_details' => null, |
| 146 | + 'scheduled_at' => '2019-08-24T14:15:22Z', |
| 147 | + 'status' => null, |
| 148 | + 'files' => [$fileData], |
| 149 | + 'photos' => [$fileData], |
| 150 | + 'videos' => [$fileData], |
| 151 | + 'media' => [$fileData], |
| 152 | + 'options' => [ |
| 153 | + ['text' => 'This Friday'], |
| 154 | + ['text' => 'Monday next week'], |
| 155 | + ], |
| 156 | + 'state_id' => null, |
| 157 | + ], 200), |
| 158 | + ]); |
| 159 | + |
| 160 | + $connector = new BeekeeperConnector; |
54 | 161 | $response = $connector->send(new CreateAPostInAGivenStream( |
55 | 162 | streamId: '6002', |
56 | 163 | text: 'Please indicate your preferred dates for next team event in the poll below. Thanks!', |
|
97 | 204 | })->group('streams'); |
98 | 205 |
|
99 | 206 | test('can create a post with collection parameters', closure: function () { |
100 | | - $connector = new BeekeeperConnector; |
101 | | - |
102 | 207 | $fileData = [ |
103 | 208 | 'updated' => '2016-10-07T12:49:21', |
104 | 209 | 'name' => 'test_file.pdf', |
|
115 | 220 | 'size' => 1024, |
116 | 221 | ]; |
117 | 222 |
|
| 223 | + Saloon::fake([ |
| 224 | + CreateAPostInAGivenStream::class => MockResponse::make([ |
| 225 | + 'id' => 12345, |
| 226 | + 'text' => 'Test post with collections', |
| 227 | + 'title' => null, |
| 228 | + 'labels' => ['test', 'collection'], |
| 229 | + 'sticky' => false, |
| 230 | + 'like_count' => 0, |
| 231 | + 'streamid' => 6002, |
| 232 | + 'digest' => 1, |
| 233 | + 'user_id' => 'user-123', |
| 234 | + 'uuid' => 'post-uuid-123', |
| 235 | + 'comment_count' => 0, |
| 236 | + 'report_count' => 0, |
| 237 | + 'source' => 'web', |
| 238 | + 'vote_count' => 0, |
| 239 | + 'moderated' => false, |
| 240 | + 'photo' => null, |
| 241 | + 'language_confidence' => null, |
| 242 | + 'type' => 'post', |
| 243 | + 'metadata' => null, |
| 244 | + 'profile' => null, |
| 245 | + 'edited' => false, |
| 246 | + 'display_name_extension' => null, |
| 247 | + 'subscribed_by_user' => false, |
| 248 | + 'reportable' => true, |
| 249 | + 'anonymous' => false, |
| 250 | + 'display_name' => null, |
| 251 | + 'unread' => false, |
| 252 | + 'locked' => false, |
| 253 | + 'reactions_disabled' => false, |
| 254 | + 'name' => null, |
| 255 | + 'language' => null, |
| 256 | + 'language_information' => null, |
| 257 | + 'created' => '2023-01-01T00:00:00Z', |
| 258 | + 'posted_by_user' => true, |
| 259 | + 'avatar' => null, |
| 260 | + 'reported_by_user' => false, |
| 261 | + 'liked_by_user' => false, |
| 262 | + 'mentions' => [], |
| 263 | + 'mentions_details' => null, |
| 264 | + 'scheduled_at' => null, |
| 265 | + 'status' => null, |
| 266 | + 'files' => [$fileData], |
| 267 | + 'photos' => [], |
| 268 | + 'videos' => [], |
| 269 | + 'media' => [], |
| 270 | + 'options' => [ |
| 271 | + ['text' => 'Option 1'], |
| 272 | + ['text' => 'Option 2'], |
| 273 | + ], |
| 274 | + 'state_id' => null, |
| 275 | + ], 200), |
| 276 | + ]); |
| 277 | + |
| 278 | + $connector = new BeekeeperConnector; |
118 | 279 | $response = $connector->send(new CreateAPostInAGivenStream( |
119 | 280 | streamId: '6002', |
120 | 281 | text: 'Test post with collections', |
|
138 | 299 | })->group('streams'); |
139 | 300 |
|
140 | 301 | test('post response contains all expected fields', closure: function () { |
141 | | - $connector = new BeekeeperConnector; |
| 302 | + Saloon::fake([ |
| 303 | + CreateAPostInAGivenStream::class => MockResponse::make([ |
| 304 | + 'id' => 12345, |
| 305 | + 'text' => 'Test post for field validation', |
| 306 | + 'title' => 'Test Title', |
| 307 | + 'labels' => [], |
| 308 | + 'sticky' => false, |
| 309 | + 'like_count' => 5, |
| 310 | + 'streamid' => 6002, |
| 311 | + 'digest' => 1, |
| 312 | + 'user_id' => 'user-123', |
| 313 | + 'uuid' => 'post-uuid-123', |
| 314 | + 'comment_count' => 3, |
| 315 | + 'report_count' => 0, |
| 316 | + 'source' => 'web', |
| 317 | + 'vote_count' => 2, |
| 318 | + 'moderated' => false, |
| 319 | + 'photo' => 'photo-url', |
| 320 | + 'language_confidence' => 0.95, |
| 321 | + 'type' => 'post', |
| 322 | + 'metadata' => '{"key": "value"}', |
| 323 | + 'profile' => 'profile-123', |
| 324 | + 'edited' => false, |
| 325 | + 'display_name_extension' => 'Jr.', |
| 326 | + 'subscribed_by_user' => true, |
| 327 | + 'reportable' => true, |
| 328 | + 'anonymous' => false, |
| 329 | + 'display_name' => 'John Doe', |
| 330 | + 'unread' => false, |
| 331 | + 'locked' => false, |
| 332 | + 'reactions_disabled' => false, |
| 333 | + 'name' => 'John', |
| 334 | + 'language' => 'en', |
| 335 | + 'language_information' => ['confidence' => 0.95], |
| 336 | + 'created' => '2023-01-01T00:00:00Z', |
| 337 | + 'posted_by_user' => true, |
| 338 | + 'avatar' => 'https://example.com/avatar.jpg', |
| 339 | + 'reported_by_user' => false, |
| 340 | + 'liked_by_user' => true, |
| 341 | + 'mentions' => [], |
| 342 | + 'mentions_details' => null, |
| 343 | + 'scheduled_at' => null, |
| 344 | + 'status' => 'published', |
| 345 | + 'files' => [], |
| 346 | + 'photos' => [], |
| 347 | + 'videos' => [], |
| 348 | + 'media' => [], |
| 349 | + 'options' => [], |
| 350 | + 'state_id' => 'state-123', |
| 351 | + ], 200), |
| 352 | + ]); |
142 | 353 |
|
| 354 | + $connector = new BeekeeperConnector; |
143 | 355 | $response = $connector->send(new CreateAPostInAGivenStream( |
144 | 356 | streamId: '6002', |
145 | 357 | text: 'Test post for field validation', |
|
189 | 401 | ->and($post->mentions)->toBeInstanceOf(Collection::class); |
190 | 402 |
|
191 | 403 | // Test optional fields |
192 | | - expect($post->photo)->toBeStringOrNull() |
193 | | - ->and($post->languageConfidence)->toBeFloatOrNull() |
194 | | - ->and($post->metadata)->toBeStringOrNull() |
195 | | - ->and($post->profile)->toBeStringOrNull() |
196 | | - ->and($post->displayNameExtension)->toBeStringOrNull() |
197 | | - ->and($post->displayName)->toBeStringOrNull() |
198 | | - ->and($post->name)->toBeStringOrNull() |
199 | | - ->and($post->language)->toBeStringOrNull() |
200 | | - ->and($post->avatar)->toBeStringOrNull() |
201 | | - ->and($post->status)->toBeStringOrNull() |
202 | | - ->and($post->stateId)->toBeStringOrNull(); |
| 404 | + expect($post->photo)->toBeString() |
| 405 | + ->and($post->languageConfidence)->toBeFloat() |
| 406 | + ->and($post->metadata)->toBeString() |
| 407 | + ->and($post->profile)->toBeString() |
| 408 | + ->and($post->displayNameExtension)->toBeString() |
| 409 | + ->and($post->displayName)->toBeString() |
| 410 | + ->and($post->name)->toBeString() |
| 411 | + ->and($post->language)->toBeString() |
| 412 | + ->and($post->avatar)->toBeString() |
| 413 | + ->and($post->status)->toBeString() |
| 414 | + ->and($post->stateId)->toBeString(); |
203 | 415 |
|
204 | 416 | // Test timestamps |
205 | 417 | if ($post->created) { |
|
0 commit comments