Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | class UsersTest extends TestCase | ||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
$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->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); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$post = [ | $post = [ | ||||
'password' => 'simple', | 'password' => 'simple', | ||||
'password_confirmation' => 'simple', | 'password_confirmation' => 'simple', | ||||
'first_name' => 'John2', | 'first_name' => 'John2', | ||||
'last_name' => 'Doe2', | 'last_name' => 'Doe2', | ||||
'email' => 'john2.doe2@kolab.org', | 'email' => 'john2.doe2@kolab.org', | ||||
'organization' => 'TestOrg', | 'organization' => 'TestOrg', | ||||
'aliases' => ['useralias1@kolab.org', 'useralias2@kolab.org'], | 'aliases' => ['useralias1@kolab.org', 'deleted@kolab.org'], | ||||
]; | ]; | ||||
// Missing package | // Missing package | ||||
$response = $this->actingAs($john)->post("/api/v4/users", $post); | $response = $this->actingAs($john)->post("/api/v4/users", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
Show All 25 Lines | public function testStore(): void | ||||
$user = User::where('email', 'john2.doe2@kolab.org')->first(); | $user = User::where('email', 'john2.doe2@kolab.org')->first(); | ||||
$this->assertInstanceOf(User::class, $user); | $this->assertInstanceOf(User::class, $user); | ||||
$this->assertSame('John2', $user->getSetting('first_name')); | $this->assertSame('John2', $user->getSetting('first_name')); | ||||
$this->assertSame('Doe2', $user->getSetting('last_name')); | $this->assertSame('Doe2', $user->getSetting('last_name')); | ||||
$this->assertSame('TestOrg', $user->getSetting('organization')); | $this->assertSame('TestOrg', $user->getSetting('organization')); | ||||
$aliases = $user->aliases()->orderBy('alias')->get(); | $aliases = $user->aliases()->orderBy('alias')->get(); | ||||
$this->assertCount(2, $aliases); | $this->assertCount(2, $aliases); | ||||
$this->assertSame('useralias1@kolab.org', $aliases[0]->alias); | $this->assertSame('deleted@kolab.org', $aliases[0]->alias); | ||||
$this->assertSame('useralias2@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) | // Test acting as account controller (not owner) | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 514 Lines • Show Last 20 Lines |