From fecf1e13b5607308488c4da9cff182f7c13e0652 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 1 Feb 2023 13:46:39 +1100 Subject: [PATCH] Fixes for tests --- app/Exceptions/Handler.php | 37 ++++++++++---------- app/Http/Controllers/VendorController.php | 4 +++ app/Jobs/Util/WebhookSingle.php | 9 +++-- app/Models/Webhook.php | 18 +++++----- app/Observers/VendorObserver.php | 4 +-- app/Repositories/VendorContactRepository.php | 4 +-- app/Repositories/VendorRepository.php | 4 +-- app/Services/Client/ClientService.php | 6 ++-- app/Services/Scheduler/SchedulerService.php | 14 ++++---- tests/Feature/Scheduler/SchedulerTest.php | 1 + 10 files changed, 52 insertions(+), 49 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index f2d53abf67c1..a7d534780cec 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -33,7 +33,6 @@ use PDOException; use Sentry\Laravel\Integration; use Sentry\State\Scope; use Symfony\Component\Console\Exception\CommandNotFoundException; -use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use League\Flysystem\UnableToCreateDirectory; @@ -47,27 +46,27 @@ class Handler extends ExceptionHandler * @var array */ protected $dontReport = [ - // PDOException::class, - // MaxAttemptsExceededException::class, - // CommandNotFoundException::class, - // ValidationException::class, - // ModelNotFoundException::class, - // NotFoundHttpException::class, + PDOException::class, + MaxAttemptsExceededException::class, + CommandNotFoundException::class, + ValidationException::class, + ModelNotFoundException::class, + NotFoundHttpException::class, ]; protected $selfHostDontReport = [ - // FilePermissionsFailure::class, - // PDOException::class, - // MaxAttemptsExceededException::class, - // CommandNotFoundException::class, - // ValidationException::class, - // ModelNotFoundException::class, - // NotFoundHttpException::class, - // UnableToCreateDirectory::class, - // GuzzleHttp\Exception\ConnectException::class, - // Symfony\Component\Process\Exception\RuntimeException::class, - // InvalidArgumentException::class, - // RuntimeException::class, + FilePermissionsFailure::class, + PDOException::class, + MaxAttemptsExceededException::class, + CommandNotFoundException::class, + ValidationException::class, + ModelNotFoundException::class, + NotFoundHttpException::class, + UnableToCreateDirectory::class, + GuzzleHttp\Exception\ConnectException::class, + Symfony\Component\Process\Exception\RuntimeException::class, + InvalidArgumentException::class, + RuntimeException::class, ]; protected $hostedDontReport = [ diff --git a/app/Http/Controllers/VendorController.php b/app/Http/Controllers/VendorController.php index 1ac624367260..9736aaaff5b4 100644 --- a/app/Http/Controllers/VendorController.php +++ b/app/Http/Controllers/VendorController.php @@ -276,6 +276,8 @@ class VendorController extends BaseController event(new VendorWasUpdated($vendor, $vendor->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event('eloquent.updated: App\Models\Vendor', $vendor); + return $this->itemResponse($vendor->fresh()); } @@ -372,6 +374,8 @@ class VendorController extends BaseController event(new VendorWasCreated($vendor, $vendor->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + event('eloquent.created: App\Models\Vendor', $vendor); + return $this->itemResponse($vendor); } diff --git a/app/Jobs/Util/WebhookSingle.php b/app/Jobs/Util/WebhookSingle.php index ec13219d823d..7016cb53795f 100644 --- a/app/Jobs/Util/WebhookSingle.php +++ b/app/Jobs/Util/WebhookSingle.php @@ -17,6 +17,7 @@ use App\Models\Client as ClientModel; use App\Models\Company; use App\Models\Product; use App\Models\SystemLog; +use App\Models\Vendor; use App\Models\Webhook; use App\Transformers\ArraySerializer; use GuzzleHttp\Client; @@ -244,7 +245,7 @@ class WebhookSingle implements ShouldQueue private function resolveClient() { //make sure it isn't an instance of the Client Model - if (! $this->entity instanceof ClientModel && ! $this->entity instanceof Product && $this->entity->client()->exists()) { + if (! $this->entity instanceof ClientModel && ! $this->entity instanceof Product && ! $this->entity instanceof Vendor && $this->entity->client()->exists()) { return $this->entity->client; } @@ -253,10 +254,8 @@ class WebhookSingle implements ShouldQueue public function failed($exception = null) { - if($exception){ - nlog("failed in webhooksingle"); - nlog($exception->getMessage()); - } + + config(['queue.failed.driver' => null]); } } diff --git a/app/Models/Webhook.php b/app/Models/Webhook.php index aedd148c2a97..e53a6d839952 100644 --- a/app/Models/Webhook.php +++ b/app/Models/Webhook.php @@ -24,27 +24,27 @@ class Webhook extends BaseModel const EVENT_CREATE_QUOTE = 3; //tested - const EVENT_CREATE_PAYMENT = 4; + const EVENT_CREATE_PAYMENT = 4; //tested - const EVENT_CREATE_VENDOR = 5; + const EVENT_CREATE_VENDOR = 5; //tested - const EVENT_UPDATE_QUOTE = 6; + const EVENT_UPDATE_QUOTE = 6; //tested - const EVENT_DELETE_QUOTE = 7; + const EVENT_DELETE_QUOTE = 7; //tested const EVENT_UPDATE_INVOICE = 8; //tested const EVENT_DELETE_INVOICE = 9; //tested - const EVENT_UPDATE_CLIENT = 10; + const EVENT_UPDATE_CLIENT = 10; //tested - const EVENT_DELETE_CLIENT = 11; + const EVENT_DELETE_CLIENT = 11; //tested - const EVENT_DELETE_PAYMENT = 12; + const EVENT_DELETE_PAYMENT = 12; //tested - const EVENT_UPDATE_VENDOR = 13; + const EVENT_UPDATE_VENDOR = 13; //tested - const EVENT_DELETE_VENDOR = 14; + const EVENT_DELETE_VENDOR = 14; // const EVENT_CREATE_EXPENSE = 15; diff --git a/app/Observers/VendorObserver.php b/app/Observers/VendorObserver.php index 89344ac4a538..5449ba1d5c77 100644 --- a/app/Observers/VendorObserver.php +++ b/app/Observers/VendorObserver.php @@ -32,9 +32,9 @@ class VendorObserver ->where('event_id', Webhook::EVENT_CREATE_VENDOR) ->exists(); - if ($subscriptions) { + if ($subscriptions) WebhookHandler::dispatch(Webhook::EVENT_CREATE_VENDOR, $vendor, $vendor->company)->delay(rand(1,5)); - } + } /** diff --git a/app/Repositories/VendorContactRepository.php b/app/Repositories/VendorContactRepository.php index 5f6dc95eaec4..6827b57d23d8 100644 --- a/app/Repositories/VendorContactRepository.php +++ b/app/Repositories/VendorContactRepository.php @@ -67,7 +67,7 @@ class VendorContactRepository extends BaseRepository $update_contact->password = Hash::make($contact['password']); } - $update_contact->save(); + $update_contact->saveQuietly(); }); $vendor->load('contacts'); @@ -80,7 +80,7 @@ class VendorContactRepository extends BaseRepository $new_contact->user_id = $vendor->user_id; $new_contact->contact_key = Str::random(40); $new_contact->is_primary = true; - $new_contact->save(); + $new_contact->saveQuietly(); } } } diff --git a/app/Repositories/VendorRepository.php b/app/Repositories/VendorRepository.php index 5a1c968fe3d6..4c4fc5fa6b23 100644 --- a/app/Repositories/VendorRepository.php +++ b/app/Repositories/VendorRepository.php @@ -45,13 +45,13 @@ class VendorRepository extends BaseRepository { $vendor->fill($data); - $vendor->save(); + $vendor->saveQuietly(); if ($vendor->number == '' || ! $vendor->number) { $vendor->number = $this->getNextVendorNumber($vendor); } //todo write tests for this and make sure that custom vendor numbers also works as expected from here - $vendor->save(); + $vendor->saveQuietly(); if (isset($data['contacts'])) { $this->contact_repo->save($data, $vendor); diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index d8e0e60d0e04..e76c9d809d50 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -40,7 +40,7 @@ class ClientService $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client->balance += $amount; - $this->client->save(); + $this->client->saveQuietly(); }, 2); } @@ -61,7 +61,7 @@ class ClientService $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client->balance += $balance; $this->client->paid_to_date += $paid_to_date; - $this->client->save(); + $this->client->saveQuietly(); }, 2); } @@ -80,7 +80,7 @@ class ClientService $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client->paid_to_date += $amount; - $this->client->save(); + $this->client->saveQuietly(); }, 2); diff --git a/app/Services/Scheduler/SchedulerService.php b/app/Services/Scheduler/SchedulerService.php index 5d4d30cb0f2e..413bbdc78f12 100644 --- a/app/Services/Scheduler/SchedulerService.php +++ b/app/Services/Scheduler/SchedulerService.php @@ -93,14 +93,14 @@ class SchedulerService private function calculateStartAndEndDates(): array { return match ($this->scheduler->parameters['date_range']) { - 'this_month' => [now()->firstOfMonth()->format('Y-m-d'), now()->lastOfMonth()->format('Y-m-d')], - 'this_quarter' => [now()->firstOfQuarter()->format('Y-m-d'), now()->lastOfQuarter()->format('Y-m-d')], - 'this_year' => [now()->firstOfYear()->format('Y-m-d'), now()->lastOfYear()->format('Y-m-d')], - 'previous_month' => [now()->subMonth()->firstOfMonth()->format('Y-m-d'), now()->subMonth()->lastOfMonth()->format('Y-m-d')], - 'previous_quarter' => [now()->subQuarter()->firstOfQuarter()->format('Y-m-d'), now()->subQuarter()->lastOfQuarter()->format('Y-m-d')], - 'previous_year' => [now()->subYear()->firstOfYear()->format('Y-m-d'), now()->subYear()->lastOfYear()->format('Y-m-d')], + 'this_month' => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], + 'this_quarter' => [now()->startOfDay()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->lastOfQuarter()->format('Y-m-d')], + 'this_year' => [now()->startOfDay()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->lastOfYear()->format('Y-m-d')], + 'previous_month' => [now()->startOfDay()->subMonthNoOverflow()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->subMonthNoOverflow()->lastOfMonth()->format('Y-m-d')], + 'previous_quarter' => [now()->startOfDay()->subQuarterNoOverflow()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->subQuarterNoOverflow()->lastOfQuarter()->format('Y-m-d')], + 'previous_year' => [now()->startOfDay()->subYearNoOverflow()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->subYearNoOverflow()->lastOfYear()->format('Y-m-d')], 'custom_range' => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']], - default => [now()->firstOfMonth()->format('Y-m-d'), now()->lastOfMonth()->format('Y-m-d')], + default => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')], }; } diff --git a/tests/Feature/Scheduler/SchedulerTest.php b/tests/Feature/Scheduler/SchedulerTest.php index 944bd6a1f567..ebaebbe7a88c 100644 --- a/tests/Feature/Scheduler/SchedulerTest.php +++ b/tests/Feature/Scheduler/SchedulerTest.php @@ -258,6 +258,7 @@ class SchedulerTest extends TestCase public function testCalculateStartAndEndDates() { + $this->travelTo(Carbon::parse('2023-01-01')); $scheduler = SchedulerFactory::create($this->company->id, $this->user->id);