From 33d5d5e24f9cd31f77477d65bdbc0ebaacf6109b Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 28 May 2024 15:21:13 +0100 Subject: [PATCH] Added tests Signed-off-by: snipe --- tests/Feature/Api/Groups/GroupStoreTest.php | 40 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Api/Groups/GroupStoreTest.php b/tests/Feature/Api/Groups/GroupStoreTest.php index 31a69fb469..65d673e7b0 100644 --- a/tests/Feature/Api/Groups/GroupStoreTest.php +++ b/tests/Feature/Api/Groups/GroupStoreTest.php @@ -15,7 +15,7 @@ class GroupStoreTest extends TestCase ->assertForbidden(); } - public function testCanStoreGroup() + public function testCanStoreGroupWithPermissionsPassed() { $this->actingAsForApi(User::factory()->superuser()->create()) ->postJson(route('api.groups.store'), [ @@ -35,4 +35,42 @@ class GroupStoreTest extends TestCase $this->assertEquals('1', $group->decodePermissions()['import']); $this->assertEquals('0', $group->decodePermissions()['reports.view']); } + + public function testStoringGroupWithoutPermissionPassed() + { + $superuser = User::factory()->superuser()->create(); + $this->actingAsForApi($superuser) + ->postJson(route('api.groups.store'), [ + 'name' => 'My Awesome Group' + ]) + ->assertOk(); + + $group = Group::where('name', 'My Awesome Group')->first(); + + $this->assertNotNull($group); + + $this->actingAsForApi($superuser) + ->getJson(route('api.groups.show', ['group' => $group])) + ->assertOk(); + + } + + public function testStoringGroupWithInvalidPermissionDropsBadPermission() + { + $this->actingAsForApi(User::factory()->superuser()->create()) + ->postJson(route('api.groups.store'), [ + 'name' => 'My Awesome Group', + 'permissions' => [ + 'admin' => '1', + 'snipe_is_awesome' => '1', + ], + ]) + ->assertOk(); + + $group = Group::where('name', 'My Awesome Group')->first(); + $this->assertNotNull($group); + $this->assertEquals('1', $group->decodePermissions()['admin']); + $this->assertNotContains('snipe_is_awesome', $group->decodePermissions()); + + } }