Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/WalletsTest.php
Show All 31 Lines | class WalletsTest extends TestCase | ||||
} | } | ||||
/** | /** | ||||
* Test for getWalletNotice() method | * Test for getWalletNotice() method | ||||
*/ | */ | ||||
public function testGetWalletNotice(): void | public function testGetWalletNotice(): void | ||||
{ | { | ||||
$user = $this->getTestUser('wallets-controller@kolabnow.com'); | $user = $this->getTestUser('wallets-controller@kolabnow.com'); | ||||
$package = \App\Package::withObjectTenantContext($user)->where('title', 'kolab')->first(); | $plan = \App\Plan::withObjectTenantContext($user)->where('title', 'individual')->first(); | ||||
$user->assignPackage($package); | $user->assignPlan($plan); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$controller = new WalletsController(); | $controller = new WalletsController(); | ||||
$method = new \ReflectionMethod($controller, 'getWalletNotice'); | $method = new \ReflectionMethod($controller, 'getWalletNotice'); | ||||
$method->setAccessible(true); | $method->setAccessible(true); | ||||
// User/entitlements created today, balance=0 | // User/entitlements created today, balance=0 | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertSame('You are in your free trial period.', $notice); | $this->assertSame('You are in your free trial period.', $notice); | ||||
$wallet->owner->created_at = Carbon::now()->subDays(15); | $wallet->owner->created_at = Carbon::now()->subWeeks(3); | ||||
$wallet->owner->save(); | $wallet->owner->save(); | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertSame('Your free trial is about to end, top up to continue.', $notice); | $this->assertSame('Your free trial is about to end, top up to continue.', $notice); | ||||
// User/entitlements created today, balance=-10 CHF | // User/entitlements created today, balance=-10 CHF | ||||
$wallet->balance = -1000; | $wallet->balance = -1000; | ||||
$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); | $this->backdateEntitlements($wallet->entitlements, Carbon::now()->subMonthsWithoutOverflow(1)->subDays(1)); | ||||
$wallet->owner->save(); | $wallet->refresh(); | ||||
// test "1 month" | // test "1 month" | ||||
$wallet->balance = 990; | $wallet->balance = 990; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertMatchesRegularExpression('/\((1 month|4 weeks)\)/', $notice); | $this->assertMatchesRegularExpression('/\((1 month|4 weeks)\)/', $notice); | ||||
// test "2 months" | // test "2 months" | ||||
$wallet->balance = 990 * 2.6; | $wallet->balance = 990 * 2.6; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertMatchesRegularExpression('/\(2 months 2 weeks\)/', $notice); | $this->assertMatchesRegularExpression('/\(1 month 4 weeks\)/', $notice); | ||||
// Change locale to make sure the text is localized by Carbon | // Change locale to make sure the text is localized by Carbon | ||||
\app()->setLocale('de'); | \app()->setLocale('de'); | ||||
// test "almost 2 years" | // test "almost 2 years" | ||||
$wallet->balance = 990 * 23.5; | $wallet->balance = 990 * 23.5; | ||||
$notice = $method->invoke($controller, $wallet); | $notice = $method->invoke($controller, $wallet); | ||||
$this->assertMatchesRegularExpression('/\(1 Jahr 11 Monate\)/', $notice); | $this->assertMatchesRegularExpression('/\(1 Jahr 10 Monate\)/', $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::withObjectTenantContext($user)->where('discount', 100)->first(); | $discount = \App\Discount::withObjectTenantContext($user)->where('discount', 100)->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
$notice = $method->invoke($controller, $wallet->refresh()); | $notice = $method->invoke($controller, $wallet->refresh()); | ||||
▲ Show 20 Lines • Show All 259 Lines • Show Last 20 Lines |