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; $formData = [ 'customer_id' => $customer->id, 'date' => now()->toDateString(), 'due_date' => now()->addDays(7)->toDateString(), 'status' => InvoiceStatus::UNPAID->value, 'has_gst' => true, 'has_pst' => true, ]; $this->livewire(CreateInvoice::class) ->fillForm($formData) ->call('create') ->assertHasNoErrors(); $this->assertDatabaseHas('invoices', [ 'internal_id' => 'INV400001', 'customer_id' => $formData['customer_id'], 'status' => $formData['status'], 'has_gst' => $formData['has_gst'], 'has_pst' => $formData['has_pst'], '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 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