Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wialon

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wialon - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

test/core.search.test.js

6

lib/core/session.js

@@ -8,9 +8,3 @@

var Session = function ( opts ) {
if ( process.env.NODE_ENV !== 'production' ) {
require( 'request-debug' )( request );
}
this.options( opts );
};

@@ -17,0 +11,0 @@

8

package.json
{
"name": "wialon",
"version": "0.0.5",
"version": "0.0.6",
"description": "NodeJS wrapper for Wialon Remote API",

@@ -22,4 +22,3 @@ "main": "index.js",

"extend": "^2.0.0",
"request": "^2.54.0",
"request-debug": "^0.1.1"
"request": "^2.54.0"
},

@@ -31,4 +30,5 @@ "devDependencies": {

"jshint": "^2.6.3",
"mocha": "^2.2.4"
"mocha": "^2.2.4",
"nock": "^1.6.0"
}
}

@@ -5,8 +5,23 @@ /* jshint expr: true */

var nock = require( 'nock' );
var chai = require( 'chai' );
var expect = chai.expect;
var session = require( '../' ).session();
var wialon = require( '../' );
describe( 'session', function() {
// session object placeholder
var session = {};
beforeEach( function () {
// destroy session data
wialon._session = {};
// create new session object
session = wialon.session();
} );
it( 'should have a wialon object', function() {

@@ -20,3 +35,4 @@ expect( session.wialon ).to.be.an( 'object' );

context( 'endpoint', function () {
describe( 'endpoint', function () {
it( 'should have a default url', function() {

@@ -29,3 +45,11 @@ expect( session._options.url ).to.not.exist;

context( 'start', function () {
describe( 'start', function () {
var credentials = {
username : 'dummy',
password : 'pass'
};
it( 'should validate credentials', function ( done ) {

@@ -38,6 +62,145 @@ session.start( {}, function ( err, data ) {

} );
it( 'should make a login request', function ( done ) {
var scope = nock( session.endpoint() )
.post( '?svc=core/login' )
.reply( 200, { eid : 'cfdf5e9dc900991577c10e3934b6c8f0' } );
session.start( credentials, function ( err, session ) {
expect( err ).to.be.null;
expect( scope.isDone() ).to.be.true;
done();
} );
} );
context( 'when there is no callback', function () {
it( 'should use the internal callback method', function ( done ) {
var scope = nock( session.endpoint() )
.post( '?svc=core/login' )
.reply( 200, { eid : 'cfdf5e9dc900991577c10e3934b6c8f0' } );
session.start( credentials );
done();
} );
} );
context( 'when API credentials are incorrect', function () {
it( 'should return an error object', function ( done ) {
var scope = nock( session.endpoint() )
.post( '?svc=core/login' )
.reply( 200, { error : 8 } );
session.start( credentials, function ( err, sess ) {
expect( err ).to.be.an.instanceof( Error );
expect( err.message ).to.be.string( 'API error: 8' );
done();
} );
} );
} );
} );
describe( 'request', function () {
it( 'should call the endpoint url', function ( done ) {
var svc = 'core/login';
var scope = nock( session.endpoint() )
.post( '?svc=' + svc )
.reply( 200, { error : 0 } );
session.request( svc, {}, function ( err, data ) {
expect( scope.isDone() ).to.be.true;
done();
} );
} );
it( 'should return API errors', function ( done ) {
var svc = 'core/login';
var scope = nock( session.endpoint() )
.post( '?svc=' + svc )
.reply( 200, { error : 8 } );
session.request( svc, {}, function ( err, data ) {
expect( err ).to.be.an.instanceof( Error );
expect( err.message ).to.be.string( 'API error: 8' );
done();
} );
} );
it( 'should validate the session when not making a login request', function ( done ) {
session.request( 'dummy', {}, function ( err, data ) {
expect( err ).to.be.an.instanceof( Error );
expect( err.message ).to.be.string( 'Invalid session' );
done();
} );
} );
context( 'when there is no callback', function () {
it( 'should use the internal callback method', function ( done ) {
var svc = 'core/login';
var scope = nock( session.endpoint() )
.post( '?svc=' + svc )
.reply( 200, { error : 0 } );
session.request( svc, {} );
done();
} );
} );
context( 'when failed to reach the API endpoint', function () {
it( 'should return an error object', function ( done ) {
var svc = 'core/login';
var scope = nock( session.endpoint() )
.post( '?svc=' + svc )
.replyWithError( 'API request failed' );
session.request( svc, {}, function ( err, data ) {
expect( err ).to.be.an.instanceof( Error );
expect( err.message ).to.be.string( 'API request failed' );
// clear all nocks which seems to be needed after replyWithError()
nock.cleanAll();
done();
} );
} );
} );
context( 'when API response is not JSON', function () {
it( 'should return an error object', function ( done ) {
var svc = 'core/login';
var scope = nock( session.endpoint() )
.post( '?svc=' + svc )
.reply( 200, 'not JSON' );
session.request( svc, {}, function ( err, data ) {
expect( err ).to.be.an.instanceof( SyntaxError );
done();
} );
} );
} );
} );
describe( 'end', function () {
it( 'should make a logout request', function ( done ) {
var scope = nock( session.endpoint() )
.post( '?svc=core/logout' )
.reply( 200, { error : 0 } );
// session data mock
session.wialon._session = {
eid : 'cfdf5e9dc900991577c10e3934b6c8f0'
};
session.end( function ( err, data ) {
expect( err ).to.be.null;
expect( scope.isDone() ).to.be.true;
done();
} );
} );
} );
} );
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc