Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | public function tearDown(): void | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | $this->deleteTestGroup('group-test@kolabnow.com'); | ||||
$this->deleteTestGroup('group-test@kolab.org'); | $this->deleteTestGroup('group-test@kolab.org'); | ||||
$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', ['greylisting'])->delete(); | $user->settings()->whereIn('key', ['greylist_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 392 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('greylisting', null); | $john->setSetting('greylist_enabled', null); | ||||
// Test unknown user id | // Test unknown user id | ||||
$post = ['greylisting' => 1]; | $post = ['greylisting' => 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(); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
Show All 15 Lines | public function testSetConfig(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$this->assertCount(1, $json['errors']); | $this->assertCount(1, $json['errors']); | ||||
$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->assertNull($john->fresh()->getSetting('greylisting')); | $this->assertNull($john->fresh()->getSetting('greylist_enabled')); | ||||
// Test some valid data | // Test some valid data | ||||
$post = ['greylisting' => 1]; | $post = ['greylisting' => 1]; | ||||
$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->fresh()->getSetting('greylisting')); | $this->assertSame('true', $john->fresh()->getSetting('greylist_enabled')); | ||||
// Test some valid data | // Test some valid data | ||||
$post = ['greylisting' => 0]; | $post = ['greylisting' => 0]; | ||||
$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('false', $john->fresh()->getSetting('greylisting')); | $this->assertSame('false', $john->fresh()->getSetting('greylist_enabled')); | ||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
▲ Show 20 Lines • Show All 813 Lines • Show Last 20 Lines |