Fixes for tests

This commit is contained in:
David Bomba 2023-02-01 13:46:39 +11:00
parent fa1e52b4ca
commit fecf1e13b5
10 changed files with 52 additions and 49 deletions

View File

@ -33,7 +33,6 @@ use PDOException;
use Sentry\Laravel\Integration; use Sentry\Laravel\Integration;
use Sentry\State\Scope; use Sentry\State\Scope;
use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use League\Flysystem\UnableToCreateDirectory; use League\Flysystem\UnableToCreateDirectory;
@ -47,27 +46,27 @@ class Handler extends ExceptionHandler
* @var array * @var array
*/ */
protected $dontReport = [ protected $dontReport = [
// PDOException::class, PDOException::class,
// MaxAttemptsExceededException::class, MaxAttemptsExceededException::class,
// CommandNotFoundException::class, CommandNotFoundException::class,
// ValidationException::class, ValidationException::class,
// ModelNotFoundException::class, ModelNotFoundException::class,
// NotFoundHttpException::class, NotFoundHttpException::class,
]; ];
protected $selfHostDontReport = [ protected $selfHostDontReport = [
// FilePermissionsFailure::class, FilePermissionsFailure::class,
// PDOException::class, PDOException::class,
// MaxAttemptsExceededException::class, MaxAttemptsExceededException::class,
// CommandNotFoundException::class, CommandNotFoundException::class,
// ValidationException::class, ValidationException::class,
// ModelNotFoundException::class, ModelNotFoundException::class,
// NotFoundHttpException::class, NotFoundHttpException::class,
// UnableToCreateDirectory::class, UnableToCreateDirectory::class,
// GuzzleHttp\Exception\ConnectException::class, GuzzleHttp\Exception\ConnectException::class,
// Symfony\Component\Process\Exception\RuntimeException::class, Symfony\Component\Process\Exception\RuntimeException::class,
// InvalidArgumentException::class, InvalidArgumentException::class,
// RuntimeException::class, RuntimeException::class,
]; ];
protected $hostedDontReport = [ protected $hostedDontReport = [

View File

@ -276,6 +276,8 @@ class VendorController extends BaseController
event(new VendorWasUpdated($vendor, $vendor->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); 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()); 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(new VendorWasCreated($vendor, $vendor->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
event('eloquent.created: App\Models\Vendor', $vendor);
return $this->itemResponse($vendor); return $this->itemResponse($vendor);
} }

View File

@ -17,6 +17,7 @@ use App\Models\Client as ClientModel;
use App\Models\Company; use App\Models\Company;
use App\Models\Product; use App\Models\Product;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\Models\Vendor;
use App\Models\Webhook; use App\Models\Webhook;
use App\Transformers\ArraySerializer; use App\Transformers\ArraySerializer;
use GuzzleHttp\Client; use GuzzleHttp\Client;
@ -244,7 +245,7 @@ class WebhookSingle implements ShouldQueue
private function resolveClient() private function resolveClient()
{ {
//make sure it isn't an instance of the Client Model //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; return $this->entity->client;
} }
@ -253,10 +254,8 @@ class WebhookSingle implements ShouldQueue
public function failed($exception = null) public function failed($exception = null)
{ {
if($exception){
nlog("failed in webhooksingle"); config(['queue.failed.driver' => null]);
nlog($exception->getMessage());
}
} }
} }

View File

@ -24,27 +24,27 @@ class Webhook extends BaseModel
const EVENT_CREATE_QUOTE = 3; //tested 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_UPDATE_INVOICE = 8; //tested
const EVENT_DELETE_INVOICE = 9; //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; const EVENT_CREATE_EXPENSE = 15;

View File

@ -32,9 +32,9 @@ class VendorObserver
->where('event_id', Webhook::EVENT_CREATE_VENDOR) ->where('event_id', Webhook::EVENT_CREATE_VENDOR)
->exists(); ->exists();
if ($subscriptions) { if ($subscriptions)
WebhookHandler::dispatch(Webhook::EVENT_CREATE_VENDOR, $vendor, $vendor->company)->delay(rand(1,5)); WebhookHandler::dispatch(Webhook::EVENT_CREATE_VENDOR, $vendor, $vendor->company)->delay(rand(1,5));
}
} }
/** /**

View File

@ -67,7 +67,7 @@ class VendorContactRepository extends BaseRepository
$update_contact->password = Hash::make($contact['password']); $update_contact->password = Hash::make($contact['password']);
} }
$update_contact->save(); $update_contact->saveQuietly();
}); });
$vendor->load('contacts'); $vendor->load('contacts');
@ -80,7 +80,7 @@ class VendorContactRepository extends BaseRepository
$new_contact->user_id = $vendor->user_id; $new_contact->user_id = $vendor->user_id;
$new_contact->contact_key = Str::random(40); $new_contact->contact_key = Str::random(40);
$new_contact->is_primary = true; $new_contact->is_primary = true;
$new_contact->save(); $new_contact->saveQuietly();
} }
} }
} }

View File

@ -45,13 +45,13 @@ class VendorRepository extends BaseRepository
{ {
$vendor->fill($data); $vendor->fill($data);
$vendor->save(); $vendor->saveQuietly();
if ($vendor->number == '' || ! $vendor->number) { if ($vendor->number == '' || ! $vendor->number) {
$vendor->number = $this->getNextVendorNumber($vendor); $vendor->number = $this->getNextVendorNumber($vendor);
} //todo write tests for this and make sure that custom vendor numbers also works as expected from here } //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'])) { if (isset($data['contacts'])) {
$this->contact_repo->save($data, $vendor); $this->contact_repo->save($data, $vendor);

View File

@ -40,7 +40,7 @@ class ClientService
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
$this->client->balance += $amount; $this->client->balance += $amount;
$this->client->save(); $this->client->saveQuietly();
}, 2); }, 2);
} }
@ -61,7 +61,7 @@ class ClientService
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
$this->client->balance += $balance; $this->client->balance += $balance;
$this->client->paid_to_date += $paid_to_date; $this->client->paid_to_date += $paid_to_date;
$this->client->save(); $this->client->saveQuietly();
}, 2); }, 2);
} }
@ -80,7 +80,7 @@ class ClientService
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first(); $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
$this->client->paid_to_date += $amount; $this->client->paid_to_date += $amount;
$this->client->save(); $this->client->saveQuietly();
}, 2); }, 2);

View File

@ -93,14 +93,14 @@ class SchedulerService
private function calculateStartAndEndDates(): array private function calculateStartAndEndDates(): array
{ {
return match ($this->scheduler->parameters['date_range']) { return match ($this->scheduler->parameters['date_range']) {
'this_month' => [now()->firstOfMonth()->format('Y-m-d'), now()->lastOfMonth()->format('Y-m-d')], 'this_month' => [now()->startOfDay()->firstOfMonth()->format('Y-m-d'), now()->startOfDay()->lastOfMonth()->format('Y-m-d')],
'this_quarter' => [now()->firstOfQuarter()->format('Y-m-d'), now()->lastOfQuarter()->format('Y-m-d')], 'this_quarter' => [now()->startOfDay()->firstOfQuarter()->format('Y-m-d'), now()->startOfDay()->lastOfQuarter()->format('Y-m-d')],
'this_year' => [now()->firstOfYear()->format('Y-m-d'), now()->lastOfYear()->format('Y-m-d')], 'this_year' => [now()->startOfDay()->firstOfYear()->format('Y-m-d'), now()->startOfDay()->lastOfYear()->format('Y-m-d')],
'previous_month' => [now()->subMonth()->firstOfMonth()->format('Y-m-d'), now()->subMonth()->lastOfMonth()->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()->subQuarter()->firstOfQuarter()->format('Y-m-d'), now()->subQuarter()->lastOfQuarter()->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()->subYear()->firstOfYear()->format('Y-m-d'), now()->subYear()->lastOfYear()->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']], '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')],
}; };
} }

View File

@ -258,6 +258,7 @@ class SchedulerTest extends TestCase
public function testCalculateStartAndEndDates() public function testCalculateStartAndEndDates()
{ {
$this->travelTo(Carbon::parse('2023-01-01'));
$scheduler = SchedulerFactory::create($this->company->id, $this->user->id); $scheduler = SchedulerFactory::create($this->company->id, $this->user->id);