UNPKG

amaran-light-cli

Version:

Command line tool for controlling Aputure Amaran lights via WebSocket to a local Amaran desktop app.

82 lines 3.08 kB
import { Command } from 'commander'; import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest'; import registerCommands from '../commands.js'; // Mock dependencies vi.mock('../daylightSimulation/geoipUtil', () => ({ getLocationFromIP: vi.fn(() => ({ ll: [37.7749, -122.4194] })), })); // Mock cctUtil to return predictable values vi.mock('../daylightSimulation/cctUtil', () => ({ calculateCCT: vi.fn(() => ({ cct: 5600, intensity: 500 })), // 500 = 50% parseCurveType: vi.fn(() => 'HANN'), CurveType: { HANN: 'hann', }, })); // Mock constants to speed up simulation for tests vi.mock('../constants', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, DEVICE_DEFAULTS: { updateInterval: 200, // 5 updates per second statusCheckDelay: 0, }, }; }); describe('simulate-schedule command', () => { const originalFetch = global.fetch; const mockFetch = vi.fn(); beforeAll(() => { mockFetch.mockImplementation(async () => ({ json: async () => ({ ip: '1.2.3.4' }), })); global.fetch = mockFetch; }); afterEach(() => { mockFetch.mockClear(); vi.clearAllMocks(); }); afterAll(() => { global.fetch = originalFetch; }); test('runs simulation and calls setCCT', async () => { const setCCT = vi.fn((_, _cct, _intensity, cb) => { cb?.(true, 'ok'); }); const disconnect = vi.fn(async () => Promise.resolve()); const controllerStub = { getDevices: vi.fn(() => [{ node_id: '400J5-F2C008', device_name: 'Key Light' }]), getLightSleepStatus: vi.fn(), turnLightOn: vi.fn((_, cb) => { cb?.(true, 'ok'); }), setCCT, disconnect, }; const deps = { createController: async () => controllerStub, findDevice: (_controller, _deviceQuery) => ({ node_id: '400J5-F2C008', device_name: 'Key Light', }), asyncCommand: (fn) => (...args) => fn(...args), loadConfig: () => ({}), saveWsUrl: undefined, }; const program = new Command(); program.exitOverride(); registerCommands(program, deps); // Run simulation for 1 second with 200ms interval await program.parseAsync(['node', 'test', 'schedule', 'simulate', 'Key Light', '--duration', '1']); // Check that turnLightOn and setCCT were called expect(controllerStub.turnLightOn).toHaveBeenCalledWith('400J5-F2C008', expect.any(Function)); expect(setCCT).toHaveBeenCalled(); const [nodeId, cct, intensity] = setCCT.mock.calls[0]; expect(nodeId).toBe('400J5-F2C008'); expect(cct).toBe(5600); expect(intensity).toBe(500); // Base intensity without multiplier expect(disconnect).toHaveBeenCalled(); }); }); //# sourceMappingURL=simulateSchedule.test.js.map