From 607be5b7f9aa6ccebf675aca5213642e57607387 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 20 Dec 2024 09:11:13 -0500 Subject: [PATCH 1/3] Rename tests for Issue #72 --- API/tests/Feature/GroceryItemControllerTest.php | 16 ++++++++-------- .../Feature/ListPermissionsControllerTest.php | 16 ++++++++++------ API/tests/Feature/ShoppingListControllerTest.php | 16 ++++++++-------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/API/tests/Feature/GroceryItemControllerTest.php b/API/tests/Feature/GroceryItemControllerTest.php index ccac5d4..a7697fa 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 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 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 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 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 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 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 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 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..6970039 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 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 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 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 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 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 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..0372bab 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 create_validShoppingListTitle_savesShoppingListTitleToDatabase() { // Create an authenticated user $user = User::factory()->create(); @@ -44,7 +44,7 @@ public function testCreateShoppingList() } - public function testGetUserShoppingLists() + public function 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 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 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 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 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 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 delete_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); From bd4822590d54ca3d5d304c652125b73b0b68734b Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 20 Dec 2024 09:37:16 -0500 Subject: [PATCH 2/3] Update create valid test for ShoppingListController --- API/tests/Feature/ShoppingListControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/tests/Feature/ShoppingListControllerTest.php b/API/tests/Feature/ShoppingListControllerTest.php index 0372bab..69ff0ad 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 create_validShoppingListTitle_savesShoppingListTitleToDatabase() + public function create_validShoppingListTitle_savesShoppingListToDatabase() { // Create an authenticated user $user = User::factory()->create(); From 495744fa44d65863cb21607f40d1474f18848d18 Mon Sep 17 00:00:00 2001 From: Cameron Green Date: Fri, 20 Dec 2024 09:41:52 -0500 Subject: [PATCH 3/3] Add prefix test_ to all existing tests so Laravel knows to run them --- API/tests/Feature/GroceryItemControllerTest.php | 16 ++++++++-------- .../Feature/ListPermissionsControllerTest.php | 12 ++++++------ API/tests/Feature/ShoppingListControllerTest.php | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/API/tests/Feature/GroceryItemControllerTest.php b/API/tests/Feature/GroceryItemControllerTest.php index a7697fa..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 store_validGroceryItem_savesItemToDatabase() + 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 store_validGroceryItem_savesItemToDatabase() ]); } - public function store_unauthorizedUser_returns403Error() + public function test_store_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -51,7 +51,7 @@ public function store_unauthorizedUser_returns403Error() ->assertStatus(403); } - public function show_validShoppingListId_returnsGroceryItems() + 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 show_validShoppingListId_returnsGroceryItems() ]); } - public function show_unauthorizedUser_returns403Error() + public function test_show_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -84,7 +84,7 @@ public function show_unauthorizedUser_returns403Error() ->assertStatus(403); } - public function update_validGroceryItem_savesItemToDatabase() + 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 update_validGroceryItem_savesItemToDatabase() ]); } - public function update_unauthorizedUser_returns403Error() + public function test_update_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -130,7 +130,7 @@ public function update_unauthorizedUser_returns403Error() ->assertStatus(403); } - public function delete_validGroceryItemId_deletesItemInDatabase() + 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 delete_validGroceryItemId_deletesItemInDatabase() $this->assertDatabaseMissing('grocery_items', ['item_id' => $groceryItem->item_id]); } - public function delete_unauthorizedUser_returns403Error() + 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 6970039..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 createShareLink_validListId_returnsNewShareLink(): void + public function test_createShareLink_validListId_returnsNewShareLink(): void { $user = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -49,7 +49,7 @@ public function createShareLink_validListId_returnsNewShareLink(): void $this->assertNotNull($sharedLink->expires_at); } - public function verifyShareLinkAndSavePerms_validShareLink_savesPermissionsInDatabase(): void + public function test_verifyShareLinkAndSavePerms_validShareLink_savesPermissionsInDatabase(): void { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -80,7 +80,7 @@ public function verifyShareLinkAndSavePerms_validShareLink_savesPermissionsInDat 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 createShareLink_sharedUserCannotCreateNewShareLink_returns403Error() { + public function test_createShareLink_sharedUserCannotCreateNewShareLink_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -112,7 +112,7 @@ public function createShareLink_sharedUserCannotCreateNewShareLink_returns403Err ]); } - public function verifyShareLinkAndSavePerms_updateAllowedButNotDelete_returns403ErrorForDeleteAttempt() { + public function test_verifyShareLinkAndSavePerms_updateAllowedButNotDelete_returns403ErrorForDeleteAttempt() { $user = User::factory()->create(); $otherUser = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -182,7 +182,7 @@ public function verifyShareLinkAndSavePerms_updateAllowedButNotDelete_returns403 ]); } - public function verifyShareLinkAndSavePerms_deleteAllowedButNotUpdate_returns403ErrorForUpdateAttempt() { + public function test_verifyShareLinkAndSavePerms_deleteAllowedButNotUpdate_returns403ErrorForUpdateAttempt() { $user = User::factory()->create(); $otherUser = User::factory()->create(); $list = ShoppingList::factory()->create([ @@ -256,7 +256,7 @@ public function verifyShareLinkAndSavePerms_deleteAllowedButNotUpdate_returns403 ]); } - public function createShareLink_unauthorizedUser_returns403Error(): 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 69ff0ad..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 create_validShoppingListTitle_savesShoppingListToDatabase() + public function test_create_validShoppingListTitle_savesShoppingListToDatabase() { // Create an authenticated user $user = User::factory()->create(); @@ -44,7 +44,7 @@ public function create_validShoppingListTitle_savesShoppingListToDatabase() } - public function getUserShoppingLists_userHasShoppingList_returnsOwnedShoppingLists() + public function test_getUserShoppingLists_userHasShoppingList_returnsOwnedShoppingLists() { // Create an authenticated user and a shopping list $user = User::factory()->create(); @@ -67,7 +67,7 @@ public function getUserShoppingLists_userHasShoppingList_returnsOwnedShoppingLis ]); } - public function get_validShoppingListId_returnsShoppingList() + public function test_get_validShoppingListId_returnsShoppingList() { // Create an authenticated user and a shopping list $user = User::factory()->create(); @@ -90,7 +90,7 @@ public function get_validShoppingListId_returnsShoppingList() ]); } - public function get_unauthorizedUser_returns403Error() + public function test_get_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -101,7 +101,7 @@ public function get_unauthorizedUser_returns403Error() ->assertStatus(403); } - public function update_validShoppingListId_updatesShoppingListInDatabase() + 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 update_validShoppingListId_updatesShoppingListInDatabase() ]); } - public function update_unauthorizedUser_returns403Error() + public function test_update_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create(); @@ -132,7 +132,7 @@ public function update_unauthorizedUser_returns403Error() ->assertStatus(403); } - public function delete_validShoppingListId_deletesShoppingListInDatabase() + public function test_delete_validShoppingListId_deletesShoppingListInDatabase() { // Create an authenticated user and a shopping list $user = User::factory()->create(); @@ -155,7 +155,7 @@ public function delete_validShoppingListId_deletesShoppingListInDatabase() ]); } - public function delete_unauthorizedUser_returns403Error() + public function test_delete_unauthorizedUser_returns403Error() { $user = User::factory()->create(); $otherUser = User::factory()->create();