Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | public function testStatusInfo(): void | ||||
$this->assertSame(['meet'], $result['betaSKUs']); | $this->assertSame(['meet'], $result['betaSKUs']); | ||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
Queue::fake(); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | $deleted_priv = $this->getTestUser('deleted@kolab.org'); | ||||
$deleted_priv->delete(); | $deleted_priv->delete(); | ||||
// Test empty request | // Test empty request | ||||
$response = $this->actingAs($john)->post("/api/v4/users", []); | $response = $this->actingAs($john)->post("/api/v4/users", []); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$this->assertSame('deleted@kolab.org', $aliases[0]->alias); | $this->assertSame('deleted@kolab.org', $aliases[0]->alias); | ||||
$this->assertSame('useralias1@kolab.org', $aliases[1]->alias); | $this->assertSame('useralias1@kolab.org', $aliases[1]->alias); | ||||
// Assert the new user entitlements | // Assert the new user entitlements | ||||
$this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage']); | $this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage']); | ||||
// Assert the wallet to which the new user should be assigned to | // Assert the wallet to which the new user should be assigned to | ||||
$wallet = $user->wallet(); | $wallet = $user->wallet(); | ||||
$this->assertSame($john->wallets()->first()->id, $wallet->id); | $this->assertSame($john->wallets()->first()->id, $wallet->id); | ||||
// Test acting as account controller (not owner) | // Attempt to create a user previously deleted | ||||
/* | $user->delete(); | ||||
// FIXME: How do we know to which wallet the new user should be assigned to? | |||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $post['package'] = $package_kolab->id; | ||||
$response = $this->actingAs($ned)->post("/api/v4/users", $post); | $post['aliases'] = []; | ||||
$response = $this->actingAs($john)->post("/api/v4/users", $post); | |||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
*/ | $this->assertSame("User created successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | |||||
$user = User::where('email', 'john2.doe2@kolab.org')->first(); | |||||
$this->assertInstanceOf(User::class, $user); | |||||
$this->assertSame('John2', $user->getSetting('first_name')); | |||||
$this->assertSame('Doe2', $user->getSetting('last_name')); | |||||
$this->assertSame('TestOrg', $user->getSetting('organization')); | |||||
$this->assertCount(0, $user->aliases()->get()); | |||||
$this->assertUserEntitlements($user, ['groupware', 'mailbox', 'storage', 'storage']); | |||||
// Test acting as account controller (not owner) | |||||
$this->markTestIncomplete(); | $this->markTestIncomplete(); | ||||
} | } | ||||
/** | /** | ||||
* Test user update (PUT /api/v4/users/<user-id>) | * Test user update (PUT /api/v4/users/<user-id>) | ||||
*/ | */ | ||||
public function testUpdate(): void | public function testUpdate(): void | ||||
▲ Show 20 Lines • Show All 477 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
public function testValidateEmail($email, $user, $expected_result): void | public function testValidateEmail($email, $user, $expected_result): void | ||||
{ | { | ||||
$result = UsersController::validateEmail($email, $user); | $result = UsersController::validateEmail($email, $user); | ||||
$this->assertSame($expected_result, $result); | $this->assertSame($expected_result, $result); | ||||
} | } | ||||
/** | /** | ||||
* User email validation - tests for $deleted argument | |||||
* | |||||
* Note: Technically these include unit tests, but let's keep it here for now. | |||||
* FIXME: Shall we do a http request for each case? | |||||
*/ | |||||
public function testValidateEmailDeleted(): void | |||||
{ | |||||
Queue::fake(); | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | |||||
$deleted_priv->delete(); | |||||
$deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | |||||
$deleted_pub->delete(); | |||||
$result = UsersController::validateEmail('deleted@kolab.org', $john, $deleted); | |||||
$this->assertSame(null, $result); | |||||
$this->assertSame($deleted_priv->id, $deleted->id); | |||||
$result = UsersController::validateEmail('deleted@kolabnow.com', $john, $deleted); | |||||
$this->assertSame('The specified email is not available.', $result); | |||||
$this->assertSame(null, $deleted); | |||||
$result = UsersController::validateEmail('jack@kolab.org', $john, $deleted); | |||||
$this->assertSame('The specified email is not available.', $result); | |||||
$this->assertSame(null, $deleted); | |||||
} | |||||
/** | |||||
* List of alias validation cases for testValidateAlias() | * List of alias validation cases for testValidateAlias() | ||||
* | * | ||||
* @return array Arguments for testValidateAlias() | * @return array Arguments for testValidateAlias() | ||||
*/ | */ | ||||
public function dataValidateAlias(): array | public function dataValidateAlias(): array | ||||
{ | { | ||||
$this->refreshApplication(); | $this->refreshApplication(); | ||||
$public_domains = Domain::getPublicDomains(); | $public_domains = Domain::getPublicDomains(); | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |