From 62fb62f1338c4d9a8086fb8fee5e5c0d1e86cd7a Mon Sep 17 00:00:00 2001 From: AbdulWahab3181 Date: Wed, 26 Jun 2024 18:15:27 +0500 Subject: [PATCH] Refactored TestGetTribesByAppUrl UT --- handlers/tribes_test.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/handlers/tribes_test.go b/handlers/tribes_test.go index c6d984623..0c08c65a6 100644 --- a/handlers/tribes_test.go +++ b/handlers/tribes_test.go @@ -155,17 +155,26 @@ func TestGetTribe(t *testing.T) { } func TestGetTribesByAppUrl(t *testing.T) { - mockDb := mocks.NewDatabase(t) - tHandler := NewTribeHandler(mockDb) + teardownSuite := SetupSuite(t) + defer teardownSuite(t) + + tHandler := NewTribeHandler(db.TestDB) t.Run("Should test that a tribe is returned when the right app URL is passed", func(t *testing.T) { - // Mock data - mockAppURL := "valid_app_url" - mockTribes := []db.Tribe{ - {UUID: "uuid", AppURL: mockAppURL}, - {UUID: "uuid", AppURL: mockAppURL}, + tribe := db.Tribe{ + UUID: "uuid", + OwnerPubKey: "pubkey", + Name: "name", + Description: "description", + Tags: []string{"tag3", "tag4"}, + AppURL: "valid_app_url", + Badges: []string{}, } - mockDb.On("GetTribesByAppUrl", mockAppURL).Return(mockTribes).Once() + db.TestDB.CreateOrEditTribe(tribe) + + // Mock data + mockAppURL := tribe.AppURL + mockTribes := []db.Tribe{tribe} // Serve request rr := httptest.NewRecorder()