cluedin-widget
Version:
This is the project for creating and managing widgets in CluedIn.
93 lines (79 loc) • 2.73 kB
JavaScript
var Bookshelf = require( 'bookshelf' );
var config = require( '../knexfile' );
require( 'should' );
var knex = require( 'knex' )( config.development );
var DB = Bookshelf( knex );
var cluedinWidget = require( '../src/index' )( DB );
var fakeReq = {
cookies: {
token: "test"
}
};
describe( 'Given a cluedin widget', function() {
it( 'should exist', function() {
cluedinWidget.should.exist;
} );
it( 'should have an express method', function() {
cluedinWidget.express.should.exist;
} );
it( 'should have getTokenScript in the express namespace', function() {
cluedinWidget.express.getTokenScript.should.exist;
} );
it( 'should have buildScript in the express namespace', function() {
cluedinWidget.express.buildScript.should.exist;
} );
describe( 'and a getTokenScript method', function() {
it( 'should be sent', function( done ) {
var fakeRes = {
header: function() {
},
send: function( value ) {
value.should.equal( 'var __cluedIn = __cluedIn || {};__cluedIn.token = \'test\';' );
done();
}
};
cluedinWidget.express.getTokenScript( fakeReq, fakeRes );
} );
} );
var widgetData = require( '../src/widgetData' )( DB );
describe( 'Given a widgetData', function() {
it( 'should exist', function() {
widgetData.should.exist;
} );
it( 'should have a widgetData method', function() {
widgetData.getAppropriateWidgetList.should.exist;
} );
it( 'should be able to get a Page', function( done ) {
this.timeout( 5000 );
widgetData.getAppropriateWidgetList( 'page-qltnk8j2', function( err, widgetList ) {
console.log( err );
widgetList[ 0 ].should.equal( 'OnBoarding' );
done();
} );
} );
} );
describe( 'Given a widgetApi', function() {
var req = {
params: {
code: 'page-qltnk8j2'
},
cookies: {
token: 'xxx'
}
};
it( 'should be able to do the full process', function( done ) {
this.timeout( 10000 );
var res = {
send: function() {
done()
},
header: function() {
}
};
cluedinWidget.express.buildScript( req, res );
} );
} );
require( './fileNameBuilder.test' );
require( './widgetFileBuilder.test' );
require( './browserifyWidget.test' );
} );