Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Console/Wallet/ChargeTest.php
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | public function testHandleSingle(): void | ||||
Queue::assertPushed(\App\Jobs\WalletCheck::class, function ($job) use ($wallet) { | Queue::assertPushed(\App\Jobs\WalletCheck::class, function ($job) use ($wallet) { | ||||
$job_wallet = TestCase::getObjectProperty($job, 'wallet'); | $job_wallet = TestCase::getObjectProperty($job, 'wallet'); | ||||
return $job_wallet->id === $wallet->id; | return $job_wallet->id === $wallet->id; | ||||
}); | }); | ||||
Queue::fake(); | Queue::fake(); | ||||
// The wallet has entitlements to charge, and negative balance | // The wallet has entitlements to charge, and negative balance | ||||
$sku = \App\Sku::where('title', 'mailbox')->first(); | $sku = \App\Sku::withObjectTenantContext($user)->where('title', 'mailbox')->first(); | ||||
$entitlement = \App\Entitlement::create([ | $entitlement = \App\Entitlement::create([ | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'sku_id' => $sku->id, | 'sku_id' => $sku->id, | ||||
'cost' => 100, | 'cost' => 100, | ||||
'entitleable_id' => $user->id, | 'entitleable_id' => $user->id, | ||||
'entitleable_type' => \App\User::class, | 'entitleable_type' => \App\User::class, | ||||
]); | ]); | ||||
\App\Entitlement::where('id', $entitlement->id)->update([ | \App\Entitlement::where('id', $entitlement->id)->update([ | ||||
'created_at' => \Carbon\Carbon::now()->subMonths(1), | 'created_at' => \Carbon\Carbon::now()->subMonthsNoOverflow(1), | ||||
'updated_at' => \Carbon\Carbon::now()->subMonths(1), | 'updated_at' => \Carbon\Carbon::now()->subMonthsNoOverflow(1), | ||||
]); | ]); | ||||
\App\User::where('id', $user->id)->update([ | \App\User::where('id', $user->id)->update([ | ||||
'created_at' => \Carbon\Carbon::now()->subMonths(1), | 'created_at' => \Carbon\Carbon::now()->subMonthsNoOverflow(1), | ||||
'updated_at' => \Carbon\Carbon::now()->subMonths(1), | 'updated_at' => \Carbon\Carbon::now()->subMonthsNoOverflow(1), | ||||
]); | ]); | ||||
$this->assertSame(100, $wallet->fresh()->chargeEntitlements(false)); | $this->assertSame(100, $wallet->fresh()->chargeEntitlements(false)); | ||||
$this->artisan('wallet:charge ' . $wallet->id) | $this->artisan('wallet:charge ' . $wallet->id) | ||||
->assertExitCode(0); | ->assertExitCode(0); | ||||
Queue::assertPushed(\App\Jobs\WalletCharge::class, 1); | Queue::assertPushed(\App\Jobs\WalletCharge::class, 1); | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |