Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show All 39 Lines | public function setUp(): void | ||||
$this->deleteTestResource('resource-test@kolabnow.com'); | $this->deleteTestResource('resource-test@kolabnow.com'); | ||||
Sku::where('title', 'test')->delete(); | Sku::where('title', 'test')->delete(); | ||||
$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->settings()->whereIn('key', ['greylist_enabled', 'guam_enabled'])->delete(); | |||||
$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 | ||||
Show All 14 Lines | public function tearDown(): void | ||||
$this->deleteTestResource('resource-test@kolabnow.com'); | $this->deleteTestResource('resource-test@kolabnow.com'); | ||||
Sku::where('title', 'test')->delete(); | Sku::where('title', 'test')->delete(); | ||||
$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->settings()->whereIn('key', ['greylist_enabled'])->delete(); | $user->settings()->whereIn('key', ['greylist_enabled', 'guam_enabled'])->delete(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test user deleting (DELETE /api/v4/users/<id>) | * Test user deleting (DELETE /api/v4/users/<id>) | ||||
▲ Show 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | public function testShow(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertEquals($userA->id, $json['id']); | $this->assertEquals($userA->id, $json['id']); | ||||
$this->assertEquals($userA->email, $json['email']); | $this->assertEquals($userA->email, $json['email']); | ||||
$this->assertTrue(is_array($json['statusInfo'])); | $this->assertTrue(is_array($json['statusInfo'])); | ||||
$this->assertTrue(is_array($json['settings'])); | $this->assertTrue(is_array($json['settings'])); | ||||
$this->assertTrue($json['config']['greylist_enabled']); | $this->assertTrue($json['config']['greylist_enabled']); | ||||
$this->assertFalse($json['config']['guam_enabled']); | |||||
$this->assertSame([], $json['skus']); | $this->assertSame([], $json['skus']); | ||||
$this->assertSame([], $json['aliases']); | $this->assertSame([], $json['aliases']); | ||||
// Values below are tested by Unit tests | // Values below are tested by Unit tests | ||||
$this->assertArrayHasKey('isDeleted', $json); | $this->assertArrayHasKey('isDeleted', $json); | ||||
$this->assertArrayHasKey('isDegraded', $json); | $this->assertArrayHasKey('isDegraded', $json); | ||||
$this->assertArrayHasKey('isAccountDegraded', $json); | $this->assertArrayHasKey('isAccountDegraded', $json); | ||||
$this->assertArrayHasKey('isSuspended', $json); | $this->assertArrayHasKey('isSuspended', $json); | ||||
$this->assertArrayHasKey('isActive', $json); | $this->assertArrayHasKey('isActive', $json); | ||||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | class UsersTest extends TestCase | ||||
* Test user config update (POST /api/v4/users/<user>/config) | * Test user config update (POST /api/v4/users/<user>/config) | ||||
*/ | */ | ||||
public function testSetConfig(): void | public function testSetConfig(): 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'); | ||||
$john->setSetting('greylist_enabled', null); | $john->setSetting('greylist_enabled', null); | ||||
$john->setSetting('guam_enabled', null); | |||||
$john->setSetting('password_policy', null); | $john->setSetting('password_policy', null); | ||||
$john->setSetting('max_password_age', null); | $john->setSetting('max_password_age', null); | ||||
// Test unknown user id | // Test unknown user id | ||||
$post = ['greylist_enabled' => 1]; | $post = ['greylist_enabled' => 1]; | ||||
$response = $this->actingAs($john)->post("/api/v4/users/123/config", $post); | $response = $this->actingAs($john)->post("/api/v4/users/123/config", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
Show All 23 Lines | public function testSetConfig(): void | ||||
$this->assertSame("The requested configuration parameter is not supported.", $json['errors']['grey']); | $this->assertSame("The requested configuration parameter is not supported.", $json['errors']['grey']); | ||||
$this->assertSame("Minimum password length cannot be less than 6.", $json['errors']['password_policy']); | $this->assertSame("Minimum password length cannot be less than 6.", $json['errors']['password_policy']); | ||||
$this->assertNull($john->fresh()->getSetting('greylist_enabled')); | $this->assertNull($john->fresh()->getSetting('greylist_enabled')); | ||||
// Test some valid data | // Test some valid data | ||||
$post = [ | $post = [ | ||||
'greylist_enabled' => 1, | 'greylist_enabled' => 1, | ||||
'guam_enabled' => 1, | |||||
'password_policy' => 'min:10,max:255,upper,lower,digit,special', | 'password_policy' => 'min:10,max:255,upper,lower,digit,special', | ||||
'max_password_age' => 6, | 'max_password_age' => 6, | ||||
]; | ]; | ||||
$response = $this->actingAs($john)->post("/api/v4/users/{$john->id}/config", $post); | $response = $this->actingAs($john)->post("/api/v4/users/{$john->id}/config", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('User settings updated successfully.', $json['message']); | $this->assertSame('User settings updated successfully.', $json['message']); | ||||
$this->assertSame('true', $john->getSetting('greylist_enabled')); | $this->assertSame('true', $john->getSetting('greylist_enabled')); | ||||
$this->assertSame('true', $john->getSetting('guam_enabled')); | |||||
$this->assertSame('min:10,max:255,upper,lower,digit,special', $john->getSetting('password_policy')); | $this->assertSame('min:10,max:255,upper,lower,digit,special', $john->getSetting('password_policy')); | ||||
$this->assertSame('6', $john->getSetting('max_password_age')); | $this->assertSame('6', $john->getSetting('max_password_age')); | ||||
// Test some valid data, acting as another account controller | // Test some valid data, acting as another account controller | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$post = ['greylist_enabled' => 0, 'password_policy' => 'min:10,max:255,upper,last:1']; | $post = ['greylist_enabled' => 0, 'guam_enabled' => 0, 'password_policy' => 'min:10,max:255,upper,last:1']; | ||||
$response = $this->actingAs($ned)->post("/api/v4/users/{$john->id}/config", $post); | $response = $this->actingAs($ned)->post("/api/v4/users/{$john->id}/config", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('User settings updated successfully.', $json['message']); | $this->assertSame('User settings updated successfully.', $json['message']); | ||||
$this->assertSame('false', $john->fresh()->getSetting('greylist_enabled')); | $this->assertSame('false', $john->fresh()->getSetting('greylist_enabled')); | ||||
$this->assertSame(null, $john->fresh()->getSetting('guam_enabled')); | |||||
$this->assertSame('min:10,max:255,upper,last:1', $john->fresh()->getSetting('password_policy')); | $this->assertSame('min:10,max:255,upper,last:1', $john->fresh()->getSetting('password_policy')); | ||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 906 Lines • Show Last 20 Lines |