/**
* @file relevance_scorer.test.js
* @description Unit tests for LODA-MCP-COMP-05: relevance_scorer
* @covers LODA-MCP-DT-05 (Query + sections → Relevance scores)
*/
const { calculateRelevance } = require('../loda/relevance_scorer');
describe('LODA-MCP-COMP-05: relevance_scorer', () => {
// Helper to create mock sections
const mockSection = (header, content) => ({ header, content });
describe('calculateRelevance()', () => {
test('UT-COMP05-001: header match scores high', () => {
// Content MUST contain the search term for relevance to be scored
const section = mockSection('Authentication Flow', 'Details about the authentication process');
const score = calculateRelevance(section, 'authentication');
expect(score).toBeGreaterThan(0.8); // 0.8 base + 0.2 header bonus = 1.0
});
test('UT-COMP05-002: partial match returns score between 0 and 1', () => {
const section = mockSection('Database Setup', 'Configure authentication for database');
const score = calculateRelevance(section, 'authentication database');
expect(score).toBeGreaterThan(0);
expect(score).toBeLessThanOrEqual(1);
});
test('UT-COMP05-003: no match returns 0', () => {
const section = mockSection('Database Setup', 'SQL configuration details');
const score = calculateRelevance(section, 'authentication');
expect(score).toBe(0);
});
test('UT-COMP05-004: case insensitive matching', () => {
const section = mockSection('AUTH', 'Authentication details');
const score = calculateRelevance(section, 'auth');
expect(score).toBeGreaterThan(0);
});
test('UT-COMP05-005: multi-word query scores all terms', () => {
const section = mockSection('User Authentication', 'The flow for user authentication');
const score = calculateRelevance(section, 'user authentication flow');
expect(score).toBeGreaterThan(0.5);
});
test('UT-COMP05-006: empty query returns 0', () => {
const section = mockSection('Test', 'Test content');
expect(calculateRelevance(section, '')).toBe(0);
});
test('UT-COMP05-007: null section returns 0', () => {
expect(calculateRelevance(null, 'test')).toBe(0);
});
test('UT-COMP05-008: section without content returns 0', () => {
expect(calculateRelevance({ header: 'Test' }, 'test')).toBe(0);
});
});
});