// This file is auto-generated by alef — DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
// To regenerate: alef generate
// To verify freshness: alef verify --exit-code
// Issues & docs: https://github.com/kreuzberg-dev/alef

// E2e tests for category: async
package e2e_test

import (
	"os"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"

	kreuzberg "github.com/kreuzberg-dev/kreuzberg/v5"
)

func Test_AsyncExtractBytes(t *testing.T) {
	// Async extract_bytes call on PDF document
	contentBytes, contentBytesErr := os.ReadFile(`pdf/fake_memo.pdf`)
	if contentBytesErr != nil {
		t.Fatalf("read fixture pdf/fake_memo.pdf: %v", contentBytesErr)
	}
	result, err := kreuzberg.ExtractBytes(contentBytes, `application/pdf`, kreuzberg.ExtractionConfig{})
	if err != nil {
		t.Fatalf("call failed: %v", err)
	}
	if strings.TrimSpace(string(result.MimeType)) != `application/pdf` {
		t.Errorf("equals mismatch: got %v", result.MimeType)
	}
	assert.GreaterOrEqual(t, len(result.Content), 50, "expected length >= 50")
}

func Test_AsyncExtractBytesEmptyMime(t *testing.T) {
	// extract_bytes empty MIME async
	contentBytes, contentBytesErr := os.ReadFile(`text/plain.txt`)
	if contentBytesErr != nil {
		t.Fatalf("read fixture text/plain.txt: %v", contentBytesErr)
	}
	_, err := kreuzberg.ExtractBytes(contentBytes, ``, kreuzberg.ExtractionConfig{})
	if err == nil {
		t.Errorf("expected an error, but call succeeded")
	}
}

func Test_AsyncExtractBytesInvalidMime(t *testing.T) {
	// extract_bytes unsupported MIME async
	contentBytes, contentBytesErr := os.ReadFile(`text/plain.txt`)
	if contentBytesErr != nil {
		t.Fatalf("read fixture text/plain.txt: %v", contentBytesErr)
	}
	_, err := kreuzberg.ExtractBytes(contentBytes, `application/x-nonexistent`, kreuzberg.ExtractionConfig{})
	if err == nil {
		t.Errorf("expected an error, but call succeeded")
	}
}
