This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
breakpilot-pwa/edu-search-service/internal/publications/pub_crawler_test.go
Benjamin Admin bfdaf63ba9 fix: Restore all files lost during destructive rebase
A previous `git pull --rebase origin main` dropped 177 local commits,
losing 3400+ files across admin-v2, backend, studio-v2, website,
klausur-service, and many other services. The partial restore attempt
(660295e2) only recovered some files.

This commit restores all missing files from pre-rebase ref 98933f5e
while preserving post-rebase additions (night-scheduler, night-mode UI,
NightModeWidget dashboard integration).

Restored features include:
- AI Module Sidebar (FAB), OCR Labeling, OCR Compare
- GPU Dashboard, RAG Pipeline, Magic Help
- Klausur-Korrektur (8 files), Abitur-Archiv (5+ files)
- Companion, Zeugnisse-Crawler, Screen Flow
- Full backend, studio-v2, website, klausur-service
- All compliance SDKs, agent-core, voice-service
- CI/CD configs, documentation, scripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 09:51:32 +01:00

189 lines
4.0 KiB
Go

package publications
import (
"testing"
"github.com/breakpilot/edu-search-service/internal/database"
)
func TestContainsPub_ByDOI(t *testing.T) {
doi1 := "10.1000/test1"
doi2 := "10.1000/test2"
doi3 := "10.1000/test3"
pubs := []*database.Publication{
{Title: "Paper 1", DOI: &doi1},
{Title: "Paper 2", DOI: &doi2},
}
tests := []struct {
name string
pub *database.Publication
expected bool
}{
{
name: "DOI exists in list",
pub: &database.Publication{Title: "Different Title", DOI: &doi1},
expected: true,
},
{
name: "DOI does not exist",
pub: &database.Publication{Title: "New Paper", DOI: &doi3},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := containsPub(pubs, tt.pub)
if result != tt.expected {
t.Errorf("Expected %v, got %v", tt.expected, result)
}
})
}
}
func TestContainsPub_ByTitle(t *testing.T) {
pubs := []*database.Publication{
{Title: "Machine Learning Applications"},
{Title: "Deep Neural Networks"},
}
tests := []struct {
name string
pub *database.Publication
expected bool
}{
{
name: "Title exists in list",
pub: &database.Publication{Title: "Machine Learning Applications"},
expected: true,
},
{
name: "Title does not exist",
pub: &database.Publication{Title: "New Research Paper"},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := containsPub(pubs, tt.pub)
if result != tt.expected {
t.Errorf("Expected %v, got %v", tt.expected, result)
}
})
}
}
func TestContainsIgnoreCase(t *testing.T) {
tests := []struct {
name string
s string
substr string
expected bool
}{
{"Exact match", "Hello World", "Hello", true},
{"Case insensitive", "Hello World", "hello", true},
{"Case insensitive uppercase", "HELLO WORLD", "world", true},
{"Substring in middle", "The quick brown fox", "brown", true},
{"No match", "Hello World", "xyz", false},
{"Empty substring", "Hello", "", true},
{"Empty string", "", "test", false},
{"Both empty", "", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := containsIgnoreCase(tt.s, tt.substr)
if result != tt.expected {
t.Errorf("containsIgnoreCase(%q, %q) = %v, expected %v",
tt.s, tt.substr, result, tt.expected)
}
})
}
}
func TestEqualFold(t *testing.T) {
tests := []struct {
name string
s1 string
s2 string
expected bool
}{
{"Same string", "hello", "hello", true},
{"Different case", "Hello", "hello", true},
{"All uppercase", "HELLO", "hello", true},
{"Mixed case", "HeLLo", "hEllO", true},
{"Different strings", "hello", "world", false},
{"Different length", "hello", "hi", false},
{"Empty strings", "", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := equalFold(tt.s1, tt.s2)
if result != tt.expected {
t.Errorf("equalFold(%q, %q) = %v, expected %v",
tt.s1, tt.s2, result, tt.expected)
}
})
}
}
func TestFindAuthorPosition(t *testing.T) {
pub := &database.Publication{
Title: "Test Paper",
Authors: []string{
"John Smith",
"Maria Müller",
"Hans Weber",
},
}
tests := []struct {
name string
staff *database.UniversityStaff
expected int
}{
{
name: "First author",
staff: &database.UniversityStaff{
LastName: "Smith",
},
expected: 1,
},
{
name: "Second author",
staff: &database.UniversityStaff{
LastName: "Müller",
},
expected: 2,
},
{
name: "Third author",
staff: &database.UniversityStaff{
LastName: "Weber",
},
expected: 3,
},
{
name: "Author not found",
staff: &database.UniversityStaff{
LastName: "Unknown",
},
expected: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := findAuthorPosition(pub, tt.staff)
if result != tt.expected {
t.Errorf("Expected position %d, got %d for author %s",
tt.expected, result, tt.staff.LastName)
}
})
}
}