Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller; | namespace Tests\Feature\Controller; | ||||
use App\Discount; | use App\Discount; | ||||
use App\Domain; | use App\Domain; | ||||
use App\Http\Controllers\API\V4\UsersController; | use App\Http\Controllers\API\V4\UsersController; | ||||
use App\Package; | use App\Package; | ||||
use App\Policy\Greylist; | |||||
use App\Sku; | use App\Sku; | ||||
use App\User; | use App\User; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Carbon\Carbon; | use Carbon\Carbon; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Illuminate\Support\Str; | use Illuminate\Support\Str; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
▲ Show 20 Lines • Show All 44 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', ['greylist_enabled'])->delete(); | Greylist\Setting::where('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('greylist_enabled', null); | Greylist\Setting::where('key', 'greylist_enabled')->delete(); | ||||
// 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('greylist_enabled')); | $this->assertTrue($john->getConfig()['greylisting']); | ||||
// 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('greylist_enabled')); | $this->assertTrue($john->getConfig()['greylisting']); | ||||
// 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('greylist_enabled')); | $this->assertFalse($john->getConfig()['greylisting']); | ||||
} | } | ||||
/** | /** | ||||
* 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 |