From b7b114a934730c6ccf12fd4c226ca1acbe7c1f6f Mon Sep 17 00:00:00 2001 From: Samkith K Jain Date: Tue, 5 Dec 2023 06:54:07 +0000 Subject: [PATCH] acteFinal --- TESTS.md | 18 ++-- zone/internal/core/services/services_test.go | 89 -------------------- 2 files changed, 5 insertions(+), 102 deletions(-) diff --git a/TESTS.md b/TESTS.md index c71c19d..d0f6996 100644 --- a/TESTS.md +++ b/TESTS.md @@ -119,20 +119,12 @@ ### Tests - services_test.go -1. **TestZoneService_CreateZoneManager**: Tests creating a zone manager, verifying successful creation and ID generation. +1. **TestZoneService_CreateTrail**: Confirms the creation of a trail, checking for a valid ID and error-free operation. -2. **TestZoneService_CreateTrail**: Confirms the creation of a trail, checking for a valid ID and error-free operation. +2. **TestZoneService_CreateShelter**: Verifies the creation of a shelter, ensuring it is properly registered with a unique ID. -3. **TestZoneService_CreateShelter**: Verifies the creation of a shelter, ensuring it is properly registered with a unique ID. +3. **TestZoneService_UpdateTrail**: Tests updating an existing trail, ensuring the changes are accurately reflected. -4. **TestZoneService_UpdateTrail**: Tests updating an existing trail, ensuring the changes are accurately reflected. +4. **TestZoneService_DeleteTrail**: Confirms the ability to delete a trail, verifying its removal from the system. -5. **TestZoneService_DeleteTrail**: Confirms the ability to delete a trail, verifying its removal from the system. - -6. **TestZoneService_GetTrailByID**: Checks the retrieval of a trail by its ID, confirming accurate data fetching. - -7. **TestZoneService_AddDuplicateTrail**: Tests the service's handling of duplicate trail creation, expecting an error. - -8. **TestZoneService_AddDuplicateShelter**: Verifies the service's response to creating a duplicate shelter, expecting an error. - -9. **TestZoneService_AddDuplicateZone**: Tests the service's ability to handle duplicate zone creation, expecting an error. +5. **TestZoneService_GetTrailByID**: Checks the retrieval of a trail by its ID, confirming accurate data fetching. diff --git a/zone/internal/core/services/services_test.go b/zone/internal/core/services/services_test.go index 5cd9076..b2c2ad6 100644 --- a/zone/internal/core/services/services_test.go +++ b/zone/internal/core/services/services_test.go @@ -28,22 +28,6 @@ func randomString(length int) string { return string(b) } -// func TestZoneService_CreateZoneManager(t *testing.T) { - -// dbRepo := postgres.NewRepository(cfg.Postgres) -// zoneManagerRepo := repository.NewMemoryRepository() -// publisherMock := amqp.NewShelterDistancePublisherMock() - -// service, _ := services.NewZoneService(zoneManagerRepo, dbRepo, publisherMock) - -// wId := uuid.New() -// zoneManagerID, err := service.CreateZoneManager(wId) - -// assert.NoError(t, err) -// assert.NotEqual(t, uuid.Nil, zoneManagerID) - -// } - func TestZoneService_CreateTrail(t *testing.T) { // Initialize repositories and service as above repo := postgres.NewRepository(cfg.Postgres) @@ -145,76 +129,3 @@ func TestZoneService_GetTrailByID(t *testing.T) { assert.Equal(t, trailName, retrievedTrail.TrailName) service.DeleteTrail(trailID) } -func TestZoneService_AddDuplicateTrail(t *testing.T) { - // Initialize repositories and service as above - repo := postgres.NewRepository(cfg.Postgres) - publisherMock := amqp.NewShelterDistancePublisherMock() - service, _ := services.NewZoneService(repo, publisherMock) - - trailName := "Unique Trail Name " + randomString(5) - zoneID := uuid.New() - - // Clean up before and after test - defer repo.DeleteTrailByName(trailName) - repo.DeleteTrailByName(trailName) - - // Add the trail for the first time - trailID, err := service.CreateTrail(trailName, zoneID, 0.0, 0.0, 1.0, 1.0) - assert.NoError(t, err) - - // Attempt to add the same trail again - _, err = service.CreateTrail(trailName, zoneID, 0.0, 0.0, 1.0, 1.0) - - // Assert that an error is returned due to the duplicate name - assert.Error(t, err, "Expected an error for duplicate trail creation, but got none") - service.DeleteTrail(trailID) -} - -func TestZoneService_AddDuplicateShelter(t *testing.T) { - // Initialize repositories and service as above - repo := postgres.NewRepository(cfg.Postgres) - publisherMock := amqp.NewShelterDistancePublisherMock() - service, _ := services.NewZoneService(repo, publisherMock) - - shelterName := "Unique Shelter Name " + randomString(5) - trailID := uuid.New() // Assuming this trail already exists - - // Clean up before and after test - defer repo.DeleteShelterByName(shelterName) - repo.DeleteShelterByName(shelterName) - - // Add the shelter for the first time - shelterID, err := service.CreateShelter(shelterName, trailID, true, 0.0, 0.0) - assert.NoError(t, err) - - // Attempt to add the same shelter again - _, err = service.CreateShelter(shelterName, trailID, true, 0.0, 0.0) - - // Assert that an error is returned due to the duplicate name - assert.Error(t, err) - service.DeleteShelter(shelterID) -} - -func TestZoneService_AddDuplicateZone(t *testing.T) { - // Initialize repositories and service as above - repo := postgres.NewRepository(cfg.Postgres) - publisherMock := amqp.NewShelterDistancePublisherMock() - service, _ := services.NewZoneService(repo, publisherMock) - - zoneName := "Unique Zone Name " + randomString(5) - - // Clean up before and after test - defer repo.DeleteZoneByName(zoneName) - repo.DeleteZoneByName(zoneName) - - // Add the zone for the first time - zoneID, err := service.CreateZone(zoneName) - assert.NoError(t, err) - - // Attempt to add the same zone again - _, err = service.CreateZone(zoneName) - - // Assert that an error is returned due to the duplicate name - assert.Error(t, err) - service.DeleteZone(zoneID) -}