Work on tests
This commit is contained in:
parent
efe78bb49f
commit
7ca9c85369
@ -20,6 +20,5 @@ enum IconEnum: string
|
|||||||
|
|
||||||
case TAB_ALL = 'lucide-layout-grid';
|
case TAB_ALL = 'lucide-layout-grid';
|
||||||
case TAB_OVERDUE = 'lucide-calendar-clock';
|
case TAB_OVERDUE = 'lucide-calendar-clock';
|
||||||
case TAB_UNPRINTED = ' lucide-printer';
|
case TAB_UNPRINTED = 'lucide-printer';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,17 @@ class Order extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'status' => OrderStatus::class,
|
'status' => OrderStatus::class,
|
||||||
'order_type' => OrderType::class,
|
'order_type' => OrderType::class,
|
||||||
|
'rush' => 'bool',
|
||||||
|
'repeat' => 'bool',
|
||||||
|
'new_art' => 'bool',
|
||||||
|
'event' => 'bool',
|
||||||
|
'digitizing' => 'bool',
|
||||||
|
'garments' => 'bool',
|
||||||
|
'supplied_file' => 'bool',
|
||||||
|
'printed' => 'bool',
|
||||||
|
'pre_production' => 'bool',
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function boot(): void
|
public static function boot(): void
|
||||||
|
@ -10,7 +10,7 @@ class CustomerFactory extends Factory
|
|||||||
{
|
{
|
||||||
protected $model = Customer::class;
|
protected $model = Customer::class;
|
||||||
|
|
||||||
public function definition()
|
public function definition(): array
|
||||||
{
|
{
|
||||||
$company_name = $this->faker->company();
|
$company_name = $this->faker->company();
|
||||||
$internal_name = explode(',', $company_name);
|
$internal_name = explode(',', $company_name);
|
||||||
|
@ -15,7 +15,7 @@ class InvoiceFactory extends Factory
|
|||||||
|
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
$customer = Customer::all()->shuffle()->first();
|
$customer = Customer::all()->shuffle()->firstOrFail();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
'created_at' => Carbon::now()->subDays(rand(1, 30)),
|
||||||
|
@ -4,20 +4,21 @@
|
|||||||
use App\Filament\Admin\Resources\InvoiceResource\Pages\CreateInvoice;
|
use App\Filament\Admin\Resources\InvoiceResource\Pages\CreateInvoice;
|
||||||
use App\Models\Customer;
|
use App\Models\Customer;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Order;
|
||||||
use App\Models\TaxRate;
|
use App\Models\TaxRate;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
|
||||||
uses(RefreshDatabase::class);
|
uses(DatabaseMigrations::class);
|
||||||
|
|
||||||
it('can create an invoice', function () {
|
it('can create an invoice', function () {
|
||||||
|
$user = User::factory(['is_admin' => true])->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
$customer = Customer::factory()->create(); // Generates a customer
|
$customer = Customer::factory()->create(); // Generates a customer
|
||||||
$user = User::factory(['is_admin' => true])->create();
|
|
||||||
$pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
|
$pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
|
||||||
$gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
|
$gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
|
||||||
|
|
||||||
$this->actingAs($user);
|
|
||||||
|
|
||||||
$formData = [
|
$formData = [
|
||||||
'customer_id' => $customer->id,
|
'customer_id' => $customer->id,
|
||||||
'date' => now()->toDateString(),
|
'date' => now()->toDateString(),
|
||||||
@ -27,13 +28,11 @@
|
|||||||
'has_pst' => true,
|
'has_pst' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Step 3: Submit the form and create an invoice
|
|
||||||
$this->livewire(CreateInvoice::class)
|
$this->livewire(CreateInvoice::class)
|
||||||
->fillForm($formData) // Simulates filling the form
|
->fillForm($formData)
|
||||||
->call('create') // Submits the form
|
->call('create')
|
||||||
->assertHasNoErrors(); // Verifies no validation errors occurred
|
->assertHasNoErrors();
|
||||||
|
|
||||||
// Step 4: Assert the invoice was successfully created in the database
|
|
||||||
$this->assertDatabaseHas('invoices', [
|
$this->assertDatabaseHas('invoices', [
|
||||||
'internal_id' => 'INV400001',
|
'internal_id' => 'INV400001',
|
||||||
'customer_id' => $formData['customer_id'],
|
'customer_id' => $formData['customer_id'],
|
||||||
@ -43,8 +42,20 @@
|
|||||||
'gst_rate' => $gst_rate,
|
'gst_rate' => $gst_rate,
|
||||||
'pst_rate' => $pst_rate,
|
'pst_rate' => $pst_rate,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$invoice = Invoice::where('internal_id', 'INV400001')->firstOrFail();
|
||||||
|
|
||||||
|
$this->assertEquals($invoice->orders->isEmpty(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// it can add orders
|
it('can add orders to an invoice', function () {
|
||||||
|
$customer = Customer::factory()->create();
|
||||||
|
$invoice = Invoice::factory()->create(['customer_id' => $customer->id]);
|
||||||
|
$orders = Order::factory()->for($customer)->count(3)->create();
|
||||||
|
|
||||||
|
$invoice->orders()->saveMany($orders);
|
||||||
|
|
||||||
|
$this->assertEquals($invoice->orders->count(), 3);
|
||||||
|
});
|
||||||
|
|
||||||
// it correctly calculates tax
|
// it correctly calculates tax
|
||||||
|
@ -15,14 +15,20 @@
|
|||||||
use App\Models\ServiceFile;
|
use App\Models\ServiceFile;
|
||||||
use App\Models\ServiceType;
|
use App\Models\ServiceType;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
use function Pest\Livewire\livewire;
|
use function Pest\Livewire\livewire;
|
||||||
|
|
||||||
|
//uses(RefreshDatabase::class);
|
||||||
|
uses(DatabaseMigrations::class);
|
||||||
|
|
||||||
it('can create an order and all associated models and save it to the database', function () {
|
it('can create an order and all associated models and save it to the database', function () {
|
||||||
$type = fake()->randomElement(OrderType::cases());
|
|
||||||
$status = fake()->randomElement(OrderStatus::cases());
|
$type = fake()->randomElement(OrderType::cases());
|
||||||
$customer = Customer::factory()->create();
|
$status = fake()->randomElement(OrderStatus::cases());
|
||||||
$contact = Contact::factory()->for($customer)->create();
|
$customer = Customer::factory()->create();
|
||||||
|
// $contact = Contact::factory()->for($customer)->create();
|
||||||
$attributes = array_map(fn ($case) => $case->value, OrderAttributes::cases());
|
$attributes = array_map(fn ($case) => $case->value, OrderAttributes::cases());
|
||||||
$orderDate = today();
|
$orderDate = today();
|
||||||
$dueDate = today()->addDays(10);
|
$dueDate = today()->addDays(10);
|
||||||
@ -144,15 +150,15 @@
|
|||||||
$status,
|
$status,
|
||||||
$dueDate->format('Y-m-d'),
|
$dueDate->format('Y-m-d'),
|
||||||
'Notes go here! Here\'s the notes!',
|
'Notes go here! Here\'s the notes!',
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
1,
|
true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Order Products
|
// Order Products
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
pest()->extend(Tests\TestCase::class)
|
pest()->extend(Tests\TestCase::class)
|
||||||
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
// ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
|
||||||
->in('Feature');
|
->in('Feature');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user