Skip to content

Commit cd05de2

Browse files
committed
delete customer test and function in cyclops service
1 parent 8a5d7f0 commit cd05de2

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/Services/CyclopsService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ public function setSubscriptions(CustomerEntity $customerEntity, array $subscrip
9393

9494
public function deleteCustomer(CyclopsIdentityEntity $identityEntity)
9595
{
96-
96+
$url = $this->cyclopsUrl . "customer/{$identityEntity->id}";
97+
$request = new HttpRequest($url, 'delete');
98+
$request->addHeader('Authorization', 'Basic ' . $this->authorization);
99+
return $this->httpClient->getResponse($request);
97100
}
98101

99102
public function getBrandOptInStatus(CustomerEntity $customerEntity): bool
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Gcd\Cyclops\Tests\unit\UseCases;
4+
5+
use Codeception\Stub;
6+
use Gcd\Cyclops\Entities\CustomerEntity;
7+
use Gcd\Cyclops\Entities\CyclopsIdentityEntity;
8+
use Gcd\Cyclops\Services\CyclopsService;
9+
use Gcd\Cyclops\Tests\unit\CyclopsTestCase;
10+
use Gcd\Cyclops\UseCases\DeleteCustomerUseCase;
11+
use Gcd\Cyclops\UseCases\GetBrandOptInUseCase;
12+
13+
class DeleteCustomerUseCaseTest extends CyclopsTestCase
14+
{
15+
public function testCustomerDeleted()
16+
{
17+
$count = 0;
18+
$service = Stub::make(CyclopsService::class, [
19+
'createCustomer' => function (CyclopsIdentityEntity $identityEntity) use (&$count): CustomerEntity {
20+
$identityEntity->id = $count++;
21+
$customer = new CustomerEntity();
22+
$customer->identity = $identityEntity;
23+
return $customer;
24+
},
25+
'loadCustomer' => function (CyclopsIdentityEntity $identityEntity) use (&$count): CustomerEntity {
26+
$customer = new CustomerEntity();
27+
$customer->identity = $identityEntity;
28+
return $customer;
29+
},
30+
'getBrandOptInStatus' => function (CustomerEntity $customerEntity): bool {
31+
return false;
32+
},
33+
'deleteCustomer' => function (CyclopsIdentityEntity $identityEntity): bool {
34+
return true;
35+
},
36+
]);
37+
38+
$id = new CyclopsIdentityEntity();
39+
$id->email = "test@test.com";
40+
41+
$useCase = new GetBrandOptInUseCase($service);
42+
$response = $useCase->execute($id);
43+
verify($response->identity->id)->notNull();
44+
45+
$deleteUseCase = new DeleteCustomerUseCase($service);
46+
$deleteUseCase->execute($response->identity);
47+
48+
$response2 = $useCase->execute($id);
49+
verify($response2->identity->id)->notNull();
50+
verify($response2->identity->id)->notSame($response->identity->id);
51+
}
52+
}

0 commit comments

Comments
 (0)