UNPKG

@shadman-a/homebridge-my-ac

Version:

A Homebridge plugin for controlling/monitoring LG ThinQ devices via LG ThinQ platform.

74 lines 2.97 kB
import { Helper, fToC, cToF } from '../helper.js'; import { PlatformType } from '../lib/constants.js'; import { describe, expect, it, jest } from '@jest/globals'; // Mock dependencies jest.mock('../lib/Device'); jest.mock('../lib/constants', () => ({ PlatformType: { ThinQ1: 'ThinQ1', ThinQ2: 'ThinQ2', }, })); // Test suite for Helper class and utility functions describe('Helper', () => { describe('make', () => { it('should return V1helper.make for ThinQ1 platform', () => { const mockDevice = { platform: PlatformType.ThinQ1 }; const result = Helper.make(mockDevice); expect(result).toBeDefined(); }); it('should return the correct class for ThinQ2 devices', () => { const mockDevice = { platform: PlatformType.ThinQ2, type: 'AC' }; const result = Helper.make(mockDevice); expect(result).toBeDefined(); }); it('should return null for unknown device types', () => { const mockDevice = { platform: PlatformType.ThinQ2, type: 'UNKNOWN' }; const result = Helper.make(mockDevice); expect(result).toBeNull(); }); it('should return null for unsupported platform types', () => { const mockDevice = { platform: 'UnsupportedPlatform' }; const result = Helper.make(mockDevice); expect(result).toBeNull(); }); }); describe('category', () => { it('should return the correct category for known device types', () => { const mockDevice = { type: 'AIR_PURIFIER' }; const result = Helper.category(mockDevice); expect(result).toBe(19 /* Categories.AIR_PURIFIER */); }); it('should return Categories.OTHER for unknown device types', () => { const mockDevice = { type: 'UNKNOWN' }; const result = Helper.category(mockDevice); expect(result).toBe(1 /* Categories.OTHER */); }); it('should return Categories.AIR_CONDITIONER for AC device type', () => { const mockDevice = { type: 'AC' }; const result = Helper.category(mockDevice); expect(result).toBe(21 /* Categories.AIR_CONDITIONER */); }); }); }); describe('Utility functions', () => { describe('fToC', () => { it('should convert Fahrenheit to Celsius', () => { expect(fToC(32)).toBe(0); expect(fToC(212)).toBe(100); }); it('should handle negative Fahrenheit values', () => { expect(fToC(-40)).toBe(-40); }); }); describe('cToF', () => { it('should convert Celsius to Fahrenheit', () => { expect(cToF(0)).toBe(32); expect(cToF(100)).toBe(212); }); it('should handle negative Celsius values', () => { expect(cToF(-40)).toBe(-40); }); }); }); //# sourceMappingURL=helper.spec.js.map