-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Factories and Unit Tests for the remaining models
- Loading branch information
Showing
12 changed files
with
292 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\App\Models\CompanyUserRequest::class, function (Faker $faker) { | ||
return [ | ||
'full_name' => $faker->name, | ||
'email' => $faker->unique()->safeEmail, | ||
'phone' => '+658' . $faker->numberBetween($min = 1, $max = 8) . $faker->randomNumber(6, true), | ||
'token' => str_random(10), | ||
'status' => $faker->numberBetween($min = 1, $max = 3), | ||
'company_id' => function () { | ||
return factory(\App\Models\Company::class)->create()->id; | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\App\Models\InvoiceEvent::class, function (Faker $faker) { | ||
return [ | ||
'time_interval' => '3', | ||
'time_period' => 'week', | ||
'until_type' => 'date', | ||
'until_meta' => '2020-10-31 00:00:00', | ||
'rule' => 'FREQ=WEEKLY;UNTIL=20201031T000000;INTERVAL=3', | ||
'company_id' => function () { | ||
return factory(\App\Models\Company::class)->create()->id; | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\App\Models\InvoiceItemTemplate::class, function (Faker $faker) { | ||
return [ | ||
'name' => $faker->bs(), | ||
'quantity' => $faker->numberBetween($min = 1, $max = 999999999), | ||
'price' => $faker->randomFloat($nbMaxDecimals = 2, $min = 0, $max = 999999999999), | ||
'description' => $faker->text(200), | ||
'invoice_template_id' => function () { | ||
return factory(\App\Models\InvoiceTemplate::class)->create()->id; | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\App\Models\InvoiceTemplate::class, function (Faker $faker) { | ||
return [ | ||
'date' => $faker->dateTime, | ||
'netdays' => $faker->numberBetween($min = 1, $max = 60), | ||
'notify' => $faker->boolean, | ||
'client_id' => function () { | ||
return factory(\App\Models\Client::class)->create()->id; | ||
}, | ||
'invoice_event_id' => function () { | ||
return factory(\App\Models\InvoiceEvent::class)->create()->id; | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class CompanyUserRequestTest extends TestCase | ||
{ | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function testExample() | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class InvoiceEventTest extends TestCase | ||
{ | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function testExample() | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use App\Models\InvoiceItemTemplate; | ||
use App\Models\InvoiceTemplate; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class InvoiceItemTemplateTest extends TestCase | ||
{ | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function test_create_invoice_item_template() | ||
{ | ||
$invoiceTemplate = factory(InvoiceTemplate::class)->create(); | ||
|
||
InvoiceItemTemplate::unguard(); | ||
|
||
$invoiceItemTemplate = InvoiceItemTemplate::create([ | ||
'name' => 'This is an Invoice Item Template la', | ||
'quantity' => '250', | ||
'price' => '5.00', | ||
'description' => 'asfdasfasfasfsf<p>asasdfasdfasfas</p>', | ||
'invoice_template_id' => $invoiceTemplate->id | ||
]); | ||
|
||
InvoiceItemTemplate::reguard(); | ||
|
||
$this->assertEquals($invoiceItemTemplate->template->id, $invoiceTemplate->id); | ||
$this->assertEquals('asfdasfasfasfsf<p>asasdfasdfasfas</p>', $invoiceItemTemplate->description); | ||
} | ||
|
||
public function test_update_invoice_item_template() | ||
{ | ||
$invoiceTemplate = factory(InvoiceTemplate::class)->create(); | ||
$invoiceTemplate2 = factory(InvoiceTemplate::class)->create(); | ||
$invoiceItemTemplate = factory(InvoiceItemTemplate::class)->create([ | ||
'invoice_template_id' => $invoiceTemplate->id | ||
]); | ||
$this->assertInstanceOf(InvoiceItemTemplate::class, $invoiceItemTemplate); | ||
|
||
$invoiceItemTemplate->price = "500.00"; | ||
$invoiceItemTemplate->quantity = "2000"; | ||
$invoiceItemTemplate->save(); | ||
$invoiceItemTemplate->refresh(); | ||
|
||
$this->assertEquals('500.00', $invoiceItemTemplate->price); | ||
$this->assertEquals('2000', $invoiceItemTemplate->quantity); | ||
|
||
$data = [ | ||
'price' => '213131.00', | ||
'quantity' => '25000', | ||
'invoice_template_id' => $invoiceTemplate2->id, | ||
]; | ||
|
||
$invoiceItemTemplate->fill($data); | ||
$invoiceItemTemplate->save(); | ||
$invoiceItemTemplate->refresh(); | ||
|
||
$this->assertEquals('213131.00', $invoiceItemTemplate->price); | ||
$this->assertEquals('25000', $invoiceItemTemplate->quantity); | ||
$this->assertNotEquals($invoiceTemplate2->id, $invoiceItemTemplate->invoice_template_id); | ||
} | ||
|
||
public function test_delete_invoice_item_template() | ||
{ | ||
$invoiceTemplate = factory(InvoiceTemplate::class)->create(); | ||
$invoiceItemTemplate = factory(InvoiceItemTemplate::class)->create([ | ||
'invoice_template_id' => $invoiceTemplate->id | ||
]); | ||
|
||
$this->assertInstanceOf(InvoiceItemTemplate::class, $invoiceItemTemplate); | ||
$invoiceItemTemplate = $invoiceItemTemplate->delete(); | ||
|
||
$this->assertEquals('true', json_encode($invoiceItemTemplate)); | ||
$this->assertEmpty($invoiceTemplate->itemtemplates); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use App\Models\Client; | ||
use App\Models\InvoiceEvent; | ||
use App\Models\InvoiceTemplate; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class InvoiceTemplateTest extends TestCase | ||
{ | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function test_create_invoice_template() | ||
{ | ||
$client = factory(Client::class)->create(); | ||
$invoiceEvent = factory(InvoiceEvent::class)->create(); | ||
|
||
InvoiceTemplate::unguard(); | ||
|
||
$invoiceTemplate = InvoiceTemplate::create([ | ||
'date' => '2018-11-01 00:00:00', | ||
'netdays' => '20', | ||
'notify' => '0', | ||
'client_id' => $client->id, | ||
'invoice_event_id' => $invoiceEvent->id | ||
]); | ||
|
||
InvoiceTemplate::reguard(); | ||
|
||
$this->assertEquals($client->company->name, $invoiceTemplate->client->company->name); | ||
$this->assertEquals('20', $invoiceTemplate->netdays); | ||
$this->assertEquals('2018-11-01 00:00:00', $invoiceTemplate->date->timezone(config('app.timezone'))->toDateTimeString()); | ||
} | ||
|
||
public function test_update_invoice_template() | ||
{ | ||
$invoiceTemplate = factory(InvoiceTemplate::class)->create(); | ||
$this->assertInstanceOf(InvoiceTemplate::class, $invoiceTemplate); | ||
|
||
$invoiceTemplate->netdays = '50'; | ||
$invoiceTemplate->notify = '0'; | ||
$invoiceTemplate->save(); | ||
$invoiceTemplate->refresh(); | ||
|
||
$this->assertEquals('50', $invoiceTemplate->netdays); | ||
$this->assertEquals('0', $invoiceTemplate->notify); | ||
|
||
//Testing fillable properties | ||
$data = [ | ||
'date' => '2018-11-26 00:00:00', | ||
'netdays' => '30', | ||
'notify' => '1' | ||
]; | ||
|
||
$invoiceTemplate->fill($data); | ||
$invoiceTemplate->save(); | ||
$invoiceTemplate->refresh(); | ||
|
||
$this->assertEquals('30', $invoiceTemplate->netdays); | ||
$this->assertEquals('1', $invoiceTemplate->notify); | ||
$this->assertEquals('2018-11-26 00:00:00', $invoiceTemplate->date->timezone(config('app.timezone'))->toDateTimeString()); | ||
} | ||
|
||
public function test_delete_invoice_template() | ||
{ | ||
$invoiceTemplate = factory(InvoiceTemplate::class)->create(); | ||
$this->assertInstanceOf(InvoiceTemplate::class, $invoiceTemplate); | ||
$invoiceTemplate = $invoiceTemplate->delete(); | ||
|
||
$this->assertEquals('true', json_encode($invoiceTemplate)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class PaymentTest extends TestCase | ||
{ | ||
/** | ||
* A basic test example. | ||
* | ||
* @return void | ||
*/ | ||
public function testExample() | ||
{ | ||
$this->assertTrue(true); | ||
} | ||
} |