Files
ewelink-api/test/invalid-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

92 lines
3.3 KiB
JavaScript

const delay = require('delay');
const ewelink = require('../main');
const {
singleChannelDeviceId,
deviceIdWithPower,
fourChannelsDevice,
} = require('./_setup/credentials.js');
describe('invalid credentials', () => {
beforeEach(async () => {
await delay(1000);
});
test('no credentials given', async () => {
const conn = new ewelink({});
expect(typeof conn).toBe('object');
expect(conn.error).toBe('No credentials provided');
});
test('get error response on ewelink credentials', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const credentials = await conn.getCredentials();
expect(typeof credentials).toBe('object');
expect(credentials.msg).toBe('Authentication error');
expect(credentials.error).toBe(400);
});
test('get error response on all devices', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const devices = await conn.getDevices();
expect(typeof devices).toBe('object');
expect(devices.msg).toBe('Authentication error');
expect(devices.error).toBe(401);
});
test('get error response on specific device', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const device = await conn.getDevice(singleChannelDeviceId);
expect(typeof device).toBe('object');
expect(device.msg).toBe('Authentication error');
expect(device.error).toBe(401);
});
test('get device power state should fail', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const powerState = await conn.getDevicePowerState(singleChannelDeviceId);
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Authentication error');
expect(powerState.error).toBe(401);
});
test('set device power state should fail', async () => {
jest.setTimeout(30000);
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const powerState = await conn.setDevicePowerState(
singleChannelDeviceId,
'on'
);
expect(typeof powerState).toBe('object');
expect(powerState.msg).toBe('Authentication error');
expect(powerState.error).toBe(401);
});
test('current month power usage should fail', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const powerUsage = await conn.getDevicePowerUsage(deviceIdWithPower);
expect(typeof powerUsage).toBe('object');
expect(powerUsage.msg).toBe('Forbidden');
expect(powerUsage.error).toBe(403);
});
test('get channel count 1 should fail', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const switchesAmount = await conn.getDeviceChannelCount(
singleChannelDeviceId
);
expect(typeof switchesAmount).toBe('object');
expect(switchesAmount.msg).toBe('Authentication error');
expect(switchesAmount.error).toBe(401);
});
test('get channel count 4 should fail', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const switchesAmount = await conn.getDeviceChannelCount(fourChannelsDevice);
expect(typeof switchesAmount).toBe('object');
expect(switchesAmount.msg).toBe('Authentication error');
expect(switchesAmount.error).toBe(401);
});
});