51 lines
1.7 KiB
PHP
51 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Company;
|
|
use App\Models\Invoice;
|
|
use App\Models\PaymentOption;
|
|
use App\Models\UserPaymentOption;
|
|
use Database\Seeders\PaymentOptionSeeder;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
test('payment option seeder creates multilingual options', function () {
|
|
/** @var TestCase $this */
|
|
$this->seed(PaymentOptionSeeder::class);
|
|
|
|
$monthly = PaymentOption::query()
|
|
->where('article_number', 'PR-MONTHLY-001')
|
|
->firstOrFail();
|
|
|
|
expect($monthly->translations()->count())->toBe(2);
|
|
});
|
|
|
|
test('user payment option supports company pivot and payments relation', function () {
|
|
/** @var TestCase $this */
|
|
$userPaymentOption = UserPaymentOption::factory()->create();
|
|
$company = Company::query()->create([
|
|
'name' => 'Test Company '.Str::random(6),
|
|
'slug' => 'test-company-'.Str::lower(Str::random(8)),
|
|
]);
|
|
|
|
$userPaymentOption->companies()->attach($company->id, ['is_active' => true]);
|
|
$payment = $userPaymentOption->payments()->create([
|
|
'amount_cents' => 9900,
|
|
'currency' => 'EUR',
|
|
'status' => 'succeeded',
|
|
'stripe_charge_id' => 'ch_test_123456',
|
|
]);
|
|
|
|
$this->assertModelExists($payment);
|
|
expect($userPaymentOption->companies()->whereKey($company->id)->exists())->toBeTrue();
|
|
expect($userPaymentOption->payments()->count())->toBe(1);
|
|
});
|
|
|
|
test('invoice factory creates valid relation graph', function () {
|
|
/** @var TestCase $this */
|
|
$invoice = Invoice::factory()->create();
|
|
|
|
$this->assertModelExists($invoice);
|
|
expect($invoice->user)->not->toBeNull();
|
|
expect($invoice->invoiceBillingAddress)->not->toBeNull();
|
|
expect($invoice->userPayment)->not->toBeNull();
|
|
});
|