Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show All 17 Lines | |||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('jane@kolabnow.com'); | |||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | $wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | ||||
$wallet->save(); | $wallet->save(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('jane@kolabnow.com'); | |||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
▲ Show 20 Lines • Show All 648 Lines • ▼ Show 20 Lines | public function testUpdate(): void | ||||
$response = $this->actingAs($owner)->put("/api/v4/users/{$user->id}", $post); | $response = $this->actingAs($owner)->put("/api/v4/users/{$user->id}", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$storage_cost = $user->entitlements() | $storage_cost = $user->entitlements() | ||||
->where('sku_id', $sku_storage->id) | ->where('sku_id', $sku_storage->id) | ||||
->orderBy('cost') | ->orderBy('cost') | ||||
->pluck('cost')->all(); | ->pluck('cost')->all(); | ||||
$this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage', 'storage']); | $this->assertUserEntitlements( | ||||
$user, | |||||
['groupware', 'mailbox', 'storage', 'storage', 'storage'] | |||||
); | |||||
$this->assertSame([0, 0, 25], $storage_cost); | $this->assertSame([0, 0, 25], $storage_cost); | ||||
} | } | ||||
/** | /** | ||||
* Test UsersController::updateEntitlements() | * Test UsersController::updateEntitlements() | ||||
*/ | */ | ||||
public function testUpdateEntitlements(): void | public function testUpdateEntitlements(): void | ||||
{ | { | ||||
// TODO: Test more cases of entitlements update | $jane = $this->getTestUser('jane@kolabnow.com'); | ||||
$this->markTestIncomplete(); | |||||
$kolab = \App\Package::where('title', 'kolab')->first(); | |||||
$storage = \App\Sku::where('title', 'storage')->first(); | |||||
$activesync = \App\Sku::where('title', 'activesync')->first(); | |||||
$groupware = \App\Sku::where('title', 'groupware')->first(); | |||||
$mailbox = \App\Sku::where('title', 'mailbox')->first(); | |||||
// standard package, 1 mailbox, 1 groupware, 2 storage | |||||
$jane->assignPackage($kolab); | |||||
// add 2 storage, 1 activesync | |||||
$post = [ | |||||
'skus' => [ | |||||
$mailbox->id => 1, | |||||
$groupware->id => 1, | |||||
$storage->id => 4, | |||||
$activesync->id => 1 | |||||
] | |||||
]; | |||||
$response = $this->actingAs($jane)->put("/api/v4/users/{$jane->id}", $post); | |||||
$response->assertStatus(200); | |||||
$this->assertUserEntitlements( | |||||
$jane, | |||||
[ | |||||
'activesync', | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage' | |||||
] | |||||
); | |||||
// add 2 storage, remove 1 activesync | |||||
$post = [ | |||||
'skus' => [ | |||||
$mailbox->id => 1, | |||||
$groupware->id => 1, | |||||
$storage->id => 6, | |||||
$activesync->id => 0 | |||||
] | |||||
]; | |||||
$response = $this->actingAs($jane)->put("/api/v4/users/{$jane->id}", $post); | |||||
$response->assertStatus(200); | |||||
$this->assertUserEntitlements( | |||||
$jane, | |||||
[ | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage' | |||||
] | |||||
); | |||||
// add mailbox | |||||
$post = [ | |||||
'skus' => [ | |||||
$mailbox->id => 2, | |||||
$groupware->id => 1, | |||||
$storage->id => 6, | |||||
$activesync->id => 0 | |||||
] | |||||
]; | |||||
$response = $this->actingAs($jane)->put("/api/v4/users/{$jane->id}", $post); | |||||
$response->assertStatus(500); | |||||
$this->assertUserEntitlements( | |||||
$jane, | |||||
[ | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage' | |||||
] | |||||
); | |||||
// remove mailbox | |||||
$post = [ | |||||
'skus' => [ | |||||
$mailbox->id => 0, | |||||
$groupware->id => 1, | |||||
$storage->id => 6, | |||||
$activesync->id => 0 | |||||
] | |||||
]; | |||||
$response = $this->actingAs($jane)->put("/api/v4/users/{$jane->id}", $post); | |||||
$response->assertStatus(500); | |||||
$this->assertUserEntitlements( | |||||
$jane, | |||||
[ | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage', | |||||
'storage' | |||||
] | |||||
); | |||||
// less than free storage | |||||
$post = [ | |||||
'skus' => [ | |||||
$mailbox->id => 1, | |||||
$groupware->id => 1, | |||||
$storage->id => 1, | |||||
$activesync->id => 0 | |||||
] | |||||
]; | |||||
$response = $this->actingAs($jane)->put("/api/v4/users/{$jane->id}", $post); | |||||
$response->assertStatus(200); | |||||
$this->assertUserEntitlements( | |||||
$jane, | |||||
[ | |||||
'groupware', | |||||
'mailbox', | |||||
'storage', | |||||
'storage' | |||||
] | |||||
); | |||||
} | } | ||||
/** | /** | ||||
* Test user data response used in show and info actions | * Test user data response used in show and info actions | ||||
*/ | */ | ||||
public function testUserResponse(): void | public function testUserResponse(): void | ||||
{ | { | ||||
$provider = \config('services.payment_provider') ?: 'mollie'; | $provider = \config('services.payment_provider') ?: 'mollie'; | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |