Work on tests

This commit is contained in:
Nisse Lommerde 2025-01-19 12:51:37 -05:00
parent efe78bb49f
commit 7ca9c85369
7 changed files with 56 additions and 31 deletions

View File

@ -20,6 +20,5 @@ enum IconEnum: string
case TAB_ALL = 'lucide-layout-grid';
case TAB_OVERDUE = 'lucide-calendar-clock';
case TAB_UNPRINTED = ' lucide-printer';
case TAB_UNPRINTED = 'lucide-printer';
}

View File

@ -52,6 +52,15 @@ class Order extends Model
protected $casts = [
'status' => OrderStatus::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

View File

@ -10,7 +10,7 @@ class CustomerFactory extends Factory
{
protected $model = Customer::class;
public function definition()
public function definition(): array
{
$company_name = $this->faker->company();
$internal_name = explode(',', $company_name);

View File

@ -15,7 +15,7 @@ class InvoiceFactory extends Factory
public function definition(): array
{
$customer = Customer::all()->shuffle()->first();
$customer = Customer::all()->shuffle()->firstOrFail();
return [
'created_at' => Carbon::now()->subDays(rand(1, 30)),

View File

@ -4,20 +4,21 @@
use App\Filament\Admin\Resources\InvoiceResource\Pages\CreateInvoice;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\Order;
use App\Models\TaxRate;
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 () {
$customer = Customer::factory()->create(); // Generates a customer
$user = User::factory(['is_admin' => true])->create();
$this->actingAs($user);
$customer = Customer::factory()->create(); // Generates a customer
$pst_rate = TaxRate::where('name', 'PST')->value('value') ?? 0;
$gst_rate = TaxRate::where('name', 'GST')->value('value') ?? 0;
$this->actingAs($user);
$formData = [
'customer_id' => $customer->id,
'date' => now()->toDateString(),
@ -27,13 +28,11 @@
'has_pst' => true,
];
// Step 3: Submit the form and create an invoice
$this->livewire(CreateInvoice::class)
->fillForm($formData) // Simulates filling the form
->call('create') // Submits the form
->assertHasNoErrors(); // Verifies no validation errors occurred
->fillForm($formData)
->call('create')
->assertHasNoErrors();
// Step 4: Assert the invoice was successfully created in the database
$this->assertDatabaseHas('invoices', [
'internal_id' => 'INV400001',
'customer_id' => $formData['customer_id'],
@ -43,8 +42,20 @@
'gst_rate' => $gst_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

View File

@ -15,14 +15,20 @@
use App\Models\ServiceFile;
use App\Models\ServiceType;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\RefreshDatabase;
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 () {
$type = fake()->randomElement(OrderType::cases());
$status = fake()->randomElement(OrderStatus::cases());
$customer = Customer::factory()->create();
$contact = Contact::factory()->for($customer)->create();
// $contact = Contact::factory()->for($customer)->create();
$attributes = array_map(fn ($case) => $case->value, OrderAttributes::cases());
$orderDate = today();
$dueDate = today()->addDays(10);
@ -144,15 +150,15 @@
$status,
$dueDate->format('Y-m-d'),
'Notes go here! Here\'s the notes!',
1,
1,
1,
1,
1,
1,
1,
1,
1,
true,
true,
true,
true,
true,
true,
true,
true,
true,
]);
// Order Products

View File

@ -12,7 +12,7 @@
*/
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
// ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');
/*