Files
ewelink-api/test/main-invalid-credentials.spec.js
Martin M 90f7cde28c Release v1.3.0 (#8)
* helper method to login into ewelink if no auth credentials found

* return websocket reponse as JSON

* created function to get raw consumption data

* created function to parse raw consumption data and return daily usage

* renamed property

* created function to get current month power usage

* created function to get raw power usage

* added new test cases

* catch websocket connection errors

* power usage enhancements

* added new test case

* removed unused code

* updated credentials file

* version bump

* updated dependencies

* tests reorganized
2019-07-27 14:52:12 -03:00

60 lines
2.3 KiB
JavaScript

const ewelink = require('../main');
const { deviceId, deviceIdWithPower } = require('./_setup/credentials.json');
describe('invalid credentials', () => {
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 api login', async () => {
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
const login = await conn.login();
expect(typeof login).toBe('object');
expect(login.msg).toBe('Authentication error');
expect(login.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(deviceId);
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(deviceId);
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(deviceId, '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('Authentication error');
expect(powerUsage.error).toBe(401);
});
});