diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 4f2b70846389..a5abd4e8a51b 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -175,7 +175,7 @@ class PaymentController extends Controller foreach($payable_invoices as $payable_invoice) { - nlog($payable_invoice); + // nlog($payable_invoice); $payable_invoice['amount'] = Number::parseFloat($payable_invoice['amount']); diff --git a/app/Http/Controllers/TaskStatusController.php b/app/Http/Controllers/TaskStatusController.php index ccb9533a06ec..7bae5b0f4b18 100644 --- a/app/Http/Controllers/TaskStatusController.php +++ b/app/Http/Controllers/TaskStatusController.php @@ -174,7 +174,7 @@ class TaskStatusController extends BaseController */ public function store(StoreTaskStatusRequest $request) { - nlog($request->all()); + // nlog($request->all()); $task_status = TaskStatusFactory::create(auth()->user()->company()->id, auth()->user()->id); $task_status->fill($request->all()); diff --git a/app/Mail/Admin/EntitySentObject.php b/app/Mail/Admin/EntitySentObject.php index f8cd6a2a8e3b..3e0f9c8f76e2 100644 --- a/app/Mail/Admin/EntitySentObject.php +++ b/app/Mail/Admin/EntitySentObject.php @@ -60,7 +60,7 @@ class EntitySentObject private function setTemplate() { - nlog($this->template); + // nlog($this->template); switch ($this->template) { case 'invoice': diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index fc091bbefc14..8ad15adfc832 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -184,8 +184,8 @@ class InvoiceTest extends TestCase ->assertStatus(302); } catch (ValidationException $e) { $message = json_decode($e->validator->getMessageBag(), 1); - nlog('inside update invoice validator'); - nlog($message); + // nlog('inside update invoice validator'); + // nlog($message); $this->assertNotNull($message); } diff --git a/tests/Integration/EventTest.php b/tests/Integration/EventTest.php index 6fd67587e1be..d161bc41b11e 100644 --- a/tests/Integration/EventTest.php +++ b/tests/Integration/EventTest.php @@ -46,14 +46,23 @@ use App\Events\Task\TaskWasCreated; use App\Events\Task\TaskWasDeleted; use App\Events\Task\TaskWasRestored; use App\Events\Task\TaskWasUpdated; +use App\Events\User\UserWasArchived; +use App\Events\User\UserWasCreated; +use App\Events\User\UserWasDeleted; +use App\Events\User\UserWasRestored; +use App\Events\User\UserWasUpdated; use App\Events\Vendor\VendorWasArchived; use App\Events\Vendor\VendorWasCreated; use App\Events\Vendor\VendorWasDeleted; use App\Events\Vendor\VendorWasRestored; use App\Events\Vendor\VendorWasUpdated; +use App\Http\Middleware\PasswordProtection; use App\Models\Invoice; use App\Models\Quote; use App\Utils\Traits\MakesHash; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Foundation\Testing\DatabaseTransactions; +use Illuminate\Routing\Middleware\ThrottleRequests; use Tests\MockAccountData; use Tests\TestCase; @@ -64,6 +73,7 @@ class EventTest extends TestCase { use MockAccountData; use MakesHash; + use DatabaseTransactions; public function setUp() :void { @@ -72,6 +82,13 @@ class EventTest extends TestCase $this->faker = \Faker\Factory::create(); $this->makeTestData(); + + Model::reguard(); + + $this->withoutMiddleware( + ThrottleRequests::class, + PasswordProtection::class + ); } public function testExpenseEvents() @@ -134,6 +151,7 @@ class EventTest extends TestCase public function testVendorEvents() { + $this->expectsEvents([ VendorWasCreated::class, VendorWasUpdated::class, @@ -456,7 +474,6 @@ class EventTest extends TestCase public function testInvoiceEvents() { - /* Test fire new invoice */ $data = [ 'client_id' => $this->client->hashed_id, @@ -573,4 +590,85 @@ class EventTest extends TestCase ])->post('/api/v1/clients/bulk?action=delete', $data) ->assertStatus(200); } + + + public function testUserEvents() + { + $this->withoutMiddleware(PasswordProtection::class); + + + $this->expectsEvents([ + UserWasCreated::class, + UserWasUpdated::class, + UserWasArchived::class, + UserWasRestored::class, + UserWasDeleted::class, + ]); + + $data = [ + 'first_name' => 'hey', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users?include=company_user', $data) + ->assertStatus(200); + + $arr = $response->json(); + + $data = [ + 'first_name' => 'hasdasdy', + 'last_name' => 'you', + 'email' => 'bob1@good.ole.boys.com', + 'company_user' => [ + 'is_admin' => false, + 'is_owner' => false, + 'permissions' => 'create_client,create_invoice', + ], + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->put('/api/v1/users/' . $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, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users/bulk?action=archive', $data) + ->assertStatus(200); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users/bulk?action=restore', $data) + ->assertStatus(200); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + ])->post('/api/v1/users/bulk?action=delete', $data) + ->assertStatus(200); + } + + } diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index aad2f31056d7..db300ab645e4 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -189,6 +189,7 @@ trait MockAccountData $this->user = User::factory()->create([ 'account_id' => $this->account->id, 'confirmation_code' => $this->createDbHash(config('database.default')), + 'email' => 'user@example.com', ]); }