Release v1.8.1 (#28)

* new method to get user region

* added new test

* version bump
This commit is contained in:
Martin M
2019-11-11 00:22:08 -03:00
committed by GitHub
parent e6f60724f1
commit 98b8d8a97c
7 changed files with 62 additions and 2 deletions

View File

@@ -150,6 +150,9 @@ const getFirmwareVersionMixin = require('./mixins/firmware/getFirmwareVersionMix
const checkDeviceUpdateMixin = require('./mixins/firmware/checkDeviceUpdateMixin');
const checkDevicesUpdatesMixin = require('./mixins/firmware/checkDevicesUpdatesMixin');
/* LOAD MIXINS: user */
const regionMixin = require('./mixins/user/regionMixin');
/* LOAD MIXINS: websocket */
const openWebSocketMixin = require('./mixins/websocket/openWebSocketMixin');
@@ -182,6 +185,8 @@ Object.assign(
checkDevicesUpdatesMixin
);
Object.assign(eWeLink.prototype, regionMixin);
Object.assign(eWeLink.prototype, openWebSocketMixin);
module.exports = eWeLink;

View File

@@ -0,0 +1,27 @@
const { _get } = require('../../lib/helpers');
const regionMixin = {
async getRegion() {
if (!this.email || !this.password) {
return {
error: 406,
msg: 'Library needs to be initialized using email and password',
};
}
const login = await this.login();
const error = _get(login, 'error', false);
if (error) {
return login;
}
return {
email: login.user.email,
region: login.region,
};
},
};
module.exports = regionMixin;

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "ewelink-api",
"version": "1.8.0",
"version": "1.8.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "ewelink-api",
"version": "1.8.0",
"version": "1.8.1",
"description": "eWeLink API for Node.js",
"author": "Martín M.",
"license": "MIT",

View File

@@ -1,6 +1,7 @@
{
"email": "<your ewelink email>",
"password": "<your ewelink password>",
"region": "<your ewelink region>",
"singleChannelDeviceId": "<your device id>",
"deviceIdWithPower": "<your device id>",
"deviceIdWithoutPower": "<your device id>",

View File

@@ -50,6 +50,11 @@ const firmwareExpectations = {
msg: expect.any(String),
};
const regionExpectations = {
email: expect.any(String),
region: expect.any(String),
};
module.exports = {
loginExpectations,
allDevicesExpectations,
@@ -57,4 +62,5 @@ module.exports = {
rawPowerUsageExpectations,
currentMonthPowerUsageExpectations,
firmwareExpectations,
regionExpectations,
};

21
test/user.spec.js Normal file
View File

@@ -0,0 +1,21 @@
const ewelink = require('../main');
const { email, password, region } = require('./_setup/credentials.json');
const { regionExpectations } = require('./_setup/expectations');
describe('check user information', () => {
let connection;
beforeAll(() => {
connection = new ewelink({ email, password });
});
test('region should be returned', async () => {
const response = await connection.getRegion();
expect(response).toMatchObject(regionExpectations);
expect(typeof response).toBe('object');
expect(response.email).toBe(email);
expect(response.region).toBe(region);
});
});