service backend
This commit is contained in:
128
api/pkg/mutil/helpers/integration_test.go
Normal file
128
api/pkg/mutil/helpers/integration_test.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
factory "github.com/tech/sendico/pkg/mlogger/factory"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// TestInterfaceImplementation verifies that the concrete types implement the expected interfaces
|
||||
func TestInterfaceImplementation(t *testing.T) {
|
||||
logger := factory.NewLogger(true)
|
||||
|
||||
// Test TaskManager interface implementation
|
||||
taskManager := NewTaskManager(logger, nil, nil)
|
||||
var _ TaskManager = taskManager
|
||||
|
||||
// Test AccountManager interface implementation
|
||||
accountManager := NewAccountManager(
|
||||
logger,
|
||||
nil, nil, nil, nil,
|
||||
)
|
||||
var _ AccountManager = accountManager
|
||||
}
|
||||
|
||||
// TestInterfaceMethodSignatures ensures all interface methods have correct signatures
|
||||
func TestInterfaceMethodSignatures(t *testing.T) {
|
||||
logger := factory.NewLogger(true)
|
||||
|
||||
projectRef := primitive.NewObjectID()
|
||||
statusRef := primitive.NewObjectID()
|
||||
|
||||
// Test TaskManager interface methods exist and have correct signatures
|
||||
taskManager := NewTaskManager(logger, nil, nil)
|
||||
|
||||
task := &model.Task{
|
||||
ProjectRef: projectRef,
|
||||
StatusRef: statusRef,
|
||||
}
|
||||
task.SetID(primitive.NewObjectID())
|
||||
|
||||
// Verify method signatures exist (don't call them to avoid nil pointer panics)
|
||||
var _ func(context.Context, primitive.ObjectID, primitive.ObjectID, *model.Task) error = taskManager.CreateTask
|
||||
var _ func(context.Context, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID) error = taskManager.MoveTask
|
||||
var _ func(context.Context, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID, primitive.ObjectID) error = taskManager.MoveTasks
|
||||
var _ func(context.Context, primitive.ObjectID, primitive.ObjectID) error = taskManager.DeleteTask
|
||||
|
||||
// Test AccountManager interface methods exist and have correct signatures
|
||||
accountManager := NewAccountManager(
|
||||
logger,
|
||||
nil, nil, nil, nil,
|
||||
)
|
||||
|
||||
// Verify method signatures exist (don't call them to avoid nil pointer panics)
|
||||
var _ func(context.Context, primitive.ObjectID) error = accountManager.DeleteAccount
|
||||
var _ func(context.Context, primitive.ObjectID) error = accountManager.DeleteOrganization
|
||||
var _ func(context.Context, primitive.ObjectID, primitive.ObjectID) error = accountManager.DeleteAll
|
||||
}
|
||||
|
||||
// TestFactoryFunctionConsistency ensures factory functions return consistent types
|
||||
func TestFactoryFunctionConsistency(t *testing.T) {
|
||||
logger := factory.NewLogger(true)
|
||||
|
||||
// Create multiple instances to ensure consistency
|
||||
for i := 0; i < 3; i++ {
|
||||
taskManager := NewTaskManager(logger, nil, nil)
|
||||
if taskManager == nil {
|
||||
t.Fatalf("NewTaskManager returned nil on iteration %d", i)
|
||||
}
|
||||
|
||||
accountManager := NewAccountManager(
|
||||
logger,
|
||||
nil, nil, nil, nil,
|
||||
)
|
||||
if accountManager == nil {
|
||||
t.Fatalf("NewAccountManager returned nil on iteration %d", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestErrorHandlingWithNilDependencies ensures helpers handle nil dependencies gracefully
|
||||
func TestErrorHandlingWithNilDependencies(t *testing.T) {
|
||||
logger := factory.NewLogger(true)
|
||||
|
||||
// Test that creating helpers with nil dependencies doesn't panic
|
||||
taskManager := NewTaskManager(logger, nil, nil)
|
||||
if taskManager == nil {
|
||||
t.Fatal("TaskManager should not be nil even with nil dependencies")
|
||||
}
|
||||
|
||||
accountManager := NewAccountManager(
|
||||
logger,
|
||||
nil, nil, nil, nil,
|
||||
)
|
||||
if accountManager == nil {
|
||||
t.Fatal("AccountManager should not be nil even with nil dependencies")
|
||||
}
|
||||
|
||||
// The actual method calls would panic with nil dependencies,
|
||||
// but that's expected behavior - the constructors should handle nil gracefully
|
||||
t.Log("Helper managers created successfully with nil dependencies")
|
||||
}
|
||||
|
||||
// TestHelperManagersDocumentedBehavior verifies expected behavior from documentation/comments
|
||||
func TestHelperManagersDocumentedBehavior(t *testing.T) {
|
||||
logger := factory.NewLogger(true)
|
||||
|
||||
// TaskManager is documented to handle task operations with proper ordering and numbering
|
||||
taskManager := NewTaskManager(logger, nil, nil)
|
||||
if taskManager == nil {
|
||||
t.Fatal("TaskManager should be created successfully")
|
||||
}
|
||||
|
||||
// AccountManager is documented to handle account management operations with cascade deletion
|
||||
accountManager := NewAccountManager(
|
||||
logger,
|
||||
nil, nil, nil, nil,
|
||||
)
|
||||
if accountManager == nil {
|
||||
t.Fatal("AccountManager should be created successfully")
|
||||
}
|
||||
|
||||
// Both should be transaction-aware (caller responsible for transactions according to comments)
|
||||
// This is more of a documentation test than a functional test
|
||||
t.Log("TaskManager and AccountManager created successfully - transaction handling is caller's responsibility")
|
||||
}
|
||||
Reference in New Issue
Block a user