Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/GroupsTest.php
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertCount(1, $json); | $this->assertCount(1, $json); | ||||
$this->assertSame($group->email, $json[0]['email']); | $this->assertSame($group->email, $json[0]['email']); | ||||
} | } | ||||
/** | /** | ||||
* Test group config update (POST /api/v4/groups/<group>/config) | |||||
*/ | |||||
public function testSetConfig(): void | |||||
{ | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$group = $this->getTestGroup('group-test@kolab.org'); | |||||
$group->assignToWallet($john->wallets->first()); | |||||
// Test unknown group id | |||||
$post = ['sender_policy' => []]; | |||||
$response = $this->actingAs($john)->post("/api/v4/groups/123/config", $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(404); | |||||
// Test access by user not being a wallet controller | |||||
$post = ['sender_policy' => []]; | |||||
$response = $this->actingAs($jack)->post("/api/v4/groups/{$group->id}/config", $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(403); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertSame("Access denied", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
// Test some invalid data | |||||
$post = ['test' => 1]; | |||||
$response = $this->actingAs($john)->post("/api/v4/groups/{$group->id}/config", $post); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(2, $json); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertSame('The requested configuration parameter is not supported.', $json['errors']['test']); | |||||
$group->refresh(); | |||||
$this->assertNull($group->getSetting('test')); | |||||
$this->assertNull($group->getSetting('sender_policy')); | |||||
// Test some valid data | |||||
$post = ['sender_policy' => ['domain.com']]; | |||||
$response = $this->actingAs($john)->post("/api/v4/groups/{$group->id}/config", $post); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame('Distribution list settings updated successfully.', $json['message']); | |||||
$this->assertSame(['sender_policy' => $post['sender_policy']], $group->fresh()->getConfig()); | |||||
// Test input validation | |||||
$post = ['sender_policy' => [5]]; | |||||
$response = $this->actingAs($john)->post("/api/v4/groups/{$group->id}/config", $post); | |||||
$response->assertStatus(422); | |||||
$json = $response->json(); | |||||
$this->assertCount(2, $json); | |||||
$this->assertSame('error', $json['status']); | |||||
$this->assertCount(1, $json['errors']); | |||||
$this->assertSame( | |||||
'The entry format is invalid. Expected an email, domain, or part of it.', | |||||
$json['errors']['sender_policy'][0] | |||||
); | |||||
$this->assertSame(['sender_policy' => ['domain.com']], $group->fresh()->getConfig()); | |||||
} | |||||
/** | |||||
* Test fetching group data/profile (GET /api/v4/groups/<group-id>) | * Test fetching group data/profile (GET /api/v4/groups/<group-id>) | ||||
*/ | */ | ||||
public function testShow(): void | public function testShow(): 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'); | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$group = $this->getTestGroup('group-test@kolab.org'); | $group = $this->getTestGroup('group-test@kolab.org'); | ||||
$group->assignToWallet($john->wallets->first()); | $group->assignToWallet($john->wallets->first()); | ||||
$group->setSetting('sender_policy', '["test"]'); | |||||
// Test unauthorized access to a profile of other user | // Test unauthorized access to a profile of other user | ||||
$response = $this->get("/api/v4/groups/{$group->id}"); | $response = $this->get("/api/v4/groups/{$group->id}"); | ||||
$response->assertStatus(401); | $response->assertStatus(401); | ||||
// Test unauthorized access to a group of another user | // Test unauthorized access to a group of another user | ||||
$response = $this->actingAs($jack)->get("/api/v4/groups/{$group->id}"); | $response = $this->actingAs($jack)->get("/api/v4/groups/{$group->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
Show All 11 Lines | public function testShow(): void | ||||
$this->assertSame($group->id, $json['id']); | $this->assertSame($group->id, $json['id']); | ||||
$this->assertSame($group->email, $json['email']); | $this->assertSame($group->email, $json['email']); | ||||
$this->assertSame($group->members, $json['members']); | $this->assertSame($group->members, $json['members']); | ||||
$this->assertTrue(!empty($json['statusInfo'])); | $this->assertTrue(!empty($json['statusInfo'])); | ||||
$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->assertSame(['sender_policy' => ['test']], $json['config']); | |||||
} | } | ||||
/** | /** | ||||
* Test fetching group status (GET /api/v4/groups/<group-id>/status) | * Test fetching group status (GET /api/v4/groups/<group-id>/status) | ||||
* and forcing setup process update (?refresh=1) | * and forcing setup process update (?refresh=1) | ||||
*/ | */ | ||||
public function testStatus(): void | public function testStatus(): void | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 327 Lines • Show Last 20 Lines |