Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 239 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(is_array($json['aliases'])); | $this->assertTrue(is_array($json['aliases'])); | ||||
$this->assertTrue($json['config']['greylisting']); | $this->assertTrue($json['config']['greylist_enabled']); | ||||
$this->assertSame([], $json['skus']); | $this->assertSame([], $json['skus']); | ||||
// Values below are tested by Unit tests | // Values below are tested by Unit tests | ||||
$this->assertArrayHasKey('isDeleted', $json); | $this->assertArrayHasKey('isDeleted', $json); | ||||
$this->assertArrayHasKey('isSuspended', $json); | $this->assertArrayHasKey('isSuspended', $json); | ||||
$this->assertArrayHasKey('isActive', $json); | $this->assertArrayHasKey('isActive', $json); | ||||
$this->assertArrayHasKey('isLdapReady', $json); | $this->assertArrayHasKey('isLdapReady', $json); | ||||
$this->assertArrayHasKey('isImapReady', $json); | $this->assertArrayHasKey('isImapReady', $json); | ||||
▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | class UsersTest extends TestCase | ||||
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); | ||||
// Test unknown user id | // Test unknown user id | ||||
$post = ['greylisting' => 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(); | ||||
$response->assertStatus(404); | $response->assertStatus(404); | ||||
// Test access by user not being a wallet controller | // Test access by user not being a wallet controller | ||||
$post = ['greylisting' => 1]; | $post = ['greylist_enabled' => 1]; | ||||
$response = $this->actingAs($jack)->post("/api/v4/users/{$john->id}/config", $post); | $response = $this->actingAs($jack)->post("/api/v4/users/{$john->id}/config", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertSame("Access denied", $json['message']); | $this->assertSame("Access denied", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
// Test some invalid data | // Test some invalid data | ||||
$post = ['grey' => 1]; | $post = ['grey' => 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(422); | $response->assertStatus(422); | ||||
$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->assertNull($john->fresh()->getSetting('greylist_enabled')); | ||||
// Test some valid data | // Test some valid data | ||||
$post = ['greylisting' => 1]; | $post = ['greylist_enabled' => 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->assertSame('true', $john->fresh()->getSetting('greylist_enabled')); | ||||
// Test some valid data | // Test some valid data | ||||
$post = ['greylisting' => 0]; | $post = ['greylist_enabled' => 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']); | ||||
▲ Show 20 Lines • Show All 823 Lines • Show Last 20 Lines |