Skip to content

Commit

Permalink
Add test for both parameters for Bulk Delete Events
Browse files Browse the repository at this point in the history
  • Loading branch information
kr-mykyta committed May 8, 2023
1 parent b533e6c commit cdde13b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Cronofy.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ public function bulkDeleteEvents($params)
When provided at least one calendar must be specified. OPTIONAL
Only one of delete_all or calendar_ids must be provided in the body, if both are set this is considered an error.
Returns true on success, associative array of errors on failure
*/
$postFields = [];

Expand Down
39 changes: 35 additions & 4 deletions tests/CronofyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ public function testDeleteEvent()
$this->assertNotNull($actual);
}

public function testBulkDeleteEvents()
public function testBulkDeleteEventsFromSpecificCalendar()
{
$params = ["calendar_ids" => ["cal_123"], "delete_all" => true];
$params = ["calendar_ids" => ["cal_123"]];

$http = $this->createMock(HttpRequest::class);
$http->expects($this->once())
Expand All @@ -323,7 +323,39 @@ public function testBulkDeleteEvents()
'Content-Type: application/json; charset=utf-8',
])
)
->will($this->returnValue(["{'foo': 'bar'}", 200]));
->will($this->returnValue(["{'foo': 'bar'}", 202]));

$cronofy = new Cronofy([
"client_id" => "clientId",
"client_secret" => "clientSecret",
"access_token" => "accessToken",
"refresh_token" => "refreshToken",
"http_client" => $http,
]);

$actual = $cronofy->bulkDeleteEvents([
"calendar_ids" => ["cal_123"]
]);
$this->assertNotNull($actual);
}

public function testBulkDeleteEventsFromAllCalendars()
{
$params = ["delete_all" => true];

$http = $this->createMock(HttpRequest::class);
$http->expects($this->once())
->method('httpDelete')
->with(
$this->equalTo('https://api.cronofy.com/v1/events'),
$this->equalTo($params),
$this->equalTo([
'Authorization: Bearer accessToken',
'Host: api.cronofy.com',
'Content-Type: application/json; charset=utf-8',
])
)
->will($this->returnValue(["{'foo': 'bar'}", 202]));

$cronofy = new Cronofy([
"client_id" => "clientId",
Expand All @@ -334,7 +366,6 @@ public function testBulkDeleteEvents()
]);

$actual = $cronofy->bulkDeleteEvents([
"calendar_ids" => ["cal_123"],
"delete_all" => true
]);
$this->assertNotNull($actual);
Expand Down

0 comments on commit cdde13b

Please sign in to comment.