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:
Martin M
2019-09-11 23:46:17 -03:00
committed by GitHub
parent 171faa617b
commit 024aaa8a2c
10 changed files with 190 additions and 52 deletions

View File

@@ -1,7 +1,12 @@
const delay = require('delay');
const ewelink = require('../main');
const { email, password, deviceId } = require('./_setup/credentials.json');
const {
email,
password,
singleChannelDeviceId,
} = require('./_setup/credentials.json');
const {
loginExpectations,
allDevicesExpectations,
@@ -12,6 +17,10 @@ describe('env: serverless', () => {
let accessToken;
let apiKey;
beforeEach(async () => {
await delay(1000);
});
test('login into ewelink', async () => {
const conn = new ewelink({ email, password });
const login = await conn.login();
@@ -30,17 +39,17 @@ describe('env: serverless', () => {
test('get specific device', async () => {
const conn = new ewelink({ at: accessToken });
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 conn = new ewelink({ at: accessToken });
const device = await conn.getDevice(deviceId);
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);
@@ -50,14 +59,17 @@ describe('env: serverless', () => {
jest.setTimeout(30000);
await delay(3000);
const conn = new ewelink({ at: accessToken, apiKey });
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);
});
@@ -66,15 +78,15 @@ describe('env: serverless', () => {
jest.setTimeout(30000);
await delay(3000);
const conn = new ewelink({ at: accessToken, apiKey });
const device = await conn.getDevice(deviceId);
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);
});