package builder

import (
	"bytes"
	"mime/multipart"
	"testing"
)

type mockMultipartFile struct {
	*bytes.Reader
}

func (m *mockMultipartFile) Close() error { return nil }

func newMockFile(data []byte) *mockMultipartFile {
	return &mockMultipartFile{Reader: bytes.NewReader(data)}
}

func TestSaveUploadedFusionPayloadRejectsDeclaredOversize(t *testing.T) {
	h := &Handler{dataDir: t.TempDir()}
	header := &multipart.FileHeader{
		Filename: "big.mkv",
		Size:     FusionMaxUploadBytes + 1,
	}
	f := newMockFile([]byte("x"))
	_, _, err := h.saveUploadedFusionPayload(f, header)
	if err == nil {
		t.Fatal("expected oversize rejection from Content-Length")
	}
}

func TestSaveUploadedFusionPayloadRejectsUnknownSize(t *testing.T) {
	h := &Handler{dataDir: t.TempDir()}
	f := newMockFile([]byte("MZ"))
	header := &multipart.FileHeader{
		Filename: "prep.exe",
		Size:     -1,
	}
	_, _, err := h.saveUploadedFusionPayload(f, header)
	if err == nil {
		t.Fatal("expected error for unknown Content-Length")
	}
}
