1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Event testing

This commit is contained in:
David Bomba 2020-11-03 21:04:15 +11:00
parent e7a1e4c4db
commit 6eb9f0f6a6
34 changed files with 1304 additions and 28 deletions

View File

@ -12,6 +12,7 @@
namespace App\Events\Client; namespace App\Events\Client;
use App\Models\Client; use App\Models\Client;
use App\Models\Company;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**

View File

@ -12,6 +12,7 @@
namespace App\Events\Client; namespace App\Events\Client;
use App\Models\Client; use App\Models\Client;
use App\Models\Company;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
@ -26,6 +27,8 @@ class ClientWasRestored
*/ */
public $client; public $client;
public $fromDeleted;
public $company; public $company;
public $event_vars; public $event_vars;
@ -37,9 +40,10 @@ class ClientWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Client $client, Company $company, array $event_vars) public function __construct(Client $client, $fromDeleted, Company $company, array $event_vars)
{ {
$this->client = $client; $this->client = $client;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -12,6 +12,7 @@
namespace App\Events\Client; namespace App\Events\Client;
use App\Models\Client; use App\Models\Client;
use App\Models\Company;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**

View File

@ -30,6 +30,7 @@ class CreditWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -37,9 +38,10 @@ class CreditWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Credit $credit, Company $company, array $event_vars) public function __construct(Credit $credit, $fromDeleted, Company $company, array $event_vars)
{ {
$this->credit = $credit; $this->credit = $credit;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -32,6 +32,7 @@ class DesignWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -39,10 +40,12 @@ class DesignWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Design $design, Company $company, array $event_vars) public function __construct(Design $design, $fromDeleted, Company $company, array $event_vars)
{ {
$this->design = $design; $this->design = $design;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;

View File

@ -31,6 +31,7 @@ class DocumentWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -38,9 +39,10 @@ class DocumentWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Document $document, Company $company, array $event_vars) public function __construct(Document $document, $fromDeleted, Company $company, array $event_vars)
{ {
$this->document = $document; $this->document = $document;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -31,6 +31,7 @@ class ExpenseWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -38,9 +39,10 @@ class ExpenseWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Expense $expense, Company $company, array $event_vars) public function __construct(Expense $expense, $fromDeleted, Company $company, array $event_vars)
{ {
$this->expense = $expense; $this->expense = $expense;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -0,0 +1,49 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Product;
use App\Models\Company;
use App\Models\Invoice;
use Illuminate\Queue\SerializesModels;
/**
* Class ProductWasRestored.
*/
class ProductWasRestored
{
use SerializesModels;
/**
* @var Product
*/
public $invoice;
public $company;
public $event_vars;
public $fromDeleted;
/**
* Create a new event instance.
*
* @param Product $invoice
* @param Company $company
* @param array $event_vars
*/
public function __construct(Product $product, $fromDeleted, Company $company, array $event_vars)
{
$this->product = $product;
$this->fromDeleted = $fromDeleted;
$this->company = $company;
$this->event_vars = $event_vars;
}
}

View File

@ -27,6 +27,7 @@ class QuoteWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -34,9 +35,10 @@ class QuoteWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Quote $quote, Company $company, array $event_vars) public function __construct(Quote $quote, $fromDeleted, Company $company, array $event_vars)
{ {
$this->quote = $quote; $this->quote = $quote;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -31,6 +31,7 @@ class TaskWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -38,9 +39,10 @@ class TaskWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Task $task, Company $company, array $event_vars) public function __construct(Task $task, $fromDeleted, Company $company, array $event_vars)
{ {
$this->task = $task; $this->task = $task;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -31,6 +31,7 @@ class VendorWasRestored
public $event_vars; public $event_vars;
public $fromDeleted;
/** /**
* Create a new event instance. * Create a new event instance.
* *
@ -38,9 +39,10 @@ class VendorWasRestored
* @param Company $company * @param Company $company
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Vendor $vendor, Company $company, array $event_vars) public function __construct(Vendor $vendor, $fromDeleted, Company $company, array $event_vars)
{ {
$this->vendor = $vendor; $this->vendor = $vendor;
$this->fromDeleted = $fromDeleted;
$this->company = $company; $this->company = $company;
$this->event_vars = $event_vars; $this->event_vars = $event_vars;
} }

View File

@ -13,6 +13,7 @@ namespace App\Http\Controllers;
use App\DataMapper\ClientSettings; use App\DataMapper\ClientSettings;
use App\Events\Client\ClientWasCreated; use App\Events\Client\ClientWasCreated;
use App\Events\Client\ClientWasUpdated;
use App\Factory\ClientFactory; use App\Factory\ClientFactory;
use App\Filters\ClientFilters; use App\Filters\ClientFilters;
use App\Http\Requests\Client\BulkClientRequest; use App\Http\Requests\Client\BulkClientRequest;
@ -288,6 +289,8 @@ class ClientController extends BaseController
$this->uploadLogo($request->file('company_logo'), $client->company, $client); $this->uploadLogo($request->file('company_logo'), $client->company, $client);
event(new ClientWasUpdated($client, $client->company, Ninja::eventVars()));
return $this->itemResponse($client->fresh()); return $this->itemResponse($client->fresh());
} }

View File

@ -11,6 +11,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\Expense\ExpenseWasCreated;
use App\Events\Expense\ExpenseWasUpdated;
use App\Factory\ExpenseFactory; use App\Factory\ExpenseFactory;
use App\Filters\ExpenseFilters; use App\Filters\ExpenseFilters;
use App\Http\Requests\Expense\CreateExpenseRequest; use App\Http\Requests\Expense\CreateExpenseRequest;
@ -29,6 +31,7 @@ use App\Models\Size;
use App\Repositories\BaseRepository; use App\Repositories\BaseRepository;
use App\Repositories\ExpenseRepository; use App\Repositories\ExpenseRepository;
use App\Transformers\ExpenseTransformer; use App\Transformers\ExpenseTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\BulkOptions; use App\Utils\Traits\BulkOptions;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Uploadable; use App\Utils\Traits\Uploadable;
@ -281,6 +284,8 @@ class ExpenseController extends BaseController
$this->uploadLogo($request->file('company_logo'), $expense->company, $expense); $this->uploadLogo($request->file('company_logo'), $expense->company, $expense);
event(new ExpenseWasUpdated($expense, $expense->company, Ninja::eventVars()));
return $this->itemResponse($expense->fresh()); return $this->itemResponse($expense->fresh());
} }
@ -373,6 +378,8 @@ class ExpenseController extends BaseController
{ {
$expense = $this->expense_repo->save($request->all(), ExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id)); $expense = $this->expense_repo->save($request->all(), ExpenseFactory::create(auth()->user()->company()->id, auth()->user()->id));
event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars()));
return $this->itemResponse($expense); return $this->itemResponse($expense);
} }

View File

@ -11,6 +11,8 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Events\Task\TaskWasCreated;
use App\Events\Task\TaskWasUpdated;
use App\Factory\TaskFactory; use App\Factory\TaskFactory;
use App\Filters\TaskFilters; use App\Filters\TaskFilters;
use App\Http\Requests\Task\CreateTaskRequest; use App\Http\Requests\Task\CreateTaskRequest;
@ -24,11 +26,12 @@ use App\Jobs\Util\ProcessBulk;
use App\Jobs\Util\UploadAvatar; use App\Jobs\Util\UploadAvatar;
use App\Models\Country; use App\Models\Country;
use App\Models\Currency; use App\Models\Currency;
use App\Models\Task;
use App\Models\Size; use App\Models\Size;
use App\Models\Task;
use App\Repositories\BaseRepository; use App\Repositories\BaseRepository;
use App\Repositories\TaskRepository; use App\Repositories\TaskRepository;
use App\Transformers\TaskTransformer; use App\Transformers\TaskTransformer;
use App\Utils\Ninja;
use App\Utils\Traits\BulkOptions; use App\Utils\Traits\BulkOptions;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\Uploadable; use App\Utils\Traits\Uploadable;
@ -278,6 +281,8 @@ class TaskController extends BaseController
$task = $this->task_repo->save($request->all(), $task); $task = $this->task_repo->save($request->all(), $task);
event(new TaskWasUpdated($task, $task->company, Ninja::eventVars()));
return $this->itemResponse($task->fresh()); return $this->itemResponse($task->fresh());
} }
@ -370,6 +375,8 @@ class TaskController extends BaseController
{ {
$task = $this->task_repo->save($request->all(), TaskFactory::create(auth()->user()->company()->id, auth()->user()->id)); $task = $this->task_repo->save($request->all(), TaskFactory::create(auth()->user()->company()->id, auth()->user()->id));
event(new TaskWasCreated($task, $task->company, Ninja::eventVars()));
return $this->itemResponse($task); return $this->itemResponse($task);
} }

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class ClientUpdatedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$client = $event->client;
$fields = new stdClass;
$fields->client_id = $client->id;
$fields->user_id = $client->user_id;
$fields->company_id = $client->company_id;
$fields->activity_type_id = Activity::UPDATE_CLIENT;
$this->activity_repo->save($fields, $client, $event->event_vars);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class CreatedExpenseActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->expense_id = $event->expense->id;
$fields->user_id = $event->expense->user_id;
$fields->company_id = $event->expense->company_id;
$fields->activity_type_id = Activity::CREATE_EXPENSE;
$this->activity_repo->save($fields, $event->expense, $event->event_vars);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class CreatedTaskActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->task_id = $event->task->id;
$fields->user_id = $event->task->user_id;
$fields->company_id = $event->task->company_id;
$fields->activity_type_id = Activity::CREATE_TASK;
$this->activity_repo->save($fields, $event->task, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class ExpenseArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$expense = $event->expense;
$fields = new stdClass;
$fields->expense_id = $expense->id;
$fields->user_id = $expense->user_id;
$fields->company_id = $expense->company_id;
$fields->activity_type_id = Activity::ARCHIVE_EXPENSE;
$this->activity_repo->save($fields, $expense, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use stdClass;
class ExpenseDeletedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->expense_id = $event->expense->id;
$fields->user_id = $event->expense->user_id;
$fields->company_id = $event->expense->company_id;
$fields->activity_type_id = Activity::DELETE_VENDOR;
$this->activity_repo->save($fields, $event->expense, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use stdClass;
class ExpenseRestoredActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->expense_id = $event->expense->id;
$fields->user_id = $event->expense->user_id;
$fields->company_id = $event->expense->company_id;
$fields->activity_type_id = Activity::RESTORE_EXPENSE;
$this->activity_repo->save($fields, $event->expense, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class ExpenseUpdatedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$expense = $event->expense;
$fields = new stdClass;
$fields->expense_id = $expense->id;
$fields->user_id = $expense->user_id;
$fields->company_id = $expense->company_id;
$fields->activity_type_id = Activity::UPDATE_EXPENSE;
$this->activity_repo->save($fields, $expense, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class TaskArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$task = $event->task;
$fields = new stdClass;
$fields->task_id = $task->id;
$fields->user_id = $task->user_id;
$fields->company_id = $task->company_id;
$fields->activity_type_id = Activity::ARCHIVE_TASK;
$this->activity_repo->save($fields, $task, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use stdClass;
class TaskDeletedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->task_id = $event->task->id;
$fields->user_id = $event->task->user_id;
$fields->company_id = $event->task->company_id;
$fields->activity_type_id = Activity::DELETE_TASK;
$this->activity_repo->save($fields, $event->task, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use stdClass;
class TaskRestoredActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->task_id = $event->task->id;
$fields->user_id = $event->task->user_id;
$fields->company_id = $event->task->company_id;
$fields->activity_type_id = Activity::RESTORE_TASK;
$this->activity_repo->save($fields, $event->task, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class TaskUpdatedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$task = $event->task;
$fields = new stdClass;
$fields->task_id = $task->id;
$fields->user_id = $task->user_id;
$fields->company_id = $task->company_id;
$fields->activity_type_id = Activity::UPDATE_TASK;
$this->activity_repo->save($fields, $task, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class VendorArchivedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$vendor = $event->vendor;
$fields = new stdClass;
$fields->vendor_id = $vendor->id;
$fields->user_id = $vendor->user_id;
$fields->company_id = $vendor->company_id;
$fields->activity_type_id = Activity::ARCHIVE_VENDOR;
$this->activity_repo->save($fields, $vendor, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use stdClass;
class VendorDeletedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->vendor_id = $event->vendor->id;
$fields->user_id = $event->vendor->user_id;
$fields->company_id = $event->vendor->company_id;
$fields->activity_type_id = Activity::DELETE_VENDOR;
$this->activity_repo->save($fields, $event->vendor, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\ClientContact;
use App\Models\InvoiceInvitation;
use App\Repositories\ActivityRepository;
use App\Utils\Traits\MakesHash;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use stdClass;
class VendorRestoredActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$fields = new stdClass;
$fields->vendor_id = $event->vendor->id;
$fields->user_id = $event->vendor->user_id;
$fields->company_id = $event->vendor->company_id;
$fields->activity_type_id = Activity::RESTORE_VENDOR;
$this->activity_repo->save($fields, $event->vendor, $event->event_vars);
}
}

View File

@ -0,0 +1,58 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Activity;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Repositories\ActivityRepository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use stdClass;
class VendorUpdatedActivity implements ShouldQueue
{
protected $activity_repo;
/**
* Create the event listener.
*
* @param ActivityRepository $activity_repo
*/
public function __construct(ActivityRepository $activity_repo)
{
$this->activity_repo = $activity_repo;
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$vendor = $event->vendor;
$fields = new stdClass;
$fields->vendor_id = $vendor->id;
$fields->user_id = $vendor->user_id;
$fields->company_id = $vendor->company_id;
$fields->activity_type_id = Activity::UPDATE_VENDOR;
$this->activity_repo->save($fields, $vendor, $event->event_vars);
}
}

View File

@ -48,23 +48,23 @@ class Activity extends StaticModel
const RESTORE_CREDIT = 28; // const RESTORE_CREDIT = 28; //
const APPROVE_QUOTE = 29; // const APPROVE_QUOTE = 29; //
const CREATE_VENDOR = 30; // const CREATE_VENDOR = 30; //
const ARCHIVE_VENDOR = 31; const ARCHIVE_VENDOR = 31;//
const DELETE_VENDOR = 32; const DELETE_VENDOR = 32;//
const RESTORE_VENDOR = 33; const RESTORE_VENDOR = 33;//
const CREATE_EXPENSE = 34; const CREATE_EXPENSE = 34;//
const ARCHIVE_EXPENSE = 35; const ARCHIVE_EXPENSE = 35;//
const DELETE_EXPENSE = 36; const DELETE_EXPENSE = 36;//
const RESTORE_EXPENSE = 37; const RESTORE_EXPENSE = 37;//
const VOIDED_PAYMENT = 39; // const VOIDED_PAYMENT = 39; //
const REFUNDED_PAYMENT = 40; // const REFUNDED_PAYMENT = 40; //
const FAILED_PAYMENT = 41; const FAILED_PAYMENT = 41;
const CREATE_TASK = 42; const CREATE_TASK = 42; //
const UPDATE_TASK = 43; const UPDATE_TASK = 43; //
const ARCHIVE_TASK = 44; const ARCHIVE_TASK = 44; //
const DELETE_TASK = 45; const DELETE_TASK = 45; //
const RESTORE_TASK = 46; const RESTORE_TASK = 46; //
const UPDATE_EXPENSE = 47; const UPDATE_EXPENSE = 47;//
const CREATE_USER = 48; // only used in CreateUser::job const CREATE_USER = 48; // only used in CreateUser::job
const UPDATE_USER = 49; // not needed? const UPDATE_USER = 49; // not needed?
@ -77,6 +77,8 @@ class Activity extends StaticModel
const REVERSED_INVOICE = 58; // const REVERSED_INVOICE = 58; //
const CANCELLED_INVOICE = 59; // const CANCELLED_INVOICE = 59; //
const VIEW_CREDIT = 60; // const VIEW_CREDIT = 60; //
const UPDATE_CLIENT = 61; //
const UPDATE_VENDOR = 62; //
protected $casts = [ protected $casts = [
'is_system' => 'boolean', 'is_system' => 'boolean',

View File

@ -30,6 +30,11 @@ use App\Events\Credit\CreditWasRestored;
use App\Events\Credit\CreditWasUpdated; use App\Events\Credit\CreditWasUpdated;
use App\Events\Credit\CreditWasViewed; use App\Events\Credit\CreditWasViewed;
use App\Events\Design\DesignWasArchived; use App\Events\Design\DesignWasArchived;
use App\Events\Expense\ExpenseWasArchived;
use App\Events\Expense\ExpenseWasCreated;
use App\Events\Expense\ExpenseWasDeleted;
use App\Events\Expense\ExpenseWasRestored;
use App\Events\Expense\ExpenseWasUpdated;
use App\Events\Invoice\InvoiceWasArchived; use App\Events\Invoice\InvoiceWasArchived;
use App\Events\Invoice\InvoiceWasCancelled; use App\Events\Invoice\InvoiceWasCancelled;
use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasCreated;
@ -57,18 +62,34 @@ use App\Events\Quote\QuoteWasEmailed;
use App\Events\Quote\QuoteWasRestored; use App\Events\Quote\QuoteWasRestored;
use App\Events\Quote\QuoteWasUpdated; use App\Events\Quote\QuoteWasUpdated;
use App\Events\Quote\QuoteWasViewed; use App\Events\Quote\QuoteWasViewed;
use App\Events\Task\TaskWasArchived;
use App\Events\Task\TaskWasCreated;
use App\Events\Task\TaskWasDeleted;
use App\Events\Task\TaskWasRestored;
use App\Events\Task\TaskWasUpdated;
use App\Events\User\UserLoggedIn; use App\Events\User\UserLoggedIn;
use App\Events\User\UserWasCreated; use App\Events\User\UserWasCreated;
use App\Events\User\UserWasDeleted; use App\Events\User\UserWasDeleted;
use App\Events\Vendor\VendorWasArchived;
use App\Events\Vendor\VendorWasCreated; use App\Events\Vendor\VendorWasCreated;
use App\Events\Vendor\VendorWasDeleted;
use App\Events\Vendor\VendorWasRestored;
use App\Events\Vendor\VendorWasUpdated;
use App\Listeners\Activity\ArchivedClientActivity; use App\Listeners\Activity\ArchivedClientActivity;
use App\Listeners\Activity\ClientUpdatedActivity;
use App\Listeners\Activity\CreatedClientActivity; use App\Listeners\Activity\CreatedClientActivity;
use App\Listeners\Activity\CreatedVendorActivity;
use App\Listeners\Activity\CreatedCreditActivity; use App\Listeners\Activity\CreatedCreditActivity;
use App\Listeners\Activity\CreatedExpenseActivity;
use App\Listeners\Activity\CreatedQuoteActivity; use App\Listeners\Activity\CreatedQuoteActivity;
use App\Listeners\Activity\CreatedTaskActivity;
use App\Listeners\Activity\CreatedVendorActivity;
use App\Listeners\Activity\CreditArchivedActivity; use App\Listeners\Activity\CreditArchivedActivity;
use App\Listeners\Activity\DeleteClientActivity; use App\Listeners\Activity\DeleteClientActivity;
use App\Listeners\Activity\DeleteCreditActivity; use App\Listeners\Activity\DeleteCreditActivity;
use App\Listeners\Activity\ExpenseArchivedActivity;
use App\Listeners\Activity\ExpenseDeletedActivity;
use App\Listeners\Activity\ExpenseRestoredActivity;
use App\Listeners\Activity\ExpenseUpdatedActivity;
use App\Listeners\Activity\PaymentCreatedActivity; use App\Listeners\Activity\PaymentCreatedActivity;
use App\Listeners\Activity\PaymentDeletedActivity; use App\Listeners\Activity\PaymentDeletedActivity;
use App\Listeners\Activity\PaymentRefundedActivity; use App\Listeners\Activity\PaymentRefundedActivity;
@ -76,7 +97,15 @@ use App\Listeners\Activity\PaymentUpdatedActivity;
use App\Listeners\Activity\PaymentVoidedActivity; use App\Listeners\Activity\PaymentVoidedActivity;
use App\Listeners\Activity\QuoteUpdatedActivity; use App\Listeners\Activity\QuoteUpdatedActivity;
use App\Listeners\Activity\RestoreClientActivity; use App\Listeners\Activity\RestoreClientActivity;
use App\Listeners\Activity\TaskArchivedActivity;
use App\Listeners\Activity\TaskDeletedActivity;
use App\Listeners\Activity\TaskRestoredActivity;
use App\Listeners\Activity\TaskUpdatedActivity;
use App\Listeners\Activity\UpdatedCreditActivity; use App\Listeners\Activity\UpdatedCreditActivity;
use App\Listeners\Activity\VendorArchivedActivity;
use App\Listeners\Activity\VendorDeletedActivity;
use App\Listeners\Activity\VendorRestoredActivity;
use App\Listeners\Activity\VendorUpdatedActivity;
use App\Listeners\Contact\UpdateContactLastLogin; use App\Listeners\Contact\UpdateContactLastLogin;
use App\Listeners\Credit\CreditRestoredActivity; use App\Listeners\Credit\CreditRestoredActivity;
use App\Listeners\Credit\CreditViewedActivity; use App\Listeners\Credit\CreditViewedActivity;
@ -163,6 +192,7 @@ class EventServiceProvider extends ServiceProvider
ArchivedClientActivity::class, ArchivedClientActivity::class,
], ],
ClientWasUpdated::class =>[ ClientWasUpdated::class =>[
ClientUpdatedActivity::class,
], ],
ClientWasDeleted::class =>[ ClientWasDeleted::class =>[
DeleteClientActivity::class, DeleteClientActivity::class,
@ -206,14 +236,29 @@ class EventServiceProvider extends ServiceProvider
CreditViewedActivity::class, CreditViewedActivity::class,
], ],
//Designs //Designs
DesignWasArchived::class => [
],
DesignWasUpdated::class => [ DesignWasUpdated::class => [
], ],
DesignWasArchived::class => [
],
DesignWasDeleted::class => [ DesignWasDeleted::class => [
], ],
DesignWasRestored::class => [ DesignWasRestored::class => [
], ],
ExpenseWasCreated::class => [
CreatedExpenseActivity::class,
],
ExpenseWasUpdated::class => [
ExpenseUpdatedActivity::class,
],
ExpenseWasArchived::class => [
ExpenseArchivedActivity::class,
],
ExpenseWasDeleted::class => [
ExpenseDeletedActivity::class,
],
ExpenseWasRestored::class => [
ExpenseRestoredActivity::class
],
//Invoices //Invoices
InvoiceWasMarkedSent::class => [ InvoiceWasMarkedSent::class => [
CreateInvoiceHtmlBackup::class, CreateInvoiceHtmlBackup::class,
@ -288,9 +333,36 @@ class EventServiceProvider extends ServiceProvider
QuoteWasRestored::class => [ QuoteWasRestored::class => [
QuoteRestoredActivity::class, QuoteRestoredActivity::class,
], ],
TaskWasCreated::class => [
CreatedTaskActivity::class,
],
TaskWasUpdated::class => [
TaskUpdatedActivity::class,
],
TaskWasArchived::class => [
TaskArchivedActivity::class,
],
TaskWasDeleted::class => [
TaskDeletedActivity::class,
],
TaskWasRestored::class => [
TaskRestoredActivity::class,
],
VendorWasCreated::class => [ VendorWasCreated::class => [
CreatedVendorActivity::class, CreatedVendorActivity::class,
] ],
VendorWasArchived::class => [
VendorArchivedActivity::class,
],
VendorWasDeleted::class => [
VendorDeletedActivity::class,
],
VendorWasRestored::class => [
VendorRestoredActivity::class,
],
VendorWasUpdated::class => [
VendorUpdatedActivity::class,
],
]; ];

View File

@ -60,7 +60,7 @@ class BaseRepository
*/ */
private function getEventClass($entity, $type) private function getEventClass($entity, $type)
{ {
return 'App\Events\\'.ucfirst(class_basename($entity)).'Was'.$type; return 'App\Events\\'.ucfirst(class_basename($entity)).'\\'.ucfirst(class_basename($entity)).'Was'.$type;
} }
/** /**

View File

@ -0,0 +1,253 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Integration;
use App\Designs\Bold;
use App\Designs\Designer;
use App\Events\Client\ClientWasArchived;
use App\Events\Client\ClientWasCreated;
use App\Events\Client\ClientWasDeleted;
use App\Events\Client\ClientWasRestored;
use App\Events\Client\ClientWasUpdated;
use App\Events\Invoice\InvoiceWasArchived;
use App\Events\Invoice\InvoiceWasCreated;
use App\Events\Invoice\InvoiceWasDeleted;
use App\Events\Invoice\InvoiceWasRestored;
use App\Events\Invoice\InvoiceWasUpdated;
use App\Events\Payment\PaymentWasArchived;
use App\Events\Payment\PaymentWasCreated;
use App\Events\Payment\PaymentWasDeleted;
use App\Events\Payment\PaymentWasRestored;
use App\Events\Payment\PaymentWasUpdated;
use App\Models\Credit;
use App\Models\Design;
use App\Models\Invoice;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Services\PdfMaker\Design as PdfDesignModel;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
use App\Utils\HtmlEngine;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use Faker\Factory;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class EventTest extends TestCase
{
use MockAccountData;
use MakesHash;
public function setUp() :void
{
parent::setUp();
$this->faker = \Faker\Factory::create();
$this->makeTestData();
}
//@TODO paymentwasvoided
//@TODO paymentwasrefunded
public function testPaymentEvents()
{
$this->expectsEvents([
PaymentWasCreated::class,
PaymentWasUpdated::class,
PaymentWasArchived::class,
PaymentWasRestored::class,
PaymentWasDeleted::class,
]);
$data = [
'amount' => $this->invoice->amount,
'client_id' => $this->client->hashed_id,
'invoices' => [
[
'invoice_id' => $this->invoice->hashed_id,
'amount' => $this->invoice->amount,
],
],
'date' => '2020/12/12',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments?include=invoices', $data)
->assertStatus(200);
$arr = $response->json();
$data = [
'transaction_reference' => 'testing'
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->put('/api/v1/payments/' . $arr['data']['id'], $data)
->assertStatus(200);
$data = [
'ids' => [$arr['data']['id']],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=archive', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=restore', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/payments/bulk?action=delete', $data)
->assertStatus(200);
}
public function testInvoiceEvents()
{
/* Test fire new invoice */
$data = [
'client_id' => $this->client->hashed_id,
'number' => 'dude',
];
$this->expectsEvents([
InvoiceWasCreated::class,
InvoiceWasUpdated::class,
InvoiceWasArchived::class,
InvoiceWasRestored::class,
InvoiceWasDeleted::class,
]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/', $data)
->assertStatus(200);
$arr = $response->json();
$data = [
'client_id' => $this->client->hashed_id,
'number' => 'dude2',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->put('/api/v1/invoices/' . $arr['data']['id'], $data)
->assertStatus(200);
$data = [
'ids' => [$arr['data']['id']],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=archive', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=restore', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/invoices/bulk?action=delete', $data)
->assertStatus(200);
}
public function testClientEvents()
{
$this->expectsEvents([
ClientWasCreated::class,
ClientWasUpdated::class,
ClientWasArchived::class,
ClientWasRestored::class,
ClientWasDeleted::class,
]);
$data = [
'name' => $this->faker->firstName,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data)
->assertStatus(200);
$arr = $response->json();
$data = [
'name' => $this->faker->firstName,
'id_number' => 'Coolio',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->put('/api/v1/clients/' . $arr['data']['id'], $data)
->assertStatus(200);
$data = [
'ids' => [$arr['data']['id']],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/bulk?action=archive', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/bulk?action=restore', $data)
->assertStatus(200);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/bulk?action=delete', $data)
->assertStatus(200);
}
}