Skip to content

Commit 75ebb4c

Browse files
committed
added optional businessAreaId param for createContactList call
AUT-4110
1 parent 9748ba8 commit 75ebb4c

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/Suite/Api/ContactList.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public function __construct(Client $apiClient, ContactListEndPoints $endPoints)
2222
$this->endPoints = $endPoints;
2323
}
2424

25-
public function createContactList(int $customerId, string $name, array $contactIds = [])
25+
public function createContactList(
26+
int $customerId,
27+
string $name,
28+
array $contactIds = [],
29+
string $businessAreaId = null)
2630
{
2731
if (!strlen(trim($name))) {
2832
throw new \InvalidArgumentException("Empty contact list name given");
@@ -36,7 +40,8 @@ public function createContactList(int $customerId, string $name, array $contactI
3640
}
3741

3842
try {
39-
return $this->apiClient->post($this->endPoints->createContactList($customerId), $data)['data']['id'];
43+
return $this->apiClient->post(
44+
$this->endPoints->createContactList($customerId, $businessAreaId), $data)['data']['id'];
4045
} catch (Error $error) {
4146
throw new RequestFailed('Could not create contact list: ' . $error->getMessage(), $error->getCode(), $error);
4247
}

src/Suite/Api/ContactListEndPoints.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ private function baseUrl(int $customerId, string $businessAreaId = null)
2020
. ($businessAreaId ? "?business_area_id=$businessAreaId" : '');
2121
}
2222

23-
public function createContactList(int $customerId)
23+
public function createContactList(int $customerId, string $businessAreaId = null)
2424
{
25-
return $this->baseUrl($customerId);
25+
return $this->baseUrl($customerId, $businessAreaId);
2626
}
2727

2828
public function contactLists(int $customerId, string $businessAreaId = null)

test/unit/Suite/Api/ContactListTest.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ public function createContactList_Perfect_Perfect(): void
4141
$this->assertEquals($this->contactListId, $contactListId);
4242
}
4343

44+
/**
45+
* @test
46+
*/
47+
public function createContactList_CalledWithBusinessAreaId_PassesBusinessAreaId(): void
48+
{
49+
$businessAreaId = 'HU';
50+
$contactIds = [1, 2, 3];
51+
$this->apiClient
52+
->expects($this->once())
53+
->method('post')
54+
->with(
55+
"api_base_url/$this->customerId/contactlist?business_area_id=$businessAreaId",
56+
[
57+
'name' => $this->listName,
58+
'key_id' => 'id',
59+
'external_ids' => $contactIds,
60+
]
61+
)
62+
->willReturn($this->apiSuccess(['id' => $this->contactListId]));
63+
64+
$this->listService->createContactList($this->customerId, $this->listName, $contactIds, $businessAreaId);
65+
}
66+
4467
/**
4568
* @test
4669
*/
@@ -106,18 +129,16 @@ public function getContactLists_CalledWithBusinessAreaId_PassesBusinessAreaId():
106129
{
107130
$businessAreaId = 'HU';
108131
$contactLists = [
109-
$this->contactListData('id1', 'contact list 1'),
110-
$this->contactListData('id2', 'contact list 2'),
132+
$this->contactListData('id', 'contact list'),
111133
];
112134

113135
$this->apiClient
136+
->expects($this->once())
114137
->method('get')
115138
->with("api_base_url/$this->customerId/contactlist?business_area_id=$businessAreaId")
116139
->willReturn($this->apiSuccess($contactLists));
117140

118-
$returnedContactLists = $this->listService->getContactLists($this->customerId, $businessAreaId);
119-
120-
$this->assertEquals($contactLists, $returnedContactLists);
141+
$this->listService->getContactLists($this->customerId, $businessAreaId);
121142
}
122143

123144
/**

0 commit comments

Comments
 (0)