Skip to content

Commit 5386588

Browse files
committed
update mocks and tests
1 parent cfd0794 commit 5386588

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

internal/handlers/category_handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ func TestCategoryHandler_UpdateCategory(t *testing.T) {
411411
// Moved setup inside t.Run for isolation
412412
mockCategoryRepo, mockUserRepo, _, _, router := setupCategoryTest(t)
413413

414-
// Mock middleware user check
415-
if tc.expectedStatus != http.StatusUnauthorized || tc.expectedBody == `{"error":"user associated with token not found"}` {
414+
// Mock middleware user check only if the UUID is valid AND we are not testing the "No Auth Token" case directly
415+
if tc.categoryID != "not-a-uuid" && tc.expectedBody != `{"error":"authorization header required"}` {
416416
mockUserRepo.On("FindByID", mock.Anything, testUserID).Return(tc.mockUserReturn, tc.mockUserErr).Once()
417417
}
418418

@@ -524,8 +524,8 @@ func TestCategoryHandler_DeleteCategory(t *testing.T) {
524524
// Moved setup inside t.Run for isolation
525525
mockCategoryRepo, mockUserRepo, _, _, router := setupCategoryTest(t)
526526

527-
// Mock middleware user check
528-
if tc.expectedStatus != http.StatusUnauthorized || tc.expectedBody == `{"error":"user associated with token not found"}` {
527+
// Mock middleware user check only if the UUID is valid AND we are not testing the "No Auth Token" case directly
528+
if tc.categoryID != "not-a-uuid" && tc.expectedBody != `{"error":"authorization header required"}` {
529529
mockUserRepo.On("FindByID", mock.Anything, testUserID).Return(tc.mockUserReturn, tc.mockUserErr).Once()
530530
}
531531

internal/handlers/product_handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ func TestProductHandler_UpdateProduct(t *testing.T) {
424424
// Moved setup inside t.Run for isolation
425425
mockProductRepo, mockUserRepo, _, _, router := setupProductTest(t)
426426

427-
// Mock middleware user check
428-
if tc.expectedStatus != http.StatusUnauthorized || tc.expectedBody == `{"error":"user associated with token not found"}` {
427+
// Mock middleware user check only if the UUID is valid AND we are not testing the "No Auth Token" case directly
428+
if tc.productID != "not-a-uuid" && tc.expectedBody != `{"error":"authorization header required"}` {
429429
mockUserRepo.On("FindByID", mock.Anything, testUserID).Return(tc.mockUserReturn, tc.mockUserErr).Once()
430430
}
431431

@@ -538,8 +538,8 @@ func TestProductHandler_DeleteProduct(t *testing.T) {
538538
// Moved setup inside t.Run for isolation
539539
mockProductRepo, mockUserRepo, _, _, router := setupProductTest(t)
540540

541-
// Mock middleware user check
542-
if tc.expectedStatus != http.StatusUnauthorized || tc.expectedBody == `{"error":"user associated with token not found"}` {
541+
// Mock middleware user check only if the UUID is valid AND we are not testing the "No Auth Token" case directly
542+
if tc.productID != "not-a-uuid" && tc.expectedBody != `{"error":"authorization header required"}` {
543543
mockUserRepo.On("FindByID", mock.Anything, testUserID).Return(tc.mockUserReturn, tc.mockUserErr).Once()
544544
}
545545

0 commit comments

Comments
 (0)