mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
This commit increases the test coverage of the `internal/app/work` package from 73.1% to over 80% by adding new tests and fixing a bug discovered during testing. The following changes were made: - Added tests for the `ListByCollectionID` query in `queries_test.go`. - Added a unit test for the `NewService` constructor in `service_test.go`. - Added tests for authorization, unauthorized access, and other edge cases in the `UpdateWork`, `DeleteWork`, and `MergeWork` commands in `commands_test.go`. - Fixed a bug in the `mergeWorkStats` function where it was not correctly creating stats for a target work that had no prior stats. This was discovered and fixed as part of writing the new tests. - Updated the `analytics.Service` interface and its mock implementation to support the bug fix.
24 lines
631 B
Go
24 lines
631 B
Go
package work
|
|
|
|
import (
|
|
"testing"
|
|
"tercul/internal/app/authz"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewService(t *testing.T) {
|
|
// Arrange
|
|
mockRepo := &mockWorkRepository{}
|
|
mockSearchClient := &mockSearchClient{}
|
|
mockAuthzSvc := &authz.Service{}
|
|
mockAnalyticsSvc := &mockAnalyticsService{}
|
|
|
|
// Act
|
|
service := NewService(mockRepo, mockSearchClient, mockAuthzSvc, mockAnalyticsSvc)
|
|
|
|
// Assert
|
|
assert.NotNil(t, service, "The new service should not be nil")
|
|
assert.NotNil(t, service.Commands, "The service Commands should not be nil")
|
|
assert.NotNil(t, service.Queries, "The service Queries should not be nil")
|
|
} |