package taskboard

import (
	"os"
	"strings"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestSendTaskScopeMessageWrapperUsesCoordinator(t *testing.T) {
	t.Parallel()

	sourceBytes, err := os.ReadFile("store_wrappers.go")
	require.NoError(t, err)
	source := sourceFromFunctionForTest(t, string(sourceBytes), "func (store *Store) SendTaskScopeMessage")
	require.Contains(t, source, `coordinator.New(store.db).Run(ctx, "send task scope message"`)
	require.NotContains(t, source, "coredb.WithTx")
}

func sourceFromFunctionForTest(t *testing.T, source string, signature string) string {
	t.Helper()

	start := strings.Index(source, signature)
	require.NotEqual(t, -1, start)
	rest := source[start+len(signature):]
	next := strings.Index(rest, "\nfunc ")
	if next == -1 {
		return source[start:]
	}
	return source[start : start+len(signature)+next]
}
