Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDomains(t *testing.T) {
|
|
all := parseDomains("all")
|
|
if !all.has("products") || !all.has("woo") {
|
|
t.Fatalf("all should include every domain")
|
|
}
|
|
d := parseDomains("settings,formulas,tags")
|
|
if d.has("products") {
|
|
t.Fatalf("products should be excluded")
|
|
}
|
|
if !d.has("settings") || !d.has("formulas") || !d.has("tags") {
|
|
t.Fatalf("expected settings/formulas/tags: %#v", d)
|
|
}
|
|
}
|
|
|
|
func TestParseCompanyFilter(t *testing.T) {
|
|
ids := parseCompanyFilter(" a ,b, a ")
|
|
if len(ids) != 2 || ids[0] != "a" || ids[1] != "b" {
|
|
t.Fatalf("got %#v", ids)
|
|
}
|
|
set := companyFilterSet(ids)
|
|
if !set["a"] || set["c"] {
|
|
t.Fatalf("set %#v", set)
|
|
}
|
|
filtered := filterCompanies([]companyRow{{LegacyID: "a"}, {LegacyID: "c"}}, set)
|
|
if len(filtered) != 1 || filtered[0].LegacyID != "a" {
|
|
t.Fatalf("filtered %#v", filtered)
|
|
}
|
|
}
|
|
|
|
func TestMysqlCompanyFilter(t *testing.T) {
|
|
clause, args := mysqlCompanyFilter("company_id", map[string]bool{"x": true, "y": true})
|
|
if clause == "" || len(args) != 2 {
|
|
t.Fatalf("clause=%q args=%v", clause, args)
|
|
}
|
|
if !strings.Contains(clause, "`company_id`") || !strings.Contains(clause, "?") {
|
|
t.Fatalf("expected quoted column and placeholders: %q", clause)
|
|
}
|
|
qual, qArgs := mysqlCompanyFilter("cf.company_id", map[string]bool{"a": true})
|
|
if len(qArgs) != 1 || qual != " AND `cf`.`company_id` IN (?)" {
|
|
t.Fatalf("qualified: clause=%q args=%v", qual, qArgs)
|
|
}
|
|
empty, emptyArgs := mysqlCompanyFilter("company_id", nil)
|
|
if empty != "" || emptyArgs != nil {
|
|
t.Fatalf("expected empty filter")
|
|
}
|
|
}
|