Files
ewelink-api/test/valid-credentials.spec.js
Martin M 098011b285 Release v2.0.0 (#44)
* Added arpTableSolver (#18)

* Added arpTableSolver

* fix package import

* linting class

* changed arp library

* refactor arp class

* using arpping fork

* refactor arpTableSolver class

* Added Zero Conf functionality (LAN mode) (#46)

* added crypto-js

* zeroconf helper functions

* zeroconf update payload

* new method to save devices cache file

* class renamed

* refactor Zeroconf class

* return cached device if exists

* moved method to get local ip address

* fix mac addresses without leading zeroes

* refactor Zeroconf class

* using new zeroconf functionality

* zeroconf working with single and multichannel devices

* save device mixin enhancement

* working on zeroconf test cases

* catch errors on filesystem methods

* zeroconf: added extra test cases

* better error handling

* zeroconf: 100% code coverage

* removed deprecated login method

* updates on credentials file

* version bump

* Docs for v2.0 (#52)

* added v1 docs

* added zeroconf docs

* updated readme

* docs updated

* removed zeroconf article warning

* updated vscode config

Co-authored-by: Luis Llamas <luisllamas@hotmail.com>
2020-01-11 01:39:29 -03:00

109 lines
4.0 KiB
JavaScript

const delay = require('delay');
const ewelink = require('../main');
const {
email,
password,
deviceIdWithoutPower,
fourChannelsDevice,
} = require('./_setup/credentials.js');
const { credentialsExpectations } = require('./_setup/expectations');
describe('valid credentials, invalid device', () => {
beforeEach(async () => {
await delay(1000);
});
test('get power state on invalid device should fail', async () => {
const conn = new ewelink({ email, password });
const powerState = await conn.getDevicePowerState('invalid deviceid');
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Device does not exist');
expect(powerState.error).toBe(500);
});
test('get power state on wrong device channel should fail', async () => {
const conn = new ewelink({ email, password });
const powerState = await conn.getDevicePowerState(fourChannelsDevice, 8);
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Device channel does not exist');
expect(powerState.error).toBe(false);
});
test('set power state on invalid device should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email, password });
const powerState = await conn.setDevicePowerState('invalid deviceid', 'on');
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Device does not exist');
expect(powerState.error).toBe(500);
});
test('set power state on wrong device channel should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email, password });
const powerState = await conn.setDevicePowerState(
fourChannelsDevice,
'on',
8
);
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Device channel does not exist');
expect(powerState.error).toBe(false);
});
test('toggle power state on invalid device should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email, password });
const powerState = await conn.toggleDevice('invalid deviceid');
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Device does not exist');
expect(powerState.error).toBe(500);
});
test('raw power usage on invalid device should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email, password });
const powerUsage = await conn.getDeviceRawPowerUsage('invalid deviceid');
expect(typeof powerUsage).toBe('object');
expect(powerUsage.msg).toBe('Forbidden');
expect(powerUsage.error).toBe(403);
});
test('current month power usage on invalid device should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email, password });
const powerUsage = await conn.getDevicePowerUsage('invalid deviceid');
expect(typeof powerUsage).toBe('object');
expect(powerUsage.msg).toBe('Forbidden');
expect(powerUsage.error).toBe(403);
});
test('raw power on device without electricity monitor should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email, password });
const powerUsage = await conn.getDeviceRawPowerUsage(deviceIdWithoutPower);
expect(typeof powerUsage).toBe('object');
expect(powerUsage.error).toBe('No power usage data found.');
});
test('get channel count should fail', async () => {
const conn = new ewelink({ email, password });
const switchesAmount = await conn.getDeviceChannelCount('invalid deviceid');
expect(typeof switchesAmount).toBe('object');
expect(switchesAmount.msg).toBe('Device does not exist');
expect(switchesAmount.error).toBe(500);
});
});
describe('valid credentials, wrong region', () => {
test('should get valid credentials in the right region', async () => {
const conn = new ewelink({ email, password, region: 'eu' });
const credentials = await conn.getCredentials();
expect(typeof credentials).toBe('object');
expect(credentials).toMatchObject(credentialsExpectations);
});
});