package system

import (
	"strings"
	"testing"
)

func validExportTemplateForTest() *ExportTemplate {
	return &ExportTemplate{Name: "users", TemplateID: "users", TableName: "sys_users", TemplateInfo: `{"id":"ID","username":"用户名"}`}
}

func TestValidateExportTemplateRejectsCustomSQL(t *testing.T) {
	value := validExportTemplateForTest()
	value.SQL = "SELECT * FROM sys_users"
	if err := ValidateExportTemplate(value); err == nil || !strings.Contains(err.Error(), "不允许自定义 SQL") {
		t.Fatalf("ValidateExportTemplate() error = %v", err)
	}
}

func TestValidateExportTemplateRejectsUnsafeJoinAndCondition(t *testing.T) {
	value := validExportTemplateForTest()
	value.Joins = []ExportJoin{{Join: "LEFT JOIN", Table: "sys_roles", On: "1=1 OR 1=1"}}
	if err := ValidateExportTemplate(value); err == nil {
		t.Fatal("ValidateExportTemplate accepted unsafe join")
	}
}
