package normalizer

import (
	"context"
	"testing"

	"github.com/bluesky-social/indigo/atproto/identity"
	"github.com/bluesky-social/indigo/atproto/syntax"
	"github.com/stretchr/testify/assert"
)

func TestNormalize(t *testing.T) {
	mockDir := identity.NewMockDirectory()
	mockDir.Insert(identity.Identity{DID: "did:plc:alice", Handle: "alice.tngl.sh"})

	norm := NewMarkdownNormalizer("hostname", mockDir)

	ctx := context.Background()

	t.Run("normalize at-mention", func(t *testing.T) {
		source := "hello @alice.tngl.sh!"
		result, mentions, _ := norm.Normalize(ctx, []byte(source))
		assert.Equal(t, "hello [did:plc:alice]!", string(result))
		assert.Equal(t, []syntax.DID{"did:plc:alice"}, mentions)
	})

	t.Run("don't normalize invalid at-mention", func(t *testing.T) {
		source := "hello @alice!"
		result, mentions, _ := norm.Normalize(ctx, []byte(source))
		assert.Equal(t, "hello @alice!", string(result))
		assert.Equal(t, 0, len(mentions))
	})
}
