get-regions.tool.spec.tsβ’1.69 kB
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { GetRegionsTool } from './get-regions.tool'
import { TimezoneService } from '../../timezone/timezone.service'
describe('GetRegionsTool', () => {
let tool: GetRegionsTool
let timezoneService: TimezoneService
beforeEach(() => {
timezoneService = new TimezoneService()
tool = new GetRegionsTool(timezoneService)
})
describe('execute', () => {
it('should return all timezone regions', async () => {
const result = await tool.execute()
expect(result).toHaveProperty('content')
expect(result.content).toBeInstanceOf(Array)
expect(result.content).toHaveLength(1)
expect(result.content[0]).toHaveProperty('type', 'text')
expect(result.content[0]).toHaveProperty('text')
})
it('should return valid JSON string with regions and count', async () => {
const result = await tool.execute()
const data = JSON.parse(result.content[0].text)
expect(data).toHaveProperty('regions')
expect(data).toHaveProperty('count')
expect(data.regions).toBeInstanceOf(Array)
expect(data.count).toBe(data.regions.length)
})
it('should include standard timezone regions', async () => {
const result = await tool.execute()
const data = JSON.parse(result.content[0].text)
expect(data.regions).toContain('America')
expect(data.regions).toContain('Europe')
expect(data.regions).toContain('Asia')
})
it('should call timezoneService.getRegions', async () => {
const spy = vi.spyOn(timezoneService, 'getRegions')
await tool.execute()
expect(spy).toHaveBeenCalledOnce()
})
})
})