73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<?php
|
|
|
|
use App\Livewire\Billing;
|
|
use App\Livewire\ConfirmRemoveOrder;
|
|
use App\Models\Customer;
|
|
use App\Models\Order;
|
|
use App\Models\User;
|
|
|
|
function cartCustomer(): array
|
|
{
|
|
$customer = Customer::factory()->create();
|
|
$user = User::factory()->create(['email' => $customer->email]);
|
|
|
|
return [$customer, $user];
|
|
}
|
|
|
|
it('says what was ordered instead of counting it', function () {
|
|
[$customer, $user] = cartCustomer();
|
|
|
|
Order::factory()->for($customer)->create(['type' => 'traffic', 'plan' => 'team', 'amount_cents' => 500, 'status' => 'pending']);
|
|
Order::factory()->for($customer)->create(['type' => 'upgrade', 'plan' => 'business', 'amount_cents' => 39900, 'status' => 'pending']);
|
|
|
|
Livewire\Livewire::actingAs($user)->test(Billing::class)
|
|
->assertSee(__('billing.cart.title'))
|
|
->assertSee(__('billing.cart.traffic', ['gb' => 1000]))
|
|
->assertSee(__('billing.cart.upgrade', ['plan' => 'Business']))
|
|
// …and what it all comes to.
|
|
->assertSee('404,00');
|
|
});
|
|
|
|
it('leaves paid orders out of the cart', function () {
|
|
[$customer, $user] = cartCustomer();
|
|
Order::factory()->for($customer)->create(['type' => 'storage', 'amount_cents' => 1000, 'status' => 'paid']);
|
|
|
|
Livewire\Livewire::actingAs($user)->test(Billing::class)->assertDontSee(__('billing.cart.title'));
|
|
});
|
|
|
|
it('removes an entry the customer changed their mind about', function () {
|
|
[$customer, $user] = cartCustomer();
|
|
$order = Order::factory()->for($customer)->create(['type' => 'storage', 'amount_cents' => 1000, 'status' => 'pending']);
|
|
|
|
Livewire\Livewire::actingAs($user)
|
|
->test(ConfirmRemoveOrder::class, ['uuid' => $order->uuid])
|
|
->assertSee(__('billing.cart.storage', ['gb' => 100]))
|
|
->call('remove');
|
|
|
|
expect(Order::query()->count())->toBe(0);
|
|
});
|
|
|
|
it('will not let one customer remove another customer\'s order', function () {
|
|
[, $user] = cartCustomer();
|
|
$stranger = Customer::factory()->create();
|
|
$order = Order::factory()->for($stranger)->create(['status' => 'pending']);
|
|
|
|
// Modals are reachable without the page's guards, so this is the real check.
|
|
Livewire\Livewire::actingAs($user)
|
|
->test(ConfirmRemoveOrder::class, ['uuid' => $order->uuid])
|
|
->assertNotFound();
|
|
|
|
expect(Order::query()->whereKey($order->id)->exists())->toBeTrue();
|
|
});
|
|
|
|
it('refuses to remove an order that is already paid', function () {
|
|
[$customer, $user] = cartCustomer();
|
|
$order = Order::factory()->for($customer)->create(['status' => 'paid']);
|
|
|
|
Livewire\Livewire::actingAs($user)
|
|
->test(ConfirmRemoveOrder::class, ['uuid' => $order->uuid])
|
|
->assertNotFound();
|
|
|
|
expect(Order::query()->whereKey($order->id)->exists())->toBeTrue();
|
|
});
|