UNPKG

amaran-light-cli

Version:

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

103 lines 4.17 kB
import { Command } from 'commander'; import registerCommands from '../commands.js'; describe('CLI intensity API usage (0-100 -> 0-1000)', () => { function buildProgram(capture) { const program = new Command(); program.exitOverride(); const mockController = { setIntensityForAllLights: async (intensity, cb) => { capture.intensityForAll = intensity; if (cb) { cb(true, 'ok'); } }, setIntensity: (nodeId, intensity, cb) => { capture.intensityOne = { nodeId, intensity }; if (cb) { cb(true, 'ok'); } }, setCCTAndIntensityForAllLights: async (cct, intensity, cb) => { capture.cctForAll = { cct, intensity }; if (cb) { cb(true, 'ok'); } }, setHSIForAllLights: async (h, s, i, _c, _g, cb) => { capture.hsiForAll = { h, s, i }; if (cb) { cb(true, 'ok'); } }, setColorForAllLights: async (color, intensity, cb) => { capture.colorForAll = { color, intensity }; if (cb) { cb(true, 'ok'); } }, disconnect: async () => { // No-op for tests }, getDevices: () => [{ node_id: 'DEV-1', device_name: 'Mock Light' }], turnOnAllLights: async () => { // No-op for tests }, turnOffAllLights: async () => { // No-op for tests }, toggleAllLights: async () => { // No-op for tests }, }; const deps = { createController: async () => mockController, findDevice: (_controller, _query) => ({ node_id: 'DEV-1', device_name: 'Mock Light', }), asyncCommand: (fn) => (...args) => fn(...args), saveWsUrl: undefined, loadConfig: () => ({}), saveConfig: () => { // Mock saveConfig for tests }, }; registerCommands(program, deps); return program; } test('intensity command maps percent to 0-1000 for all devices', async () => { const capture = {}; const program = buildProgram(capture); await program.parseAsync(['node', 'test', 'intensity', '25', 'all']); expect(capture.intensityForAll).toBe(250); }); test('intensity command boundaries 0% => 0 and 100% => 1000', async () => { const capture = {}; const program = buildProgram(capture); await program.parseAsync(['node', 'test', 'intensity', '0', 'all']); expect(capture.intensityForAll).toBe(0); const capture2 = {}; const program2 = buildProgram(capture2); await program2.parseAsync(['node', 'test', 'intensity', '100', 'all']); expect(capture2.intensityForAll).toBe(1000); }); test('cct --intensity maps percent to API range', async () => { const capture = {}; const program = buildProgram(capture); await program.parseAsync(['node', 'test', 'cct', '3000', '--intensity', '30', 'all']); expect(capture.cctForAll).toEqual({ cct: 3000, intensity: 300 }); }); test('hsi intensity argument maps percent to API range', async () => { const capture = {}; const program = buildProgram(capture); await program.parseAsync(['node', 'test', 'hsi', '120', '50', '40', 'all']); expect(capture.hsiForAll).toEqual({ h: 120, s: 50, i: 400 }); }); test('color --intensity maps percent to API range', async () => { const capture = {}; const program = buildProgram(capture); await program.parseAsync(['node', 'test', 'color', 'red', '--intensity', '12', 'all']); expect(capture.colorForAll).toEqual({ color: 'red', intensity: 120 }); }); }); //# sourceMappingURL=intensityApi.test.js.map