4
4
5
5
namespace spec \Webgriffe \SyliusActiveCampaignPlugin \MessageHandler \Contact ;
6
6
7
+ use Symfony \Component \HttpKernel \Exception \UnprocessableEntityHttpException ;
7
8
use Tests \Webgriffe \SyliusActiveCampaignPlugin \App \Entity \Customer \CustomerInterface ;
8
9
use InvalidArgumentException ;
9
10
use PhpSpec \ObjectBehavior ;
16
17
use Webgriffe \SyliusActiveCampaignPlugin \Model \ActiveCampaign \ContactInterface ;
17
18
use Webgriffe \SyliusActiveCampaignPlugin \Model \ActiveCampaignAwareInterface ;
18
19
use Webgriffe \SyliusActiveCampaignPlugin \ValueObject \Response \CreateResourceResponseInterface ;
20
+ use Webgriffe \SyliusActiveCampaignPlugin \ValueObject \Response \ListResourcesResponseInterface ;
19
21
use Webgriffe \SyliusActiveCampaignPlugin \ValueObject \Response \ResourceResponseInterface ;
20
22
21
23
class ContactCreateHandlerSpec extends ObjectBehavior
@@ -30,6 +32,7 @@ public function let(
30
32
$ contactMapper ->mapFromCustomer ($ customer )->willReturn ($ contact );
31
33
32
34
$ customer ->getActiveCampaignId ()->willReturn (null );
35
+ $ customer ->getEmail ()->willReturn ('email ' );
33
36
34
37
$ customerRepository ->find (12 )->willReturn ($ customer );
35
38
@@ -91,4 +94,24 @@ public function it_creates_contact_on_active_campaign(
91
94
92
95
$ this ->__invoke (new ContactCreate (12 ));
93
96
}
97
+
98
+ public function it_search_for_contact_id_if_validation_fails_due_to_duplicated_email (
99
+ ContactInterface $ contact ,
100
+ ActiveCampaignResourceClientInterface $ activeCampaignContactClient ,
101
+ CustomerInterface $ customer ,
102
+ CustomerRepositoryInterface $ customerRepository ,
103
+ ResourceResponseInterface $ contactResponse ,
104
+ ListResourcesResponseInterface $ searchContactsForEmail ,
105
+ ): void {
106
+ $ contactResponse ->getId ()->willReturn (3423 );
107
+ $ activeCampaignContactClient ->create ($ contact )->shouldBeCalledOnce ()->willThrow (new UnprocessableEntityHttpException ());
108
+ $ activeCampaignContactClient ->list (['email ' => 'email ' ])->shouldBeCalledOnce ()->willReturn ($ searchContactsForEmail );
109
+
110
+ $ searchContactsForEmail ->getResourceResponseLists ()->willReturn ([$ contactResponse ]);
111
+
112
+ $ customer ->setActiveCampaignId (3423 )->shouldBeCalledOnce ();
113
+ $ customerRepository ->add ($ customer )->shouldBeCalledOnce ();
114
+
115
+ $ this ->__invoke (new ContactCreate (12 ));
116
+ }
94
117
}
0 commit comments