34
34
use Kerox \Messenger \Model \Callback \Optin ;
35
35
use Kerox \Messenger \Model \Callback \PassThreadControl ;
36
36
use Kerox \Messenger \Model \Callback \Payment ;
37
+ use Kerox \Messenger \Model \Callback \Payment \PaymentCredential ;
38
+ use Kerox \Messenger \Model \Callback \Payment \RequestedUserInfo ;
37
39
use Kerox \Messenger \Model \Callback \PolicyEnforcement ;
38
40
use Kerox \Messenger \Model \Callback \Postback ;
39
41
use Kerox \Messenger \Model \Callback \PreCheckout ;
42
44
use Kerox \Messenger \Model \Callback \Referral ;
43
45
use Kerox \Messenger \Model \Callback \RequestThreadControl ;
44
46
use Kerox \Messenger \Model \Callback \TakeThreadControl ;
47
+ use Kerox \Messenger \Model \Common \Address ;
45
48
use Kerox \Messenger \Test \TestCase \AbstractTestCase ;
46
49
47
50
class EventFactoryTest extends AbstractTestCase
@@ -57,6 +60,11 @@ public function testRawEvent(): void
57
60
$ this ->assertEquals ($ expectedEvent , $ event );
58
61
}
59
62
63
+ public function testEntryEvent (): void
64
+ {
65
+
66
+ }
67
+
60
68
public function testMessageEvent (): void
61
69
{
62
70
$ json = file_get_contents (__DIR__ . '/../../Mocks/Event/message.json ' );
@@ -66,6 +74,24 @@ public function testMessageEvent(): void
66
74
$ event = EventFactory::create ($ array );
67
75
68
76
$ this ->assertEquals ($ expectedEvent , $ event );
77
+
78
+ $ message = $ event ->getMessage ();
79
+ $ this ->assertSame ('mid.1457764197618:41d102a3e1ae206a38 ' , $ message ->getMessageId ());
80
+ $ this ->assertTrue ($ message ->hasText ());
81
+ $ this ->assertSame ('hello, world! ' , $ message ->getText ());
82
+ $ this ->assertTrue ($ message ->hasQuickReply ());
83
+ $ this ->assertSame ('DEVELOPER_DEFINED_PAYLOAD ' , $ message ->getQuickReply ());
84
+ $ this ->assertTrue ($ message ->hasAttachments ());
85
+ $ this ->assertSame ([['type ' => 'image ' , 'payload ' => ['url ' => 'IMAGE_URL ' ]]], $ message ->getAttachments ());
86
+ $ this ->assertTrue ($ message ->hasEntities ());
87
+ $ this ->assertSame ([
88
+ 'datetime ' => [
89
+ ['confidence ' => 0.97249440664957 , 'values ' => ['... ' ], 'value ' => '2017-05-10T14:00:00.000-07:00 ' , 'grain ' => 'hour ' , 'type ' => 'value ' ]
90
+ ],
91
+ 'greetings ' => [
92
+ ['confidence ' => 1 , 'value ' => 'true ' ]
93
+ ]
94
+ ], $ message ->getEntities ());
69
95
}
70
96
71
97
public function testMessageEchoEvent (): void
@@ -77,6 +103,12 @@ public function testMessageEchoEvent(): void
77
103
$ event = EventFactory::create ($ array );
78
104
79
105
$ this ->assertEquals ($ expectedEvent , $ event );
106
+
107
+ $ messageEcho = $ event ->getMessageEcho ();
108
+ $ this ->assertTrue ($ messageEcho ->isEcho ());
109
+ $ this ->assertSame (1517776481860111 , $ messageEcho ->getAppId ());
110
+ $ this ->assertSame ('DEVELOPER_DEFINED_METADATA_STRING ' , $ messageEcho ->getMetadata ());
111
+ $ this ->assertSame ('mid.1457764197618:41d102a3e1ae206a38 ' , $ messageEcho ->getMessageId ());
80
112
}
81
113
82
114
public function testPostbackEvent (): void
@@ -88,6 +120,31 @@ public function testPostbackEvent(): void
88
120
$ event = EventFactory::create ($ array );
89
121
90
122
$ this ->assertEquals ($ expectedEvent , $ event );
123
+
124
+ $ postback = $ event ->getPostback ();
125
+ $ this ->assertSame ('TITLE_FOR_THE_CTA ' , $ postback ->getTitle ());
126
+ $ this ->assertTrue ($ postback ->hasPayload ());
127
+ $ this ->assertSame ('USER_DEFINED_PAYLOAD ' , $ postback ->getPayload ());
128
+ $ this ->assertTrue ($ postback ->hasReferral ());
129
+ $ this ->assertInstanceOf (Referral::class, $ postback ->getReferral ());
130
+ }
131
+
132
+ public function testPostbackEventFromStandBy (): void
133
+ {
134
+ $ json = file_get_contents (__DIR__ . '/../../Mocks/Event/postback_from_stand_by.json ' );
135
+ $ array = json_decode ($ json , true );
136
+
137
+ $ expectedEvent = new PostbackEvent ('USER_ID ' , 'PAGE_ID ' , 1458692752478 , Postback::create ($ array ['postback ' ]));
138
+ $ event = EventFactory::create ($ array );
139
+
140
+ $ this ->assertEquals ($ expectedEvent , $ event );
141
+
142
+ $ postback = $ event ->getPostback ();
143
+ $ this ->assertSame ('TITLE_FOR_THE_CTA ' , $ postback ->getTitle ());
144
+ $ this ->assertFalse ($ postback ->hasPayload ());
145
+ $ this ->assertNull ($ postback ->getPayload ());
146
+ $ this ->assertFalse ($ postback ->hasReferral ());
147
+ $ this ->assertNull ($ postback ->getReferral ());
91
148
}
92
149
93
150
public function testOptinEvent (): void
@@ -99,6 +156,9 @@ public function testOptinEvent(): void
99
156
$ event = EventFactory::create ($ array );
100
157
101
158
$ this ->assertEquals ($ expectedEvent , $ event );
159
+
160
+ $ optin = $ event ->getOptin ();
161
+ $ this ->assertSame ('PASS_THROUGH_PARAM ' , $ optin ->getRef ());
102
162
}
103
163
104
164
public function testAccountLinkingEvent (): void
@@ -110,6 +170,11 @@ public function testAccountLinkingEvent(): void
110
170
$ event = EventFactory::create ($ array );
111
171
112
172
$ this ->assertEquals ($ expectedEvent , $ event );
173
+
174
+ $ accountLinking = $ event ->getAccountLinking ();
175
+ $ this ->assertSame ('linked ' , $ accountLinking ->getStatus ());
176
+ $ this ->assertTrue ($ accountLinking ->hasAuthorizationCode ());
177
+ $ this ->assertSame ('PASS_THROUGH_AUTHORIZATION_CODE ' , $ accountLinking ->getAuthorizationCode ());
113
178
}
114
179
115
180
public function testDeliveryEvent (): void
@@ -121,6 +186,10 @@ public function testDeliveryEvent(): void
121
186
$ event = EventFactory::create ($ array );
122
187
123
188
$ this ->assertEquals ($ expectedEvent , $ event );
189
+
190
+ $ delivery = $ event ->getDelivery ();
191
+ $ this ->assertSame (1458668856253 , $ delivery ->getWatermark ());
192
+ $ this ->assertSame (['mid.1458668856218:ed81099e15d3f4f233 ' ], $ delivery ->getMessageIds ());
124
193
}
125
194
126
195
public function testReadEvent (): void
@@ -132,6 +201,9 @@ public function testReadEvent(): void
132
201
$ event = EventFactory::create ($ array );
133
202
134
203
$ this ->assertEquals ($ expectedEvent , $ event );
204
+
205
+ $ read = $ event ->getRead ();
206
+ $ this ->assertSame (1458668856253 , $ read ->getWatermark ());
135
207
}
136
208
137
209
public function testPaymentEvent (): void
@@ -143,6 +215,37 @@ public function testPaymentEvent(): void
143
215
$ event = EventFactory::create ($ array );
144
216
145
217
$ this ->assertEquals ($ expectedEvent , $ event );
218
+
219
+ $ payment = $ event ->getPayment ();
220
+ $ this ->assertSame ('DEVELOPER_DEFINED_PAYLOAD ' , $ payment ->getPayload ());
221
+ $ this ->assertSame ('123 ' , $ payment ->getShippingOptionId ());
222
+ $ this ->assertSame ('USD ' , $ payment ->getCurrency ());
223
+ $ this ->assertSame ('29.62 ' , $ payment ->getAmount ());
224
+ $ this ->assertInstanceOf (RequestedUserInfo::class, $ payment ->getRequestedUserInfo ());
225
+ $ this ->assertInstanceOf (PaymentCredential::class, $ payment ->getPaymentCredential ());
226
+ $ this ->assertInstanceOf (Address::class, $ payment ->getShippingAddress ());
227
+
228
+ $ requestedUserInfo = $ payment ->getRequestedUserInfo ();
229
+ $ this ->assertSame ('Peter Chang ' , $ requestedUserInfo ->getContactName ());
230
+ $ this ->
assertSame (
'[email protected] ' ,
$ requestedUserInfo->
getContactEmail ());
231
+ $ this ->assertSame ('+15105551234 ' , $ requestedUserInfo ->getContactPhone ());
232
+
233
+ $ paymentCredential = $ payment ->getPaymentCredential ();
234
+ $ this ->assertSame ('token ' , $ paymentCredential ->getProviderType ());
235
+ $ this ->assertSame ('ch_18tmdBEoNIH3FPJHa60ep123 ' , $ paymentCredential ->getChargeId ());
236
+ $ this ->assertSame ('__tokenized_card__ ' , $ paymentCredential ->getTokenizedCard ());
237
+ $ this ->assertSame ('tokenized cvv ' , $ paymentCredential ->getTokenizedCvv ());
238
+ $ this ->assertSame ('3 ' , $ paymentCredential ->getTokenExpiryMonth ());
239
+ $ this ->assertSame ('2019 ' , $ paymentCredential ->getTokenExpiryYear ());
240
+ $ this ->assertSame ('123456789 ' , $ paymentCredential ->getFbPaymentId ());
241
+
242
+ $ shippingAddress = $ payment ->getShippingAddress ();
243
+ $ this ->assertSame ('1 Hacker Way ' , $ shippingAddress ->getStreet ());
244
+ $ this ->assertSame ('' , $ shippingAddress ->getAdditionalStreet ());
245
+ $ this ->assertSame ('MENLO PARK ' , $ shippingAddress ->getCity ());
246
+ $ this ->assertSame ('CA ' , $ shippingAddress ->getState ());
247
+ $ this ->assertSame ('US ' , $ shippingAddress ->getCountry ());
248
+ $ this ->assertSame ('94025 ' , $ shippingAddress ->getPostalCode ());
146
249
}
147
250
148
251
public function testCheckoutUpdateEvent (): void
@@ -154,6 +257,19 @@ public function testCheckoutUpdateEvent(): void
154
257
$ event = EventFactory::create ($ array );
155
258
156
259
$ this ->assertEquals ($ expectedEvent , $ event );
260
+
261
+ $ checkoutUpdate = $ event ->getCheckoutUpdate ();
262
+ $ this ->assertSame ('DEVELOPER_DEFINED_PAYLOAD ' , $ checkoutUpdate ->getPayload ());
263
+ $ this ->assertInstanceOf (Address::class, $ checkoutUpdate ->getShippingAddress ());
264
+
265
+ $ shippingAddress = $ checkoutUpdate ->getShippingAddress ();
266
+ $ this ->assertSame ('1 Hacker Way ' , $ shippingAddress ->getStreet ());
267
+ $ this ->assertSame ('' , $ shippingAddress ->getAdditionalStreet ());
268
+ $ this ->assertSame ('MENLO PARK ' , $ shippingAddress ->getCity ());
269
+ $ this ->assertSame ('CA ' , $ shippingAddress ->getState ());
270
+ $ this ->assertSame ('US ' , $ shippingAddress ->getCountry ());
271
+ $ this ->assertSame ('94025 ' , $ shippingAddress ->getPostalCode ());
272
+ $ this ->assertSame (10105655000959552 , $ shippingAddress ->getId ());
157
273
}
158
274
159
275
public function testPreCheckoutEvent (): void
@@ -165,6 +281,25 @@ public function testPreCheckoutEvent(): void
165
281
$ event = EventFactory::create ($ array );
166
282
167
283
$ this ->assertEquals ($ expectedEvent , $ event );
284
+
285
+ $ preCheckout = $ event ->getPreCheckout ();
286
+ $ this ->assertSame ('DEVELOPER_DEFINED_PAYLOAD ' , $ preCheckout ->getPayload ());
287
+ $ this ->assertSame ('USD ' , $ preCheckout ->getCurrency ());
288
+ $ this ->assertSame ('29.62 ' , $ preCheckout ->getAmount ());
289
+ $ this ->assertInstanceOf (RequestedUserInfo::class, $ preCheckout ->getRequestedUserInfo ());
290
+ $ this ->assertInstanceOf (Address::class, $ preCheckout ->getShippingAddress ());
291
+
292
+ $ requestedUserInfo = $ preCheckout ->getRequestedUserInfo ();
293
+ $ this ->assertSame ('Peter Chang ' , $ requestedUserInfo ->getContactName ());
294
+
295
+ $ shippingAddress = $ preCheckout ->getShippingAddress ();
296
+ $ this ->assertSame ('Peter Chang ' , $ shippingAddress ->getName ());
297
+ $ this ->assertSame ('1 Hacker Way ' , $ shippingAddress ->getStreet ());
298
+ $ this ->assertSame ('' , $ shippingAddress ->getAdditionalStreet ());
299
+ $ this ->assertSame ('MENLO PARK ' , $ shippingAddress ->getCity ());
300
+ $ this ->assertSame ('CA ' , $ shippingAddress ->getState ());
301
+ $ this ->assertSame ('US ' , $ shippingAddress ->getCountry ());
302
+ $ this ->assertSame ('94025 ' , $ shippingAddress ->getPostalCode ());
168
303
}
169
304
170
305
public function testTakeThreadControlEvent (): void
@@ -176,6 +311,10 @@ public function testTakeThreadControlEvent(): void
176
311
$ event = EventFactory::create ($ array );
177
312
178
313
$ this ->assertEquals ($ expectedEvent , $ event );
314
+
315
+ $ takeThreadControl = $ event ->getTakeThreadControl ();
316
+ $ this ->assertSame (123456789 , $ takeThreadControl ->getPreviousOwnerAppId ());
317
+ $ this ->assertSame ('additional content that the caller wants to set ' , $ takeThreadControl ->getMetadata ());
179
318
}
180
319
181
320
public function testPassThreadControlEvent (): void
@@ -187,6 +326,10 @@ public function testPassThreadControlEvent(): void
187
326
$ event = EventFactory::create ($ array );
188
327
189
328
$ this ->assertEquals ($ expectedEvent , $ event );
329
+
330
+ $ passThreadControl = $ event ->getPassThreadControl ();
331
+ $ this ->assertSame (123456789 , $ passThreadControl ->getNewOwnerAppId ());
332
+ $ this ->assertSame ('additional content that the caller wants to set ' , $ passThreadControl ->getMetadata ());
190
333
}
191
334
192
335
public function testRequestThreadControlEvent (): void
@@ -198,6 +341,10 @@ public function testRequestThreadControlEvent(): void
198
341
$ event = EventFactory::create ($ array );
199
342
200
343
$ this ->assertEquals ($ expectedEvent , $ event );
344
+
345
+ $ requestThreadControl = $ event ->getRequestThreadControl ();
346
+ $ this ->assertSame (123456789 , $ requestThreadControl ->getRequestedOwnerAppId ());
347
+ $ this ->assertSame ('additional content that the caller wants to set ' , $ requestThreadControl ->getMetadata ());
201
348
}
202
349
203
350
public function testPolicyEnforcementEvent (): void
@@ -209,6 +356,11 @@ public function testPolicyEnforcementEvent(): void
209
356
$ event = EventFactory::create ($ array );
210
357
211
358
$ this ->assertEquals ($ expectedEvent , $ event );
359
+
360
+ $ policyEnforcement = $ event ->getPolicyEnforcement ();
361
+ $ this ->assertSame ('block ' , $ policyEnforcement ->getAction ());
362
+ $ this ->assertSame ('The bot violated our Platform Policies (https://developers.facebook.com/policy/#messengerplatform). Common violations include sending out excessive spammy messages or being non-functional. ' , $ policyEnforcement ->getReason ());
363
+
212
364
}
213
365
214
366
public function testAppRolesEvent (): void
@@ -220,6 +372,9 @@ public function testAppRolesEvent(): void
220
372
$ event = EventFactory::create ($ array );
221
373
222
374
$ this ->assertEquals ($ expectedEvent , $ event );
375
+
376
+ $ appRoles = $ event ->getAppRoles ();
377
+ $ this ->assertSame (['123456789 ' => ['automation ' ]], $ appRoles ->getAppRoles ());
223
378
}
224
379
225
380
public function testReferralEvent (): void
@@ -231,6 +386,11 @@ public function testReferralEvent(): void
231
386
$ event = EventFactory::create ($ array );
232
387
233
388
$ this ->assertEquals ($ expectedEvent , $ event );
389
+
390
+ $ referral = $ event ->getReferral ();
391
+ $ this ->assertSame ('REF DATA PASSED IN M.ME PARAM ' , $ referral ->getRef ());
392
+ $ this ->assertSame ('SHORTLINK ' , $ referral ->getSource ());
393
+ $ this ->assertSame ('OPEN_THREAD ' , $ referral ->getType ());
234
394
}
235
395
236
396
public function testGamePlayEvent (): void
@@ -242,6 +402,14 @@ public function testGamePlayEvent(): void
242
402
$ event = EventFactory::create ($ array );
243
403
244
404
$ this ->assertEquals ($ expectedEvent , $ event );
405
+
406
+ $ gamePlay = $ event ->getGamePlay ();
407
+ $ this ->assertSame ('1234 ' , $ gamePlay ->getGameId ());
408
+ $ this ->assertSame ('666 ' , $ gamePlay ->getPlayerId ());
409
+ $ this ->assertSame ('SOLO|THREAD ' , $ gamePlay ->getContextType ());
410
+ $ this ->assertSame ('123 ' , $ gamePlay ->getContextId ());
411
+ $ this ->assertSame (1234567890 , $ gamePlay ->getScore ());
412
+ $ this ->assertSame ('DEVELOPER_DEFINED_PAYLOAD ' , $ gamePlay ->getPayload ());
245
413
}
246
414
247
415
public function testReactionEvent (): void
@@ -253,5 +421,11 @@ public function testReactionEvent(): void
253
421
$ event = EventFactory::create ($ array );
254
422
255
423
$ this ->assertEquals ($ expectedEvent , $ event );
424
+
425
+ $ reaction = $ event ->getReaction ();
426
+ $ this ->assertSame ('smile ' , $ reaction ->getReaction ());
427
+ $ this ->assertSame ("❤️ " , $ reaction ->getEmoji ());
428
+ $ this ->assertSame ('react ' , $ reaction ->getAction ());
429
+ $ this ->assertSame ('<MID> ' , $ reaction ->getMid ());
256
430
}
257
431
}
0 commit comments