import { describe, it, after } from 'node:test'
import assert from 'node:assert'
import { TOOL_CONFIG } from '../src/config/api.ts'
import type { McpToolResponse } from './types.ts'
import type { Talk } from '../src/types/index.ts'
import { createTestClient, parseToolResponse } from './helpers.ts'
describe('Talks API Tests', async () => {
const client = await createTestClient()
after(async () => {
await client.close()
})
it('should get a list of talks with default pagination', async () => {
const result = await client.callTool({
name: TOOL_CONFIG.talks.name,
arguments: {}
}) as McpToolResponse
assert.ok(result.content[0]?.text.includes('Talks Results'))
const data = parseToolResponse(result)
assert.ok(data.totalCount > 0)
assert.ok(Array.isArray(data.talks))
assert.equal(data.talks.length, 10) // Default limit
})
it('should get a limited number of talks', async () => {
const limit = 2
const result = await client.callTool({
name: TOOL_CONFIG.talks.name,
arguments: { limit }
}) as McpToolResponse
const data = parseToolResponse(result)
assert.equal(data.talks.length, limit)
})
it('should filter talks by language', async () => {
const result = await client.callTool({
name: TOOL_CONFIG.talks.name,
arguments: {
language: 'es',
limit: 5
}
}) as McpToolResponse
const data = parseToolResponse(result)
assert.ok(data.talks.every((talk: Talk) => talk.language === 'es'))
})
it('should filter talks by country', async () => {
const country = 'Spain'
const result = await client.callTool({
name: TOOL_CONFIG.talks.name,
arguments: {
country,
limit: 5
}
}) as McpToolResponse
const data = parseToolResponse(result)
assert.ok(data.talks.every((talk: Talk) => talk.location?.country === country))
})
it('should get talk counts by group', async () => {
const result = await client.callTool({
name: TOOL_CONFIG.talks.name,
arguments: {
count_only: true,
group_by: 'language'
}
}) as McpToolResponse
assert.ok(result?.content[0]?.text.includes('Total talks:'))
assert.ok(result?.content[0]?.text.includes('Breakdown by language:'))
})
})