diff --git a/API/tests/Feature/GroceryItemControllerTest.php b/API/tests/Feature/GroceryItemControllerTest.php index ccac5d4..c3b5b91 100644 --- a/API/tests/Feature/GroceryItemControllerTest.php +++ b/API/tests/Feature/GroceryItemControllerTest.php @@ -12,7 +12,7 @@ class GroceryItemControllerTest extends TestCase { use RefreshDatabase; - public function testStoreGroceryItem() + public function test_store_validGroceryItem_savesItemToDatabase() { $user = User::factory()->create(); $shoppingList = ShoppingList::factory()->create(['user_id' => $user->user_id]); @@ -35,7 +35,7 @@ public function testStoreGroceryItem() ]); } - public function testStoreGroceryItemUnauthorized() + public function test_store_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -51,7 +51,7 @@ public function testStoreGroceryItemUnauthorized() ->assertStatus(403); } - public function testShowGroceryItems() + public function test_show_validShoppingListId_returnsGroceryItems() { $user = User::factory()->create(); $shoppingList = ShoppingList::factory()->create(['user_id' => $user->user_id]); @@ -73,7 +73,7 @@ public function testShowGroceryItems() ]); } - public function testShowGroceryItemsUnauthorized() + public function test_show_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -84,7 +84,7 @@ public function testShowGroceryItemsUnauthorized() ->assertStatus(403); } - public function testUpdateGroceryItem() + public function test_update_validGroceryItem_savesItemToDatabase() { $user = User::factory()->create(); $shoppingList = ShoppingList::factory()->create(['user_id' => $user->user_id]); @@ -111,7 +111,7 @@ public function testUpdateGroceryItem() ]); } - public function testUpdateGroceryItemUnauthorized() + public function test_update_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -130,7 +130,7 @@ public function testUpdateGroceryItemUnauthorized() ->assertStatus(403); } - public function testDeleteGroceryItem() + public function test_delete_validGroceryItemId_deletesItemInDatabase() { $user = User::factory()->create(); $shoppingList = ShoppingList::factory()->create(['user_id' => $user->user_id]); @@ -144,7 +144,7 @@ public function testDeleteGroceryItem() $this->assertDatabaseMissing('grocery_items', ['item_id' => $groceryItem->item_id]); } - public function testDeleteGroceryItemUnauthorized() + public function test_delete_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); diff --git a/API/tests/Feature/ListPermissionsControllerTest.php b/API/tests/Feature/ListPermissionsControllerTest.php index c3daec3..d47ca52 100644 --- a/API/tests/Feature/ListPermissionsControllerTest.php +++ b/API/tests/Feature/ListPermissionsControllerTest.php @@ -20,7 +20,7 @@ protected function setUp(): void parent::setUp(); } - public function testCreateShareLink(): void + public function test_createShareLink_validListId_returnsNewShareLink(): void { $user = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -49,7 +49,7 @@ public function testCreateShareLink(): void $this->assertNotNull($sharedLink->expires_at); } - public function testVerifyShareLinkValid(): void + public function test_verifyShareLinkAndSavePerms_validShareLink_savesPermissionsInDatabase(): void { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -76,7 +76,11 @@ public function testVerifyShareLinkValid(): void ]); } - public function testCreateShareLinkChainUnauthorized() { + /* Purpose: User A shares list with User B, but User B shouldn't be able to share with + another user because that isn't okay to User A (only User A should be able to create + share links for their lists since they own those lists) + */ + public function test_createShareLink_sharedUserCannotCreateNewShareLink_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -108,7 +112,7 @@ public function testCreateShareLinkChainUnauthorized() { ]); } - public function testVerifyShareLinkUpdateAllowedButNotDelete() { + public function test_verifyShareLinkAndSavePerms_updateAllowedButNotDelete_returns403ErrorForDeleteAttempt() { $user = User::factory()->create(); $otherUser = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -178,7 +182,7 @@ public function testVerifyShareLinkUpdateAllowedButNotDelete() { ]); } - public function testVerifyShareLinkDeleteAllowedButNotUpdate() { + public function test_verifyShareLinkAndSavePerms_deleteAllowedButNotUpdate_returns403ErrorForUpdateAttempt() { $user = User::factory()->create(); $otherUser = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -252,7 +256,7 @@ public function testVerifyShareLinkDeleteAllowedButNotUpdate() { ]); } - public function testUnauthorizedUserCannotCreateShareLink(): void + public function test_createShareLink_unauthorizedUser_returns403Error(): void { $owner = User::factory()->create(); $unauthorizedUser = User::factory()->create(); diff --git a/API/tests/Feature/ShoppingListControllerTest.php b/API/tests/Feature/ShoppingListControllerTest.php index ad1a00c..35c439e 100644 --- a/API/tests/Feature/ShoppingListControllerTest.php +++ b/API/tests/Feature/ShoppingListControllerTest.php @@ -15,7 +15,7 @@ class ShoppingListControllerTest extends TestCase // Runs our migrations to set up the in-memory database with all the proper tables use RefreshDatabase; - public function testCreateShoppingList() + public function test_create_validShoppingListTitle_savesShoppingListToDatabase() { // Create an authenticated user $user = User::factory()->create(); @@ -44,7 +44,7 @@ public function testCreateShoppingList() } - public function testGetUserShoppingLists() + public function test_getUserShoppingLists_userHasShoppingList_returnsOwnedShoppingLists() { // Create an authenticated user and a shopping list $user = User::factory()->create(); @@ -67,7 +67,7 @@ public function testGetUserShoppingLists() ]); } - public function testGetSpecificShoppingList() + public function test_get_validShoppingListId_returnsShoppingList() { // Create an authenticated user and a shopping list $user = User::factory()->create(); @@ -90,7 +90,7 @@ public function testGetSpecificShoppingList() ]); } - public function testGetSpecificShoppingListUnauthorized() + public function test_get_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -101,7 +101,7 @@ public function testGetSpecificShoppingListUnauthorized() ->assertStatus(403); } - public function testUpdateShoppingList() + public function test_update_validShoppingListId_updatesShoppingListInDatabase() { $user = User::factory()->create(); $list = ShoppingList::factory()->create(['user_id' => $user->user_id, 'name' => 'foo']); @@ -119,7 +119,7 @@ public function testUpdateShoppingList() ]); } - public function testUpdateShoppingListUnauthorized() + public function test_update_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -132,7 +132,7 @@ public function testUpdateShoppingListUnauthorized() ->assertStatus(403); } - public function testDeleteShoppingList() + public function test_delete_validShoppingListId_deletesShoppingListInDatabase() { // Create an authenticated user and a shopping list $user = User::factory()->create(); @@ -155,7 +155,7 @@ public function testDeleteShoppingList() ]); } - public function testDeleteShoppingListUnauthorized() + public function test_delete_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create();