Skip to content

Commit

Permalink
Merge branch 'feature/bstepien/fixForDayOfCycleInCreateContact' into …
Browse files Browse the repository at this point in the history
…'develop'

Feature/bstepien/fix for day of cycle in create contact

See merge request integrations/share-code-plugin!43
  • Loading branch information
Bartłomiej Stępień committed Oct 16, 2018
2 parents 7386164 + e9f8d1a commit e90c9d2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Contact/ContactService.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private function prepareParams(AddContactCommand $addContactCommand, ContactCust
unset($params['name']);
}

if (!empty($addContactCommand->getDayOfCycle())) {
if (null !== $addContactCommand->getDayOfCycle()) {
$params['dayOfCycle'] = $addContactCommand->getDayOfCycle();
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -244,7 +245,7 @@ public static function createAddContactCommand($name = 'Adam Kowalski')
'[email protected]',
$name,
'contactListId',
3,
$dayOfCycle,
$customFieldCollection,
'origin'
);
Expand Down
82 changes: 80 additions & 2 deletions tests/Unit/Domain/Contact/ContactServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,7 @@ public function shouldThrowExceptionWhenClientNotExists()
* @dataProvider validAddContactProvider
* @param $addContactCommand
* @param $params
* @throws \GrShareCode\GetresponseApiException
* @throws GetresponseApiException
*/
public function shouldCreateContact($addContactCommand, $params)
{
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -351,6 +428,7 @@ public function shouldUnsubscribeContact()
* @param string $email
* @param string $origin
* @param string $invalidOrigin
* @throws GetresponseApiException
*/
public function shouldNotUnsubscribeContact($email, $origin, $invalidOrigin)
{
Expand Down

0 comments on commit e90c9d2

Please sign in to comment.