valence-connect
Version:
Connect to Valence for requests coming from applications running in the Valence Portal
73 lines (65 loc) • 2.08 kB
JavaScript
/**
* Test Services
*/
const tap = require('tap'),
valenceConnect = require('valence-connect'),
customersService = require('../services/customers'),
sessionId = process.env.session;
// perform test(s) if a session id is passed in
//
if (sessionId) {
console.log('Start tests...');
/**
* First initialize valence connect
*/
tap.test('valence-connect init', function(t) {
return valenceConnect.init()
.then(() => {
t.end();
});
});
/**
* Test the Customers "queryAll" Service
*/
tap.test('Get Customers', function(t) {
return customersService.queryAll({
sid : sessionId,
})
.then((resp) => {
// test the response
//
t.equal(resp !== 'undefined', true,
'Invalid response from customersService query all');
// test the response data exists
//
t.equal(resp.data !== 'undefined', true,
'Invalid response from customersService query all because data undefined');
if (resp.data !== 'undefined') {
// test response data is the an array
//
t.equal(Array.isArray(resp.data), true,
'Should get data as an array back');
if (Array.isArray(resp.data)) {
// test that we are getting at least one record back
//
t.equal(resp.data.length > 0, true,
'Should get at least 1 record back');
}
}
// Check if this is an invalid session id
//
if (!resp.success && resp.hdr === 'invalidSession') {
console.log('Invalid Session Passed');
}
t.end();
});
});
} else {
// let the caller know we didn't get a session id passed
//
if (process.platform !== 'win32') {
console.log('Session not found. Example command = session=CURRENTSESSIONID npm test');
} else {
console.log('Session not found. Example command = set session=CURRENTSESSIONID & npm test');
}
}