136 lines
4.4 KiB
JavaScript
136 lines
4.4 KiB
JavaScript
|
import { describe, it, expect } from 'vitest';
|
||
|
import { timeTools } from '../src/tools/index.js';
|
||
|
|
||
|
describe('Time Tools', () => {
|
||
|
describe('getCurrentTime', () => {
|
||
|
it('should return current time in ISO format by default', async () => {
|
||
|
const getCurrentTime = timeTools.find(
|
||
|
tool => tool.name === 'getCurrentTime'
|
||
|
);
|
||
|
expect(getCurrentTime).toBeDefined();
|
||
|
|
||
|
const result = await getCurrentTime.handler({});
|
||
|
expect(result).toHaveProperty('content');
|
||
|
expect(result.content[0]).toHaveProperty('text');
|
||
|
|
||
|
const response = JSON.parse(result.content[0].text);
|
||
|
expect(response).toHaveProperty('currentTime');
|
||
|
expect(response).toHaveProperty('timezone');
|
||
|
expect(response).toHaveProperty('format');
|
||
|
});
|
||
|
|
||
|
it('should return time in specified timezone', async () => {
|
||
|
const getCurrentTime = timeTools.find(
|
||
|
tool => tool.name === 'getCurrentTime'
|
||
|
);
|
||
|
const result = await getCurrentTime.handler({
|
||
|
timezone: 'America/New_York',
|
||
|
});
|
||
|
|
||
|
const response = JSON.parse(result.content[0].text);
|
||
|
expect(response.timezone).toBe('America/New_York');
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('getTimezone', () => {
|
||
|
it('should return timezone information', async () => {
|
||
|
const getTimezone = timeTools.find(tool => tool.name === 'getTimezone');
|
||
|
expect(getTimezone).toBeDefined();
|
||
|
|
||
|
const result = await getTimezone.handler({ timezone: 'UTC' });
|
||
|
const response = JSON.parse(result.content[0].text);
|
||
|
|
||
|
expect(response).toHaveProperty('timezone');
|
||
|
expect(response).toHaveProperty('offset');
|
||
|
expect(response).toHaveProperty('abbreviation');
|
||
|
expect(response).toHaveProperty('longName');
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('formatTime', () => {
|
||
|
it('should format time correctly', async () => {
|
||
|
const formatTime = timeTools.find(tool => tool.name === 'formatTime');
|
||
|
expect(formatTime).toBeDefined();
|
||
|
|
||
|
const testDate = '2024-01-01T12:00:00Z';
|
||
|
const result = await formatTime.handler({
|
||
|
time: testDate,
|
||
|
format: 'iso',
|
||
|
});
|
||
|
|
||
|
const response = JSON.parse(result.content[0].text);
|
||
|
expect(response).toHaveProperty('originalTime');
|
||
|
expect(response).toHaveProperty('formattedTime');
|
||
|
expect(response).toHaveProperty('format');
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('calculateDateDifference', () => {
|
||
|
it('should calculate date difference correctly', async () => {
|
||
|
const calculateDateDifference = timeTools.find(
|
||
|
tool => tool.name === 'calculateDateDifference'
|
||
|
);
|
||
|
expect(calculateDateDifference).toBeDefined();
|
||
|
|
||
|
const result = await calculateDateDifference.handler({
|
||
|
startDate: '2024-01-01',
|
||
|
endDate: '2024-01-02',
|
||
|
unit: 'days',
|
||
|
});
|
||
|
|
||
|
const response = JSON.parse(result.content[0].text);
|
||
|
expect(response).toHaveProperty('startDate');
|
||
|
expect(response).toHaveProperty('endDate');
|
||
|
expect(response).toHaveProperty('difference');
|
||
|
expect(response.difference).toBe(1);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('getWorldClock', () => {
|
||
|
it('should return world clock information', async () => {
|
||
|
const getWorldClock = timeTools.find(
|
||
|
tool => tool.name === 'getWorldClock'
|
||
|
);
|
||
|
expect(getWorldClock).toBeDefined();
|
||
|
|
||
|
const result = await getWorldClock.handler({
|
||
|
timezones: ['UTC', 'America/New_York'],
|
||
|
});
|
||
|
|
||
|
const response = JSON.parse(result.content[0].text);
|
||
|
expect(response).toHaveProperty('worldClock');
|
||
|
expect(Array.isArray(response.worldClock)).toBe(true);
|
||
|
expect(response.worldClock).toHaveLength(2);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('Tool Validation', () => {
|
||
|
it('should have all required tools', () => {
|
||
|
const expectedTools = [
|
||
|
'getCurrentTime',
|
||
|
'getTimezone',
|
||
|
'formatTime',
|
||
|
'calculateDateDifference',
|
||
|
'getWorldClock',
|
||
|
];
|
||
|
|
||
|
expectedTools.forEach(toolName => {
|
||
|
const tool = timeTools.find(t => t.name === toolName);
|
||
|
expect(tool).toBeDefined();
|
||
|
expect(tool).toHaveProperty('name');
|
||
|
expect(tool).toHaveProperty('description');
|
||
|
expect(tool).toHaveProperty('inputSchema');
|
||
|
expect(tool).toHaveProperty('handler');
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it('should have valid input schemas', () => {
|
||
|
timeTools.forEach(tool => {
|
||
|
expect(tool.inputSchema).toHaveProperty('type');
|
||
|
expect(tool.inputSchema.type).toBe('object');
|
||
|
expect(tool.inputSchema).toHaveProperty('properties');
|
||
|
});
|
||
|
});
|
||
|
});
|