Skip to content

Commit

Permalink
Merge pull request #15 from Talentify/feature/add-delete-method
Browse files Browse the repository at this point in the history
Feature - Add delete customer method
  • Loading branch information
dreanmer authored Dec 28, 2021
2 parents e487e1d + 9aaf95d commit 7f7bb06
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Request/Track/Customer/DeleteCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace CIO\Request\Track\Customer;

use CIO\Entity\Customer\Customer;
use CIO\Entity\EntityInterface;
use CIO\Entity\RequestMethod;
use CIO\Request\Track\TrackBaseRequest;

class DeleteCustomer extends TrackBaseRequest
{
/**
* @var \CIO\Entity\Customer\Customer
*/
private $customer;

public function __construct(EntityInterface $customer)
{
assert($customer instanceof Customer);
$this->customer = $customer;
}

public function getEndpoint() : string
{
return sprintf('/api/v1/customers/%s', $this->customer->getIdentifier());
}

public function getMethod() : RequestMethod
{
return RequestMethod::DELETE();
}

public function getBody() : array
{
return [];
}
}
40 changes: 40 additions & 0 deletions tests/unit/Request/Track/Customer/DeleteCustomerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace CIO\Request\Track\Customer;

use CIO\CustomerIoClient;
use CIO\Entity\AccountRegion;
use CIO\Entity\Customer\Customer;
use CIO\Entity\Customer\Identifier;
use CIO\Request\Track\Customer\AddOrUpdateCustomer;
use Helpers\RequestTestCase;
use Helpers\TestClient;

class DeleteCustomerTest extends RequestTestCase
{
public function testDeleteCustomerRequest() : void
{
$httpTestClient = new TestClient();

$client = new CustomerIoClient(
['token' => 'token'],
AccountRegion::US(),
$httpTestClient
);

$request = new DeleteCustomer(
new Customer(
new Identifier("123")
)
);

$client->execute($request);

$executedRequest = $httpTestClient->getRequestsExecuted()[0];

$this->assertEquals('https://track.customer.io/api/v1/customers/123', $executedRequest['uri']);
$this->assertEquals('DELETE', $executedRequest['method']);
}
}

0 comments on commit 7f7bb06

Please sign in to comment.