mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-21 21:33:11 +01:00
Release v1.4.1 (#13)
* specific error when requested channel is bigger than total * fix for multi-channel devices * updated test expectations * fixes with uiid api changes * fix wrong error message * added new test cases * return expected error on wrong channel number * added more devices * version bump
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
const delay = require('delay');
|
||||
|
||||
const ewelink = require('../main');
|
||||
const { email, password, deviceId } = require('./_setup/credentials.json');
|
||||
const {
|
||||
email,
|
||||
password,
|
||||
singleChannelDeviceId,
|
||||
fourChannelsDevice,
|
||||
} = require('./_setup/credentials.json');
|
||||
const {
|
||||
loginExpectations,
|
||||
allDevicesExpectations,
|
||||
@@ -15,6 +20,10 @@ describe('env: node script', () => {
|
||||
conn = new ewelink({ email, password });
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await delay(1000);
|
||||
});
|
||||
|
||||
test('login into ewelink', async () => {
|
||||
const login = await conn.login();
|
||||
expect(typeof login).toBe('object');
|
||||
@@ -28,49 +37,103 @@ describe('env: node script', () => {
|
||||
});
|
||||
|
||||
test('get specific device', async () => {
|
||||
const device = await conn.getDevice(deviceId);
|
||||
const device = await conn.getDevice(singleChannelDeviceId);
|
||||
expect(typeof device).toBe('object');
|
||||
expect(device.deviceid).toBe(deviceId);
|
||||
expect(device.deviceid).toBe(singleChannelDeviceId);
|
||||
expect(device).toMatchObject(specificDeviceExpectations);
|
||||
});
|
||||
|
||||
test('get device power state', async () => {
|
||||
const device = await conn.getDevice(deviceId);
|
||||
test('get single channel device power state', async () => {
|
||||
const device = await conn.getDevice(singleChannelDeviceId);
|
||||
const currentState = device.params.switch;
|
||||
const powerState = await conn.getDevicePowerState(deviceId);
|
||||
const powerState = await conn.getDevicePowerState(singleChannelDeviceId);
|
||||
expect(typeof powerState).toBe('object');
|
||||
expect(powerState.status).toBe('ok');
|
||||
expect(powerState.state).toBe(currentState);
|
||||
});
|
||||
|
||||
test('set device power state', async () => {
|
||||
test('get multi channel device power state', async () => {
|
||||
const channel = 3;
|
||||
const device = await conn.getDevice(fourChannelsDevice);
|
||||
const currentState = device.params.switches[channel - 1].switch;
|
||||
const powerState = await conn.getDevicePowerState(
|
||||
fourChannelsDevice,
|
||||
channel
|
||||
);
|
||||
expect(typeof powerState).toBe('object');
|
||||
expect(powerState.status).toBe('ok');
|
||||
expect(powerState.state).toBe(currentState);
|
||||
});
|
||||
|
||||
test('set single channel device power state', async () => {
|
||||
jest.setTimeout(30000);
|
||||
await delay(3000);
|
||||
const device = await conn.getDevice(deviceId);
|
||||
const device = await conn.getDevice(singleChannelDeviceId);
|
||||
const currentState = device.params.switch;
|
||||
const newState = currentState === 'on' ? 'off' : 'on';
|
||||
const powerState = await conn.setDevicePowerState(deviceId, newState);
|
||||
const powerState = await conn.setDevicePowerState(
|
||||
singleChannelDeviceId,
|
||||
newState
|
||||
);
|
||||
expect(typeof powerState).toBe('object');
|
||||
expect(powerState.status).toBe('ok');
|
||||
expect(powerState.state).toBe(newState);
|
||||
const deviceVerify = await conn.getDevice(deviceId);
|
||||
const deviceVerify = await conn.getDevice(singleChannelDeviceId);
|
||||
const currentStateVerify = deviceVerify.params.switch;
|
||||
expect(newState).toBe(currentStateVerify);
|
||||
});
|
||||
|
||||
test('toggle device power state', async () => {
|
||||
test('set multi channel device power state', async () => {
|
||||
jest.setTimeout(30000);
|
||||
await delay(3000);
|
||||
const device = await conn.getDevice(deviceId);
|
||||
const channel = 3;
|
||||
const device = await conn.getDevice(fourChannelsDevice);
|
||||
const currentState = device.params.switches[channel - 1].switch;
|
||||
const newState = currentState === 'on' ? 'off' : 'on';
|
||||
const powerState = await conn.setDevicePowerState(
|
||||
fourChannelsDevice,
|
||||
newState,
|
||||
channel
|
||||
);
|
||||
expect(typeof powerState).toBe('object');
|
||||
expect(powerState.status).toBe('ok');
|
||||
expect(powerState.state).toBe(newState);
|
||||
const deviceVerify = await conn.getDevice(fourChannelsDevice);
|
||||
const currentStateVerify = deviceVerify.params.switches[channel - 1].switch;
|
||||
expect(newState).toBe(currentStateVerify);
|
||||
});
|
||||
|
||||
test('toggle single channel device power state', async () => {
|
||||
jest.setTimeout(30000);
|
||||
await delay(3000);
|
||||
const device = await conn.getDevice(singleChannelDeviceId);
|
||||
const currentState = device.params.switch;
|
||||
const newState = currentState === 'on' ? 'off' : 'on';
|
||||
await conn.toggleDevice(deviceId);
|
||||
const deviceVerify = await conn.getDevice(deviceId);
|
||||
await conn.toggleDevice(singleChannelDeviceId);
|
||||
const deviceVerify = await conn.getDevice(singleChannelDeviceId);
|
||||
const currentStateVerify = deviceVerify.params.switch;
|
||||
expect(newState).toBe(currentStateVerify);
|
||||
await conn.toggleDevice(deviceId);
|
||||
const deviceVerifyAgain = await conn.getDevice(deviceId);
|
||||
await conn.toggleDevice(singleChannelDeviceId);
|
||||
const deviceVerifyAgain = await conn.getDevice(singleChannelDeviceId);
|
||||
const currentStateVerifyAgain = deviceVerifyAgain.params.switch;
|
||||
expect(currentState).toBe(currentStateVerifyAgain);
|
||||
});
|
||||
|
||||
test('toggle multi channel device power state', async () => {
|
||||
jest.setTimeout(30000);
|
||||
await delay(3000);
|
||||
const channel = 3;
|
||||
const device = await conn.getDevice(fourChannelsDevice);
|
||||
const currentState = device.params.switches[channel - 1].switch;
|
||||
const newState = currentState === 'on' ? 'off' : 'on';
|
||||
await conn.toggleDevice(fourChannelsDevice, channel);
|
||||
const deviceVerify = await conn.getDevice(fourChannelsDevice);
|
||||
const currentStateVerify = deviceVerify.params.switches[channel - 1].switch;
|
||||
expect(newState).toBe(currentStateVerify);
|
||||
await conn.toggleDevice(fourChannelsDevice, channel);
|
||||
const deviceVerifyAgain = await conn.getDevice(fourChannelsDevice);
|
||||
const currentStateVerifyAgain =
|
||||
deviceVerifyAgain.params.switches[channel - 1].switch;
|
||||
expect(currentState).toBe(currentStateVerifyAgain);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user