mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-21 13:23:05 +01:00
* updated dependencies * code linting * added new app id & app secret * cleanup requests payloads * remove unused function * update test cases * enabled firmware tests * refactor getDevice to use right api endpoint * error messages improvements * error messages improvements * error messages improvements * error messages improvements * error messages improvements * payload cleanup * refactor setDevicePowerState to use right api endpoint * update test exepectation * removed deprecated class * updated tests to reflect new error codes * error messages improvements * refactoring project structure: devices methods refactoring project sturcture * refactoring project structure: firmware methods * refactoring project structure: temperature/humidity * refactoring project structure: credentials methods * refactoring project structure: power usage methods * refactoring project structure: power state methods * refactoring project structure: websocket methods * removed deprecated login method from docs * refactoring project structure: power usage methods * refactoring project structure: zeroconf classes * refactoring project structure: websocket classes * refactoring project structure: zeroconf classes * refactor and cleanup * refactoring project structure: firmware methods * moved parsers to own directory * update tests with methods renames * export missing temperature/humidity methods * removed unused package * refactor and cleanup * fix test expectation * refactoring project structure: moved data files * refactoring project structure: moved data files * refactoring project structure: moved helpers files * refactoring project structure: moved helpers files * refactoring project structure: moved payload files * refactor and cleanup * refactor getDevicePowerState * setDevicePowerState returns channel * convert error 400 to 404 for clarity * updated test cases * remove console.log * cache path for zeroconf cache files * installed nock * using nock to simulate server requests during testing * moved credentials file to config folder * update request url when using nock * refactor nock helper file * move cooldown delay to setupTests file * updating testing instructions * restored delete code block * fix wrong error code * accept phone number to login to ewelink * added test cases for initialize main class * improvements on class initialization parameters * allow login using phone number * rename test file * updated test case * fixed regression bug * Release v3.0.0 - use node-fetch (#87) * replaced deprecated request library with node-fetch * refactor: moved makeRequest to own mixin file * refactor to use node-fetch * fixes * update config * created helper method * constant rename * ignore files from final package * version bump
157 lines
4.5 KiB
JavaScript
157 lines
4.5 KiB
JavaScript
const ewelink = require('../main');
|
|
const errors = require('../src/data/errors');
|
|
|
|
describe('main class instantiation: valid parameters combinations', () => {
|
|
test('email and password should initialize class', async () => {
|
|
const credentials = { email: 'user@email.com', password: 'pass' };
|
|
const connection = new ewelink(credentials);
|
|
expect(connection).toEqual({
|
|
region: 'us',
|
|
email: credentials.email,
|
|
phoneNumber: null,
|
|
password: credentials.password,
|
|
apiKey: null,
|
|
arpTable: null,
|
|
at: null,
|
|
devicesCache: null,
|
|
});
|
|
});
|
|
|
|
test('email and password with region should initialize class', async () => {
|
|
const credentials = {
|
|
region: 'cn',
|
|
email: 'user@email.com',
|
|
password: 'pass',
|
|
};
|
|
const connection = new ewelink(credentials);
|
|
expect(connection).toEqual({
|
|
region: 'cn',
|
|
email: credentials.email,
|
|
phoneNumber: null,
|
|
password: credentials.password,
|
|
apiKey: null,
|
|
arpTable: null,
|
|
at: null,
|
|
devicesCache: null,
|
|
});
|
|
});
|
|
|
|
test('phone number and password should initialize class', async () => {
|
|
const credentials = { phoneNumber: '555123789', password: 'pass' };
|
|
const connection = new ewelink(credentials);
|
|
expect(connection).toEqual({
|
|
region: 'us',
|
|
email: null,
|
|
phoneNumber: credentials.phoneNumber,
|
|
password: credentials.password,
|
|
apiKey: null,
|
|
at: null,
|
|
arpTable: null,
|
|
devicesCache: null,
|
|
});
|
|
});
|
|
|
|
test('access token should initialize class', async () => {
|
|
const credentials = { at: 'xxxyyyzzz' };
|
|
const connection = new ewelink(credentials);
|
|
expect(connection).toEqual({
|
|
region: 'us',
|
|
email: null,
|
|
phoneNumber: null,
|
|
password: null,
|
|
apiKey: null,
|
|
at: credentials.at,
|
|
arpTable: null,
|
|
devicesCache: null,
|
|
});
|
|
});
|
|
|
|
test('devices and arp table cache files should initialize class', async () => {
|
|
const credentials = { devicesCache: 'devices', arpTable: 'arptable' };
|
|
const connection = new ewelink(credentials);
|
|
expect(connection).toEqual({
|
|
region: 'us',
|
|
email: null,
|
|
phoneNumber: null,
|
|
password: null,
|
|
apiKey: null,
|
|
at: null,
|
|
arpTable: credentials.arpTable,
|
|
devicesCache: credentials.devicesCache,
|
|
});
|
|
});
|
|
|
|
test('email and access token should initialize class', async () => {
|
|
const credentials = {
|
|
email: 'user@email.com',
|
|
at: 'xxxyyyzzz',
|
|
};
|
|
const connection = new ewelink(credentials);
|
|
expect(connection).toEqual({
|
|
region: 'us',
|
|
email: credentials.email,
|
|
phoneNumber: null,
|
|
password: null,
|
|
apiKey: null,
|
|
at: credentials.at,
|
|
arpTable: null,
|
|
devicesCache: null,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('main class instantiation: invalid parameters combinations', () => {
|
|
test('user and no password should fail', async () => {
|
|
const credentials = { email: 'user@email.com' };
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
|
|
test('only password should fail', async () => {
|
|
const credentials = { password: 'pass' };
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
|
|
test('phone number and no password should fail', async () => {
|
|
const credentials = { phoneNumber: '555123789' };
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
|
|
test('email and phone number should fail', async () => {
|
|
const credentials = { email: 'user@email.com', phoneNumber: '555123789' };
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
|
|
test('email and phone number with password should fail', async () => {
|
|
const credentials = {
|
|
email: 'user@email.com',
|
|
phoneNumber: '555123789',
|
|
password: 'pass',
|
|
};
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
|
|
test('devices cache without arp table should fail', async () => {
|
|
const credentials = { devicesCache: 'devices' };
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
|
|
test('arp table without devices cache should fail', async () => {
|
|
const credentials = { arpTable: 'arptable' };
|
|
expect(() => {
|
|
const connection = new ewelink(credentials);
|
|
}).toThrow(errors.invalidCredentials);
|
|
});
|
|
});
|