package mock

import (
	"context"
	"testing"

	v1alpha1 "github.com/pfeifferj/container-mom-go/pkg/apis/containermom/v1alpha1"
	"github.com/pfeifferj/container-mom-go/pkg/operator/mongodb/api"
	"github.com/stretchr/testify/assert"
)

func TestMockMongoDBUtils(t *testing.T) {
	ctx := context.TODO()
	mock := NewMockMongoDB()

	// Test GetClient
	client := mock.GetClient()
	assert.NotNil(t, client)

	// Test Database
	db := mock.Database("test")
	assert.NotNil(t, db)
	assert.Equal(t, "test", db.Name())

	// Test Disconnect
	assert.NoError(t, mock.Disconnect(ctx))

	// Create test deployment first
	deployment := &api.MongoDeployment{
		ID:        "test-deployment",
		Name:      "test-deployment",
		Namespace: "default",
		GitURL:    "https://github.com/test/repo",
		Env: []v1alpha1.EnvVar{
			{
				Name:  "TEST_KEY",
				Value: "test_value",
			},
		},
	}
	err := mock.CreateDeployment(context.Background(), deployment)
	assert.NoError(t, err)

	// Test UpdateDeployment
	deployment.GitURL = "https://github.com/test/repo"
	err = mock.UpdateDeployment(context.Background(), deployment)
	assert.NoError(t, err)

	// Verify update
	updated, err := mock.GetDeployment(context.Background(), deployment.ID)
	assert.NoError(t, err)
	assert.Equal(t, deployment.GitURL, updated.GitURL)
}
