-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/bstepien/fixForDayOfCycleInCreateContact' into …
…'develop' Feature/bstepien/fix for day of cycle in create contact See merge request integrations/share-code-plugin!43
- Loading branch information
Showing
3 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,9 +232,10 @@ private static function createHistoricalOrderCollection() | |
|
||
/** | ||
* @param string $name | ||
* @param int $dayOfCycle | ||
* @return AddContactCommand | ||
*/ | ||
public static function createAddContactCommand($name = 'Adam Kowalski') | ||
public static function createAddContactCommand($name = 'Adam Kowalski', $dayOfCycle = 3) | ||
{ | ||
$customFieldCollection = new ContactCustomFieldsCollection(); | ||
$customFieldCollection->add(new ContactCustomField('id_1', 'value_1')); | ||
|
@@ -244,7 +245,7 @@ public static function createAddContactCommand($name = 'Adam Kowalski') | |
'[email protected]', | ||
$name, | ||
'contactListId', | ||
3, | ||
$dayOfCycle, | ||
$customFieldCollection, | ||
'origin' | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,9 @@ | |
use GrShareCode\Contact\ContactNotFoundException; | ||
use GrShareCode\Contact\ContactService; | ||
use GrShareCode\GetresponseApiClient; | ||
use GrShareCode\GetresponseApiException; | ||
use GrShareCode\Tests\Generator; | ||
use GrShareCode\Tests\Unit\BaseTestCase; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class ContactServiceTest | ||
|
@@ -75,7 +75,7 @@ public function shouldThrowExceptionWhenClientNotExists() | |
* @dataProvider validAddContactProvider | ||
* @param $addContactCommand | ||
* @param $params | ||
* @throws \GrShareCode\GetresponseApiException | ||
* @throws GetresponseApiException | ||
*/ | ||
public function shouldCreateContact($addContactCommand, $params) | ||
{ | ||
|
@@ -289,6 +289,83 @@ public function shouldCreateContactWithOriginIfCustomFieldNotExists() | |
$contactService->createContact($addContactCommand); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateContactWithDayOfCycleZero() | ||
{ | ||
$customerName = 'Adam Kowalski'; | ||
$dayOfCycle = 0; | ||
|
||
$params = [ | ||
'name' => $customerName, | ||
'email' => '[email protected]', | ||
'campaign' => [ | ||
'campaignId' => 'contactListId' | ||
], | ||
'dayOfCycle' => $dayOfCycle, | ||
'customFieldValues' => [ | ||
['customFieldId' => 'id_1', 'value' => ['value_1']], | ||
['customFieldId' => 'id_2', 'value' => ['value_2']], | ||
['customFieldId' => 'cx4R', 'value' => ['origin']] | ||
] | ||
]; | ||
|
||
$this->getResponseApiClientMock | ||
->expects($this->once()) | ||
->method('createContact') | ||
->with($params); | ||
|
||
$this->getResponseApiClientMock | ||
->expects($this->once()) | ||
->method('getCustomFieldByName') | ||
->with('origin') | ||
->willReturn(['customFieldId' => 'cx4R']); | ||
|
||
$addContactCommand = Generator::createAddContactCommand($customerName, $dayOfCycle); | ||
|
||
$contactService = new ContactService($this->getResponseApiClientMock); | ||
$contactService->createContact($addContactCommand); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateContactWithNoDayOfCycle() | ||
{ | ||
$customerName = 'Adam Kowalski'; | ||
$dayOfCycle = null; | ||
|
||
$params = [ | ||
'name' => $customerName, | ||
'email' => '[email protected]', | ||
'campaign' => [ | ||
'campaignId' => 'contactListId' | ||
], | ||
'customFieldValues' => [ | ||
['customFieldId' => 'id_1', 'value' => ['value_1']], | ||
['customFieldId' => 'id_2', 'value' => ['value_2']], | ||
['customFieldId' => 'cx4R', 'value' => ['origin']] | ||
] | ||
]; | ||
|
||
$this->getResponseApiClientMock | ||
->expects($this->once()) | ||
->method('createContact') | ||
->with($params); | ||
|
||
$this->getResponseApiClientMock | ||
->expects($this->once()) | ||
->method('getCustomFieldByName') | ||
->with('origin') | ||
->willReturn(['customFieldId' => 'cx4R']); | ||
|
||
$addContactCommand = Generator::createAddContactCommand($customerName, $dayOfCycle); | ||
|
||
$contactService = new ContactService($this->getResponseApiClientMock); | ||
$contactService->createContact($addContactCommand); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|
@@ -351,6 +428,7 @@ public function shouldUnsubscribeContact() | |
* @param string $email | ||
* @param string $origin | ||
* @param string $invalidOrigin | ||
* @throws GetresponseApiException | ||
*/ | ||
public function shouldNotUnsubscribeContact($email, $origin, $invalidOrigin) | ||
{ | ||
|