update rm deadcode
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Api\Service;
|
||||
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Models\Addon;
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Invoice;
|
||||
@@ -13,6 +14,7 @@ use App\Models\OrderItem;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductPricings;
|
||||
use App\Models\Service;
|
||||
use App\Models\ServiceAddon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -70,6 +72,137 @@ class RenewServiceTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
private function createServiceWithCycle(string $billingCycle, int $cycleMonths, int $oldPrice): Service
|
||||
{
|
||||
$order = Order::create([
|
||||
'order_num' => 'ORD-' . uniqid(),
|
||||
'customer_id' => $this->customer->id,
|
||||
'sub_total' => $oldPrice,
|
||||
'total' => $oldPrice,
|
||||
'status' => OrderStatus::ACTIVE->value,
|
||||
]);
|
||||
|
||||
$orderItem = OrderItem::create([
|
||||
'order_id' => $order->id,
|
||||
'product_id' => $this->product->id,
|
||||
'billing_cycle' => $billingCycle,
|
||||
'months' => $cycleMonths,
|
||||
'quantity' => 1,
|
||||
'price' => $oldPrice,
|
||||
]);
|
||||
|
||||
return Service::create([
|
||||
'customer_id' => $this->customer->id,
|
||||
'product_id' => $this->product->id,
|
||||
'order_item_id' => $orderItem->id,
|
||||
'status' => 'active',
|
||||
'server_name' => 'test-server',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_renew_annual_service_for_exactly_one_cycle_charges_the_annual_price(): void
|
||||
{
|
||||
$service = $this->createServiceWithCycle('annually', 12, 1_800_000);
|
||||
|
||||
ProductPricings::create([
|
||||
'product_id' => $this->product->id,
|
||||
'billing_cycle' => 'annually',
|
||||
'price' => 1_800_000,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAsCustomer()->postJson(
|
||||
"/v1/client/dich-vu/{$service->id}/renew",
|
||||
['months' => 12],
|
||||
);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.total', 1_800_000);
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => $response->json('data.invoice_id'),
|
||||
'total' => 1_800_000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_renew_annual_service_with_months_not_matching_the_cycle_is_rejected(): void
|
||||
{
|
||||
$service = $this->createServiceWithCycle('annually', 12, 1_800_000);
|
||||
|
||||
ProductPricings::create([
|
||||
'product_id' => $this->product->id,
|
||||
'billing_cycle' => 'annually',
|
||||
'price' => 1_800_000,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAsCustomer()->postJson(
|
||||
"/v1/client/dich-vu/{$service->id}/renew",
|
||||
['months' => 1],
|
||||
);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$this->assertSame(0, Invoice::where('customer_id', $this->customer->id)->count());
|
||||
}
|
||||
|
||||
public function test_renew_charges_the_recurring_addon_price_on_top_of_the_service_price(): void
|
||||
{
|
||||
$service = $this->createServiceWithOldPrice(90_000);
|
||||
|
||||
$addon = Addon::create([
|
||||
'type' => $this->product->product_type,
|
||||
'code' => 'ram',
|
||||
'name' => 'RAM',
|
||||
'price' => 50_000,
|
||||
'min' => 1,
|
||||
'max' => 64,
|
||||
'step' => 1,
|
||||
'status' => true,
|
||||
]);
|
||||
|
||||
$service->orderItem->update(['addons_meta' => [[
|
||||
'addon_id' => $addon->id,
|
||||
'code' => 'ram',
|
||||
'name' => 'RAM',
|
||||
'qty' => 2,
|
||||
'price' => 40_000,
|
||||
'subtotal' => 80_000,
|
||||
]]]);
|
||||
|
||||
ServiceAddon::create([
|
||||
'service_id' => $service->id,
|
||||
'addon_type' => 'ram',
|
||||
'addon_value' => '6144',
|
||||
'price' => 50_000,
|
||||
]);
|
||||
|
||||
ProductPricings::create([
|
||||
'product_id' => $this->product->id,
|
||||
'billing_cycle' => 'monthly',
|
||||
'price' => 100_000,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAsCustomer()->postJson(
|
||||
"/v1/client/dich-vu/{$service->id}/renew",
|
||||
['months' => 1],
|
||||
);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.total', 200_000);
|
||||
$invoiceId = $response->json('data.invoice_id');
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $invoiceId,
|
||||
'type' => 'renewal',
|
||||
'unit_price' => 100_000,
|
||||
]);
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $invoiceId,
|
||||
'type' => 'addon',
|
||||
'quantity' => 2,
|
||||
'total_price' => 100_000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_renew_uses_current_catalog_price_not_the_original_order_price(): void
|
||||
{
|
||||
$service = $this->createServiceWithOldPrice(90_000);
|
||||
|
||||
Reference in New Issue
Block a user