UNPKG

@homebridge-plugins/homebridge-resideo

Version:

The Resideo plugin allows you to access your Resideo device(s) from HomeKit.

86 lines 3.27 kB
import { beforeEach, describe, expect, it, vi } from 'vitest'; import { ResideoPlatform } from './Platform.HAP.js'; describe('resideoPlatform', () => { let platform; let log; let config; let api; beforeEach(() => { log = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn(), }; config = { platform: 'Resideo', name: 'Test Platform', credentials: { accessToken: 'testAccessToken', consumerKey: 'testConsumerKey', consumerSecret: 'testConsumerSecret', refreshToken: 'testRefreshToken', }, options: { refreshRate: 120, pushRate: 0.1, devices: [], }, }; api = { hap: { uuid: { generate: vi.fn().mockReturnValue('test-uuid'), }, }, platformAccessory: vi.fn().mockImplementation((name, uuid) => ({ displayName: name, UUID: uuid, context: {}, })), user: { configPath: vi.fn().mockReturnValue('/path/to/config.json'), }, on: vi.fn(), updatePlatformAccessories: vi.fn(), }; platform = new ResideoPlatform(log, config, api); }); it('should initialize platform with given config', () => { expect(platform.config.name).toBe('Test Platform'); expect(platform.config.credentials?.accessToken).toBe('testAccessToken'); }); it('should verify config correctly', () => { expect(() => platform.verifyConfig()).not.toThrow(); }); it('should throw error if refresh rate is less than 30', () => { if (platform.config.options) { platform.config.options.refreshRate = 20; } expect(() => platform.verifyConfig()).toThrow('Refresh Rate must be above 30 seconds.'); }); it('should refresh access token', async () => { vi.spyOn(platform.httpClient, 'post').mockResolvedValue({ data: { access_token: 'newAccessToken', refresh_token: 'newRefreshToken', }, status: 200, headers: {}, }); await platform.refreshAccessToken(); expect(platform.config.credentials?.accessToken).toBe('newAccessToken'); expect(platform.config.credentials?.refreshToken).toBe('newRefreshToken'); }); it('should discover locations', async () => { const mockLocations = [{ locationID: '1', name: 'Location 1', devices: [] }]; vi.spyOn(platform.httpClient, 'get').mockResolvedValue({ data: mockLocations, status: 200, headers: {} }); const locations = await platform.discoverlocations(); expect(locations).toEqual(mockLocations); }); it('should handle error during location discovery', async () => { vi.spyOn(platform.httpClient, 'get').mockRejectedValue(new Error('Network Error')); await expect(platform.discoverlocations()).rejects.toThrow('Network Error'); }); }); //# sourceMappingURL=Platform.HAP.test.js.map