Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/WalletsTest.php
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public function testGetWalletNotice(): void | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertSame('You are out of credit, top up your balance now.', $notice); | $this->assertSame('You are out of credit, top up your balance now.', $notice); | ||||
// User/entitlements created slightly more than a month ago, balance=9,99 CHF (monthly) | // User/entitlements created slightly more than a month ago, balance=9,99 CHF (monthly) | ||||
$wallet->owner->created_at = Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1); | $wallet->owner->created_at = Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1); | ||||
$wallet->owner->save(); | $wallet->owner->save(); | ||||
// test "1 month" | |||||
$wallet->balance = 999; | $wallet->balance = 999; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertRegExp('/\((1 month|4 weeks)\)/', $notice); | $this->assertRegExp('/\((1 month|4 weeks)\)/', $notice); | ||||
// test "2 months" | |||||
$wallet->balance = 999 * 2.6; | |||||
$notice = $method->invoke($controller, $wallet); | |||||
$this->assertRegExp('/\(2 months 2 weeks\)/', $notice); | |||||
// test "almost 2 years" | |||||
$wallet->balance = 999 * 23.5; | |||||
$notice = $method->invoke($controller, $wallet); | |||||
$this->assertRegExp('/\(1 year 11 months\)/', $notice); | |||||
// Old entitlements, 100% discount | // Old entitlements, 100% discount | ||||
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40)); | $this->backdateEntitlements($wallet->entitlements, Carbon::now()->subDays(40)); | ||||
$discount = \App\Discount::where('discount', 100)->first(); | $discount = \App\Discount::where('discount', 100)->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
$notice = $method->invoke($controller, $wallet->refresh()); | $notice = $method->invoke($controller, $wallet->refresh()); | ||||
$this->assertSame(null, $notice); | $this->assertSame(null, $notice); | ||||
▲ Show 20 Lines • Show All 255 Lines • Show Last 20 Lines |