- Add consistent Bun test framework imports to all test files - Remove duplicate import statements - Ensure uniform import style for describe, expect, and test functions - Simplify test file import configurations
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { jest, describe, beforeEach, it, expect } from '@jest/globals';
|
|
import { z } from 'zod';
|
|
import { DomainSchema } from '../../src/schemas.js';
|
|
|
|
type MockResponse = { success: boolean };
|
|
|
|
// Define types for tool and server
|
|
interface Tool {
|
|
name: string;
|
|
description: string;
|
|
execute: (params: any) => Promise<MockResponse>;
|
|
parameters: z.ZodType<any>;
|
|
}
|
|
|
|
interface MockService {
|
|
[key: string]: jest.Mock<Promise<MockResponse>>;
|
|
}
|
|
|
|
interface MockServices {
|
|
light: {
|
|
turn_on: jest.Mock<Promise<MockResponse>>;
|
|
turn_off: jest.Mock<Promise<MockResponse>>;
|
|
};
|
|
climate: {
|
|
set_temperature: jest.Mock<Promise<MockResponse>>;
|
|
};
|
|
}
|
|
|
|
interface MockHassInstance {
|
|
services: MockServices;
|
|
}
|
|
|
|
// Mock LiteMCP class
|
|
class MockLiteMCP {
|
|
private tools: Tool[] = [];
|
|
|
|
constructor(public name: string, public version: string) { }
|
|
|
|
addTool(tool: Tool) {
|
|
this.tools.push(tool);
|
|
}
|
|
|
|
getTools() {
|
|
return this.tools;
|
|
}
|
|
}
|
|
|
|
const createMockFn = (): jest.Mock<Promise<MockResponse>> => {
|
|
return jest.fn<() => Promise<MockResponse>>().mockResolvedValue({ success: true });
|
|
};
|
|
|
|
// Mock the Home Assistant instance
|
|
const mockHassServices: MockHassInstance = {
|
|
services: {
|
|
light: {
|
|
turn_on: createMockFn(),
|
|
turn_off: createMockFn(),
|
|
},
|
|
climate: {
|
|
set_temperature: createMockFn(),
|
|
},
|
|
},
|
|
};
|
|
|
|
// Mock get_hass function
|
|
const get_hass = jest.fn<() => Promise<MockHassInstance>>().mockResolvedValue(mockHassServices);
|
|
|
|
describe('Context Tests', () => {
|
|
let mockTool: Tool;
|
|
|
|
beforeEach(() => {
|
|
mockTool = {
|
|
name: 'test_tool',
|
|
description: 'A test tool',
|
|
execute: jest.fn<(params: any) => Promise<MockResponse>>().mockResolvedValue({ success: true }),
|
|
parameters: z.object({
|
|
test: z.string()
|
|
})
|
|
};
|
|
});
|
|
|
|
// Add your test cases here
|
|
test('should execute tool successfully', async () => {
|
|
const result = await mockTool.execute({ test: 'value' });
|
|
expect(result.success).toBe(true);
|
|
});
|
|
});
|