Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | public function testDestroyByController(): void | ||||
$domain->assignPackage($package_domain, $user1); | $domain->assignPackage($package_domain, $user1); | ||||
$user1->assignPackage($package_kolab, $user2); | $user1->assignPackage($package_kolab, $user2); | ||||
$user1->assignPackage($package_kolab, $user3); | $user1->assignPackage($package_kolab, $user3); | ||||
$user1->wallets()->first()->addController($user2); | $user1->wallets()->first()->addController($user2); | ||||
// TODO/FIXME: | // TODO/FIXME: | ||||
// For now controller can delete himself, as well as | // For now controller can delete himself, as well as | ||||
// the whole account he has control to, including the owner | // the whole account he has control to, including the owner | ||||
// Probably he should not be able to do either of those | // Probably he should not be able to do none of those | ||||
// However, this is not 0-regression scenario as we | // However, this is not 0-regression scenario as we | ||||
// do not fully support additional controllers. | // do not fully support additional controllers. | ||||
//$response = $this->actingAs($user2)->delete("api/v4/users/{$user2->id}"); | //$response = $this->actingAs($user2)->delete("api/v4/users/{$user2->id}"); | ||||
//$response->assertStatus(403); | //$response->assertStatus(403); | ||||
$response = $this->actingAs($user2)->delete("api/v4/users/{$user3->id}"); | $response = $this->actingAs($user2)->delete("api/v4/users/{$user3->id}"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | public function testUserResponse(): void | ||||
$this->assertTrue(is_array($result['aliases'])); | $this->assertTrue(is_array($result['aliases'])); | ||||
$this->assertCount(1, $result['aliases']); | $this->assertCount(1, $result['aliases']); | ||||
$this->assertSame('john.doe@kolab.org', $result['aliases'][0]); | $this->assertSame('john.doe@kolab.org', $result['aliases'][0]); | ||||
$this->assertTrue(is_array($result['settings'])); | $this->assertTrue(is_array($result['settings'])); | ||||
$this->assertSame('US', $result['settings']['country']); | $this->assertSame('US', $result['settings']['country']); | ||||
$this->assertSame('USD', $result['settings']['currency']); | $this->assertSame('USD', $result['settings']['currency']); | ||||
// TODO: Test all settings | |||||
$this->assertTrue(is_array($result['accounts'])); | $this->assertTrue(is_array($result['accounts'])); | ||||
$this->assertTrue(is_array($result['wallets'])); | $this->assertTrue(is_array($result['wallets'])); | ||||
$this->assertCount(0, $result['accounts']); | $this->assertCount(0, $result['accounts']); | ||||
$this->assertCount(1, $result['wallets']); | $this->assertCount(1, $result['wallets']); | ||||
$this->assertSame($wallet->id, $result['wallet']['id']); | $this->assertSame($wallet->id, $result['wallet']['id']); | ||||
$this->assertArrayNotHasKey('discount', $result['wallet']); | $this->assertArrayNotHasKey('discount', $result['wallet']); | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$package_domain = \App\Package::where('title', 'domain-hosting')->first(); | $package_domain = \App\Package::where('title', 'domain-hosting')->first(); | ||||
$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', | |||||
'aliases' => ['useralias1@kolab.org', 'useralias2@kolab.org'], | 'aliases' => ['useralias1@kolab.org', 'useralias2@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 23 Lines | public function testStore(): void | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame("User created successfully.", $json['message']); | $this->assertSame("User created successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$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')); | |||||
$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('useralias1@kolab.org', $aliases[0]->alias); | ||||
$this->assertSame('useralias2@kolab.org', $aliases[1]->alias); | $this->assertSame('useralias2@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(); | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | public function testUpdate(): void | ||||
$this->assertSame('The currency must be 3 characters.', $json['errors']['currency'][0]); | $this->assertSame('The currency must be 3 characters.', $json['errors']['currency'][0]); | ||||
// Test full profile update including password | // Test full profile update including password | ||||
$post = [ | $post = [ | ||||
'password' => 'simple', | 'password' => 'simple', | ||||
'password_confirmation' => 'simple', | 'password_confirmation' => 'simple', | ||||
'first_name' => 'John2', | 'first_name' => 'John2', | ||||
'last_name' => 'Doe2', | 'last_name' => 'Doe2', | ||||
'organization' => 'TestOrg', | |||||
'phone' => '+123 123 123', | 'phone' => '+123 123 123', | ||||
'external_email' => 'external@gmail.com', | 'external_email' => 'external@gmail.com', | ||||
'billing_address' => 'billing', | 'billing_address' => 'billing', | ||||
'country' => 'CH', | 'country' => 'CH', | ||||
'currency' => 'CHF', | 'currency' => 'CHF', | ||||
'aliases' => ['useralias1@' . \config('app.domain'), 'useralias2@' . \config('app.domain')] | 'aliases' => ['useralias1@' . \config('app.domain'), 'useralias2@' . \config('app.domain')] | ||||
]; | ]; | ||||
Show All 14 Lines | public function testUpdate(): void | ||||
$this->assertCount(2, $aliases); | $this->assertCount(2, $aliases); | ||||
$this->assertSame('useralias1@' . \config('app.domain'), $aliases[0]->alias); | $this->assertSame('useralias1@' . \config('app.domain'), $aliases[0]->alias); | ||||
$this->assertSame('useralias2@' . \config('app.domain'), $aliases[1]->alias); | $this->assertSame('useralias2@' . \config('app.domain'), $aliases[1]->alias); | ||||
// Test unsetting values | // Test unsetting values | ||||
$post = [ | $post = [ | ||||
'first_name' => '', | 'first_name' => '', | ||||
'last_name' => '', | 'last_name' => '', | ||||
'organization' => '', | |||||
'phone' => '', | 'phone' => '', | ||||
'external_email' => '', | 'external_email' => '', | ||||
'billing_address' => '', | 'billing_address' => '', | ||||
'country' => '', | 'country' => '', | ||||
'currency' => '', | 'currency' => '', | ||||
'aliases' => ['useralias2@' . \config('app.domain')] | 'aliases' => ['useralias2@' . \config('app.domain')] | ||||
]; | ]; | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |