Skip to content

Commit

Permalink
acteFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
samkithkjain committed Dec 5, 2023
1 parent a445c2e commit b7b114a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 102 deletions.
18 changes: 5 additions & 13 deletions TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
89 changes: 0 additions & 89 deletions zone/internal/core/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

0 comments on commit b7b114a

Please sign in to comment.