44namespace Nipwaayoni \Tests \SnsHandler \Feature ;
55
66use Aws \Sns \MessageValidator ;
7- use Illuminate \Http \Client \Request ;
87use Illuminate \Support \Facades \Event ;
9- use Illuminate \Support \Facades \Http ;
108use Nipwaayoni \SnsHandler \Events \SnsConfirmationRequestReceived ;
119use Nipwaayoni \SnsHandler \Events \SnsMessageReceived ;
12- use Nipwaayoni \SnsHandler \Listeners \SnsConfirmationRequestListener ;
1310use Nipwaayoni \SnsHandler \NullMessageValidator ;
1411use Nipwaayoni \SnsHandler \ServiceProvider ;
1512use Nipwaayoni \SnsHandler \SnsMessage ;
13+ use Nipwaayoni \Tests \SnsHandler \Events \SnsConfirmationRequestAlphaReceived ;
14+ use Nipwaayoni \Tests \SnsHandler \Events \SnsConfirmationRequestBetaReceived ;
15+ use Nipwaayoni \Tests \SnsHandler \Events \SnsMessageAlphaReceived ;
16+ use Nipwaayoni \Tests \SnsHandler \Events \SnsMessageBetaReceived ;
1617use Nipwaayoni \Tests \SnsHandler \MakesSnsTests ;
1718
1819class SnsHandlerTest extends \Nipwaayoni \Tests \SnsHandler \TestCase
@@ -22,51 +23,64 @@ class SnsHandlerTest extends \Nipwaayoni\Tests\SnsHandler\TestCase
2223 public function setUp (): void
2324 {
2425 parent ::setUp ();
25- $ this ->app ->bind (MessageValidator::class, NullMessageValidator::class);
26- }
2726
28- protected function getEnvironmentSetUp ($ app )
29- {
30- // $app['config']->set('sns-handler.sns-class-map', [
31- // 'arn:aws:sns:us-west-2:123456789012:MyTopic' => SnsMessageHandlerStub::class,
32- // ]);
27+ Event::fake ();
28+
29+ $ this ->app ->bind (MessageValidator::class, NullMessageValidator::class);
3330 }
3431
3532 protected function getPackageProviders ($ app )
3633 {
3734 return [ServiceProvider::class];
3835 }
3936
40- public function testReturnsNotFoundForUnknownTopicArn (): void
37+ protected function getEnvironmentSetUp ( $ app )
4138 {
42- $ this ->markTestSkipped ("Skipping until we implement enhanced mapping functionality for events. " );
43- $ data = $ this ->makeSnsMessageData ([
44- 'Type ' => SnsMessage::NOTIFICATION_TYPE ,
45- 'TopicArn ' => 'arn:aws:sns:us-west-2:123456789012:Unknown ' ,
39+ $ app ['config ' ]->set ('sns-handler.confirmation-events ' , [
40+ SnsConfirmationRequestAlphaReceived::class => ['arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ],
41+ SnsConfirmationRequestReceived::class => ['* ' ],
4642 ]);
47- $ response = $ this ->postJson ('/api/sns/message ' , $ data );
4843
49- $ this ->assertEquals (404 , $ response ->status ());
44+ $ app ['config ' ]->set ('sns-handler.message-events ' , [
45+ SnsMessageAlphaReceived::class => ['arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ],
46+ SnsMessageReceived::class => ['* ' ],
47+ ]);
5048 }
5149
5250 public function testDispatchesDefaultConfirmationEvent (): void
5351 {
54- Event::fake ();
55-
5652 $ data = $ this ->makeSnsMessageData ([
5753 'Type ' => SnsMessage::SUBSCRIBE_TYPE ,
5854 'Message ' => json_encode (['id ' => 123 , 'color ' => 'red ' ], true ),
5955 'SubscribeURL ' => 'https://aws.amazon.com/sns/register/abc123 '
6056 ]);
6157
6258 $ response = $ this ->postJson ('/api/sns/message ' , $ data );
59+
60+ $ this ->assertEquals (200 , $ response ->status ());
6361 Event::assertDispatched (SnsConfirmationRequestReceived::class);
62+ Event::assertNotDispatched (SnsConfirmationRequestAlphaReceived::class);
63+ Event::assertNotDispatched (SnsConfirmationRequestBetaReceived::class);
64+ }
65+
66+ public function testDispatchesMappedConfirmationEvent (): void
67+ {
68+ $ data = $ this ->makeSnsMessageData ([
69+ 'Type ' => SnsMessage::SUBSCRIBE_TYPE ,
70+ 'TopicArn ' => 'arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ,
71+ 'SubscribeURL ' => 'https://aws.amazon.com/sns/register/abc123 '
72+ ]);
73+
74+ $ response = $ this ->postJson ('/api/sns/message ' , $ data );
75+
6476 $ this ->assertEquals (200 , $ response ->status ());
77+ Event::assertDispatched (SnsConfirmationRequestAlphaReceived::class);
78+ Event::assertNotDispatched (SnsConfirmationRequestBetaReceived::class);
79+ Event::assertNotDispatched (SnsConfirmationRequestReceived::class);
6580 }
6681
6782 public function testDispatchesDefaultMessageEvent (): void
6883 {
69- Event::fake ();
7084 $ data = $ this ->makeSnsMessageData ([
7185 'Type ' => SnsMessage::NOTIFICATION_TYPE ,
7286 'TopicArn ' => 'arn:aws:sns:us-west-2:123456789012:MyTopic ' ,
@@ -76,7 +90,24 @@ public function testDispatchesDefaultMessageEvent(): void
7690 $ response = $ this ->postJson ('/api/sns/message ' , $ data );
7791
7892 $ this ->assertEquals (200 , $ response ->status ());
79-
8093 Event::assertDispatched (SnsMessageReceived::class);
94+ Event::assertNotDispatched (SnsMessageAlphaReceived::class);
95+ Event::assertNotDispatched (SnsMessageBetaReceived::class);
96+ }
97+
98+ public function testDispatchesMappedMessageEvent (): void
99+ {
100+ $ data = $ this ->makeSnsMessageData ([
101+ 'Type ' => SnsMessage::NOTIFICATION_TYPE ,
102+ 'TopicArn ' => 'arn:aws:sns:us-west-2:123456789012:AlphaTopic ' ,
103+ 'Message ' => 'Test message ' ,
104+ ]);
105+
106+ $ response = $ this ->postJson ('/api/sns/message ' , $ data );
107+
108+ $ this ->assertEquals (200 , $ response ->status ());
109+ Event::assertDispatched (SnsMessageAlphaReceived::class);
110+ Event::assertNotDispatched (SnsMessageReceived::class);
111+ Event::assertNotDispatched (SnsMessageBetaReceived::class);
81112 }
82113}
0 commit comments