File: /home/xedaptot/ai.naniguide.com/tests/Unit/RemoteSubscription/RemoteSubscriptionDTOTest.php
<?php
namespace Tests\Unit\RemoteSubscription;
use Tests\TestCase;
use App\Cashier\DTO\RemoteSubscriptionDTO;
use Carbon\Carbon;
class RemoteSubscriptionDTOTest extends TestCase
{
public function test_active_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_123',
status: 'active',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: Carbon::parse('2026-04-12'),
currentPeriodStart: Carbon::parse('2026-03-12'),
canceledAt: null,
latestInvoiceAmount: 29.99,
latestInvoiceStatus: 'paid',
);
$this->assertTrue($dto->isActive());
$this->assertFalse($dto->isCanceled());
$this->assertFalse($dto->isPastDue());
$this->assertEquals('sub_123', $dto->id);
$this->assertEquals(29.99, $dto->latestInvoiceAmount);
}
public function test_trialing_is_active()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_trial',
status: 'trialing',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: Carbon::parse('2026-04-12'),
currentPeriodStart: Carbon::parse('2026-03-12'),
canceledAt: null,
latestInvoiceAmount: null,
latestInvoiceStatus: null,
);
$this->assertTrue($dto->isActive());
$this->assertFalse($dto->isCanceled());
}
public function test_canceled_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_canceled',
status: 'canceled',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: Carbon::parse('2026-03-12'),
currentPeriodStart: Carbon::parse('2026-02-12'),
canceledAt: Carbon::parse('2026-03-10'),
latestInvoiceAmount: 29.99,
latestInvoiceStatus: 'paid',
);
$this->assertFalse($dto->isActive());
$this->assertTrue($dto->isCanceled());
$this->assertFalse($dto->isPastDue());
}
public function test_past_due_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_overdue',
status: 'past_due',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: Carbon::parse('2026-03-12'),
currentPeriodStart: Carbon::parse('2026-02-12'),
canceledAt: null,
latestInvoiceAmount: 29.99,
latestInvoiceStatus: 'open',
);
$this->assertFalse($dto->isActive());
$this->assertFalse($dto->isCanceled());
$this->assertTrue($dto->isPastDue());
}
public function test_unpaid_is_past_due()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_unpaid',
status: 'unpaid',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: null,
currentPeriodStart: null,
canceledAt: null,
latestInvoiceAmount: null,
latestInvoiceStatus: null,
);
$this->assertTrue($dto->isPastDue());
}
public function test_incomplete_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_inc',
status: 'incomplete',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: null,
currentPeriodStart: null,
canceledAt: null,
latestInvoiceAmount: null,
latestInvoiceStatus: null,
);
$this->assertTrue($dto->isIncomplete());
$this->assertFalse($dto->isIncompleteExpired());
$this->assertFalse($dto->isActive());
$this->assertTrue($dto->hasIssue());
$this->assertFalse($dto->isTerminal());
}
public function test_incomplete_expired_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_ie',
status: 'incomplete_expired',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: null,
currentPeriodStart: null,
canceledAt: null,
latestInvoiceAmount: null,
latestInvoiceStatus: null,
);
$this->assertTrue($dto->isIncompleteExpired());
$this->assertFalse($dto->isIncomplete());
$this->assertTrue($dto->isTerminal());
$this->assertFalse($dto->hasIssue());
}
public function test_paused_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_paused',
status: 'paused',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: Carbon::now()->addDays(10),
currentPeriodStart: Carbon::now()->subDays(20),
canceledAt: null,
latestInvoiceAmount: null,
latestInvoiceStatus: null,
);
$this->assertTrue($dto->isPaused());
$this->assertFalse($dto->isActive());
$this->assertTrue($dto->hasIssue());
$this->assertFalse($dto->isTerminal());
}
public function test_trialing_subscription()
{
$dto = new RemoteSubscriptionDTO(
id: 'sub_trial2',
status: 'trialing',
remotePlanId: 'price_456',
remoteCustomerId: 'cus_789',
currentPeriodEnd: Carbon::now()->addDays(14),
currentPeriodStart: Carbon::now(),
canceledAt: null,
latestInvoiceAmount: null,
latestInvoiceStatus: null,
);
$this->assertTrue($dto->isTrialing());
$this->assertTrue($dto->isActive()); // trialing = active
$this->assertFalse($dto->hasIssue());
$this->assertFalse($dto->isTerminal());
}
public function test_terminal_statuses()
{
$canceled = new RemoteSubscriptionDTO(
id: 'sub_c', status: 'canceled', remotePlanId: 'p', remoteCustomerId: 'c',
currentPeriodEnd: null, currentPeriodStart: null, canceledAt: Carbon::now(),
latestInvoiceAmount: null, latestInvoiceStatus: null,
);
$this->assertTrue($canceled->isTerminal());
$incExpired = new RemoteSubscriptionDTO(
id: 'sub_ie', status: 'incomplete_expired', remotePlanId: 'p', remoteCustomerId: 'c',
currentPeriodEnd: null, currentPeriodStart: null, canceledAt: null,
latestInvoiceAmount: null, latestInvoiceStatus: null,
);
$this->assertTrue($incExpired->isTerminal());
$active = new RemoteSubscriptionDTO(
id: 'sub_a', status: 'active', remotePlanId: 'p', remoteCustomerId: 'c',
currentPeriodEnd: null, currentPeriodStart: null, canceledAt: null,
latestInvoiceAmount: null, latestInvoiceStatus: null,
);
$this->assertFalse($active->isTerminal());
}
public function test_issue_statuses()
{
foreach (['past_due', 'unpaid', 'incomplete', 'paused'] as $status) {
$dto = new RemoteSubscriptionDTO(
id: "sub_{$status}", status: $status, remotePlanId: 'p', remoteCustomerId: 'c',
currentPeriodEnd: null, currentPeriodStart: null, canceledAt: null,
latestInvoiceAmount: null, latestInvoiceStatus: null,
);
$this->assertTrue($dto->hasIssue(), "Status '{$status}' should have issue");
}
foreach (['active', 'trialing', 'canceled', 'incomplete_expired'] as $status) {
$dto = new RemoteSubscriptionDTO(
id: "sub_{$status}", status: $status, remotePlanId: 'p', remoteCustomerId: 'c',
currentPeriodEnd: null, currentPeriodStart: null, canceledAt: null,
latestInvoiceAmount: null, latestInvoiceStatus: null,
);
$this->assertFalse($dto->hasIssue(), "Status '{$status}' should NOT have issue");
}
}
}