From 4f444144500a76b4600ca9884fbdfeec99ad3c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Fri, 18 Jun 2021 10:52:20 +0300 Subject: [PATCH] added reconciliation factory --- app/Models/Banking/Reconciliation.php | 13 ++++ app/Models/Common/Media.php | 2 - database/factories/Reconciliation.php | 63 +++++++++++++++++++ tests/Feature/Banking/ReconciliationsTest.php | 15 +---- 4 files changed, 79 insertions(+), 14 deletions(-) create mode 100644 database/factories/Reconciliation.php diff --git a/app/Models/Banking/Reconciliation.php b/app/Models/Banking/Reconciliation.php index d8265141c..6fa2b1c51 100644 --- a/app/Models/Banking/Reconciliation.php +++ b/app/Models/Banking/Reconciliation.php @@ -3,9 +3,12 @@ namespace App\Models\Banking; use App\Abstracts\Model; +use Illuminate\Database\Eloquent\Factories\HasFactory; class Reconciliation extends Model { + use HasFactory; + protected $table = 'reconciliations'; protected $dates = ['deleted_at', 'started_at', 'ended_at']; @@ -38,4 +41,14 @@ class Reconciliation extends Model { return $this->belongsTo('App\Models\Banking\Account'); } + + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory() + { + return \Database\Factories\Reconciliation::new(); + } } diff --git a/app/Models/Common/Media.php b/app/Models/Common/Media.php index d07fa333e..0a71d8774 100644 --- a/app/Models/Common/Media.php +++ b/app/Models/Common/Media.php @@ -10,8 +10,6 @@ class Media extends BaseMedia { use SoftDeletes, Tenants; - protected $tenantable = true; - protected $dates = ['deleted_at']; protected $fillable = ['company_id']; diff --git a/database/factories/Reconciliation.php b/database/factories/Reconciliation.php new file mode 100644 index 000000000..93ef46801 --- /dev/null +++ b/database/factories/Reconciliation.php @@ -0,0 +1,63 @@ +faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'); + $ended_at = Date::parse($started_at)->addDays($this->faker->randomNumber(3))->format('Y-m-d H:i:s'); + + return [ + 'company_id' => $this->company->id, + 'account_id' => '1', + 'currency_code' => setting('default.currency'), + 'opening_balance' => '0', + 'closing_balance' => '10', + 'started_at' => $started_at, + 'ended_at' => $ended_at, + 'reconcile' => $this->faker->boolean ? 1 : 0, + ]; + } + + /** + * Indicate that the model is reconciled. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + public function reconciled() + { + return $this->state([ + 'reconcile' => 1, + ]); + } + + /** + * Indicate that the model is not reconciled. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + public function notreconciled() + { + return $this->state([ + 'reconcile' => 0, + ]); + } +} diff --git a/tests/Feature/Banking/ReconciliationsTest.php b/tests/Feature/Banking/ReconciliationsTest.php index cbb45cdda..1fb738ee5 100644 --- a/tests/Feature/Banking/ReconciliationsTest.php +++ b/tests/Feature/Banking/ReconciliationsTest.php @@ -3,11 +3,12 @@ namespace Tests\Feature\Banking; use App\Jobs\Banking\CreateReconciliation; +use App\Models\Banking\Reconciliation; use Tests\Feature\FeatureTestCase; class ReconciliationsTest extends FeatureTestCase { - public function testItShouldSeeReconciliationtListPage() + public function testItShouldSeeReconciliationListPage() { $this->loginAs() ->get(route('reconciliations.index')) @@ -76,16 +77,6 @@ class ReconciliationsTest extends FeatureTestCase private function getRequest() { - return [ - 'company_id' => $this->company->id, - 'account_id' => '1', - 'currency_code' => setting('default.currency'), - 'opening_balance' => '0', - 'closing_balance' => '10', - 'started_at' => $this->faker->date(), - 'ended_at' => $this->faker->date(), - 'reconcile' => null, - 'reconciled' => '1', - ]; + return Reconciliation::factory()->reconciled()->raw(); } }