Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/inikoo/aiku into main
Browse files Browse the repository at this point in the history
  • Loading branch information
YudhistiraA committed Oct 4, 2024
2 parents fb6d952 + 3a7ff29 commit 7d787e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/Actions/CRM/Customer/DeleteCustomerDeliveryAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
class DeleteCustomerDeliveryAddress extends OrgAction
{
protected Address $address;
public function handle(Customer $customer, Address $address)
public function handle(Customer $customer, Address $address): Customer
{
$customer->addresses()->detach($address->id);

$address->delete();

AddressHydrateUsage::dispatch($address);

$address->delete();

$customer->refresh();
return $customer;
}

Expand All @@ -50,6 +52,13 @@ public function asController(FulfilmentCustomer $fulfilmentCustomer, Address $ad
$this->handle($fulfilmentCustomer->customer, $address);
}

public function action(Customer $customer, Address $address): Customer
{
$this->address = $address;
$this->initialisationFromShop($customer->shop, []);
return $this->handle($customer, $address);
}

public function inCustomer(Customer $customer, Address $address, ActionRequest $request): void
{
$this->address = $address;
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/CrmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

use App\Actions\CRM\Customer\AddDeliveryAddressToCustomer;
use App\Actions\CRM\Customer\DeleteCustomerDeliveryAddress;
use App\Actions\CRM\Customer\HydrateCustomers;
use App\Actions\CRM\Customer\StoreCustomer;
use App\Actions\CRM\Prospect\StoreProspect;
Expand Down Expand Up @@ -192,8 +193,20 @@

expect($customer)->toBeInstanceOf(Customer::class)
->and($customer->addresses->count())->toBe(2);

return $customer;
})->depends('create customer');

test('delete delivery address from customer', function (Customer $customer) {
$address = $customer->addresses()->skip(1)->first();
$customer = DeleteCustomerDeliveryAddress::make()->action($customer, $address);

expect($customer)->toBeInstanceOf(Customer::class)
->and($customer->addresses->count())->toBe(1);

return $customer;
})->depends('add delivery address to customer');

test('can show list of prospects lists', function () {
$shop = $this->shop;
$response = get(route('grp.org.shops.show.crm.prospects.lists.index', [$shop->slug]));
Expand Down

0 comments on commit 7d787e1

Please sign in to comment.