Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change calipsoHelper to be async using a finalize function.

  • Loading branch information...
commit 84f3af41cc45a652f7547484cc172e928b6999eb 1 parent ea5777d
@richtera richtera authored
View
21 test/helpers/calipsoHelper.js
@@ -163,12 +163,15 @@ var requests = {
/**
* Initialise everything and then export
*/
-new MockApp(function (app) {
- module.exports = {
- app: app,
- calipso: calipso,
- testPermit: calipso.permission.Helper.hasPermission("test:permission"),
- requests: requests,
- response: CreateResponse()
- }
-})
+module.exports.finalize = function (next) {
+ if (module.exports.app)
+ return next(null, module.exports);
+ new MockApp(function (app) {
+ module.exports.app = app;
+ module.exports.calipso = calipso;
+ module.exports.testPermit = calipso.permission.Helper.hasPermission("test:permission"),
+ module.exports.requests = requests;
+ module.exports.response = CreateResponse();
+ next(null, module.exports);
+ });
+};
View
238 test/lib.calipso.js
@@ -5,133 +5,135 @@ var should = require('should'),
rootpath = process.cwd() + '/',
path = require('path'),
fs = require('fs'),
- calipsoHelper = require('./helpers/calipsoHelper'),
- calipso = calipsoHelper.calipso,
+ helper = require('./helpers/calipsoHelper'),
mochaConfig = path.join(rootpath,'tmp','mocha.json');
//calipso = require('./helpers/require')('calipso');
-describe('Calipso', function(){
-
- before(function(done){
- try { fs.unlinkSync(mochaConfig); } catch(ex) { /** ignore **/ }
- calipso.init(calipsoHelper.app, function(app) {
- done();
- })
- });
-
- describe('Basic loading and initialisation', function(){
-
- it('Calipso has loaded successfully', function(done) {
- calipso.loaded.should.equal(true);
- calipso.modules.should.exist;
- done();
- });
-
- it('I can send a mock request through.', function(done) {
-
- var req = calipsoHelper.requests.testUser,
- res = calipsoHelper.response,
- response = 0,
- routeFn = calipso.routingFn();
-
- req.url = '/';
- res.outputStack = [];
-
- // Over ride the res.end and increment our counter
- res.send = function(content) {
- response++;
- }
-
- routeFn(req, res, function(err) {
- response.should.equal(1);
- res.outputStack.should.eql(['module_first','module_b','module_last']);
- done();
- })
-
- });
-
- it('I can send a mock request through to an invalid route and get a 404', function(done) {
-
- var req = calipsoHelper.requests.testUser,
- res = calipsoHelper.response,
- response = 0,
- routeFn = calipso.routingFn();
-
- req.url = '/invalid.html';
- res.outputStack = [];
-
- // Over ride the res.end and increment our counter
- res.send = function(content) {
- response++;
- }
-
- routeFn(req, res, function(err) {
- response.should.equal(1);
- res.statusCode.should.equal(404);
- res.outputStack.should.eql(['module_first','module_last']);
- done();
- })
-
- });
-
- it('I can send a mock admin request through as an admin user', function(done) {
-
- var req = calipsoHelper.requests.adminUser,
- res = calipsoHelper.response,
- response = 0,
- responseContent = '',
- routeFn = calipso.routingFn();
-
- req.url = '/secured';
- res.outputStack = [];
-
- // Over ride the res.end and increment our counter
- res.send = function(content) {
- responseContent = content;
- response++;
- }
- routeFn(req, res, function(err) {
- response.should.equal(1);
- res.outputStack.should.eql(['module_first','module_a','module_last']);
- responseContent.should.match(/world/);
- done();
- })
- });
-
- it('I can send a mock admin request through and fail as a test user.', function(done) {
- var req = calipsoHelper.requests.anonUser,
- res = calipsoHelper.response,
- response = 0,
- routeFn = calipso.routingFn();
-
- req.cookies = {};
- req.url = '/secured';
- res.outputStack = [];
-
- routeFn(req, res, function(err) {
- res.outputStack.should.eql(['module_first','module_last']);
- req.flashMsgs[0].type.should.equal('error');
- res.redirectQueue.length.should.equal(1);
- res.redirectQueue[0].should.equal('/');
- response.should.equal(0); // Don't match
- done();
- })
+helper.finalize(function (err, calipsoHelper) {
+ var calipso = calipsoHelper.calipso;
+ describe('Calipso', function(){
+
+ before(function(done){
+ try { fs.unlinkSync(mochaConfig); } catch(ex) { /** ignore **/ }
+ calipso.init(calipsoHelper.app, function(app) {
+ done();
+ })
});
-
- it('I can reload the configuration', function(done) {
- calipso.reloadConfig('RELOAD', {}, function(err) {
+
+ describe('Basic loading and initialisation', function(){
+
+ it('Calipso has loaded successfully', function(done) {
+ calipso.loaded.should.equal(true);
calipso.modules.should.exist;
done();
});
+
+ it('I can send a mock request through.', function(done) {
+
+ var req = calipsoHelper.requests.testUser,
+ res = calipsoHelper.response,
+ response = 0,
+ routeFn = calipso.routingFn();
+
+ req.url = '/';
+ res.outputStack = [];
+
+ // Over ride the res.end and increment our counter
+ res.send = function(content) {
+ response++;
+ }
+
+ routeFn(req, res, function(err) {
+ response.should.equal(1);
+ res.outputStack.should.eql(['module_first','module_b','module_last']);
+ done();
+ })
+
+ });
+
+ it('I can send a mock request through to an invalid route and get a 404', function(done) {
+
+ var req = calipsoHelper.requests.testUser,
+ res = calipsoHelper.response,
+ response = 0,
+ routeFn = calipso.routingFn();
+
+ req.url = '/invalid.html';
+ res.outputStack = [];
+
+ // Over ride the res.end and increment our counter
+ res.send = function(content) {
+ response++;
+ }
+
+ routeFn(req, res, function(err) {
+ response.should.equal(1);
+ res.statusCode.should.equal(404);
+ res.outputStack.should.eql(['module_first','module_last']);
+ done();
+ })
+
+ });
+
+ it('I can send a mock admin request through as an admin user', function(done) {
+
+ var req = calipsoHelper.requests.adminUser,
+ res = calipsoHelper.response,
+ response = 0,
+ responseContent = '',
+ routeFn = calipso.routingFn();
+
+ req.url = '/secured';
+ res.outputStack = [];
+
+ // Over ride the res.end and increment our counter
+ res.send = function(content) {
+ responseContent = content;
+ response++;
+ }
+ routeFn(req, res, function(err) {
+ response.should.equal(1);
+ res.outputStack.should.eql(['module_first','module_a','module_last']);
+ responseContent.should.match(/world/);
+ done();
+ })
+ });
+
+ it('I can send a mock admin request through and fail as a test user.', function(done) {
+ var req = calipsoHelper.requests.anonUser,
+ res = calipsoHelper.response,
+ response = 0,
+ routeFn = calipso.routingFn();
+
+ req.cookies = {};
+ req.url = '/secured';
+ res.outputStack = [];
+
+ routeFn(req, res, function(err) {
+ res.outputStack.should.eql(['module_first','module_last']);
+ req.flashMsgs[0].type.should.equal('error');
+ res.redirectQueue.length.should.equal(1);
+ res.redirectQueue[0].should.equal('/');
+ response.should.equal(0); // Don't match
+ done();
+ })
+
+ });
+
+ it('I can reload the configuration', function(done) {
+ calipso.reloadConfig('RELOAD', {}, function(err) {
+ calipso.modules.should.exist;
+ done();
+ });
+ });
+
});
-
+
+ after(function() {
+ try { fs.unlinkSync(mochaConfig); } catch(ex) { /** ignore **/ }
+ })
+
});
-
- after(function() {
- try { fs.unlinkSync(mochaConfig); } catch(ex) { /** ignore **/ }
- })
-
});
-
View
246 test/lib.client.client.js
@@ -5,134 +5,136 @@ var should = require('should'),
fs = require('fs'),
rootpath = process.cwd() + '/',
path = require('path'),
- calipsoHelper = require('./helpers/calipsoHelper'),
- calipso = calipsoHelper.calipso,
- Client = require('./helpers/require')('client/Client');
-
-describe('Client', function(){
-
- before(function(){
- //
- });
-
- describe('Adding scripts', function(){
-
- it('I can add a basic client script', function(done){
- var client = new Client(), script = {name:'test',url:'/test.js',weight:10};
- client.addScript(script);
- client.scripts.length.should.equal(1);
- client.scripts[0].should.equal(script);
- done();
- });
-
- it('If there is no name, it assigns the url as the name', function(done){
- var client = new Client(), script = {url:'/test.js', weight:10}, scriptWithName = {url:'/test.js',weight:10, name:'/test.js'};
- client.addScript(script);
- client.scripts.length.should.equal(1);
- client.scripts[0].should.eql(scriptWithName);
- done();
- });
-
- it('I can add core scripts just by name', function(done){
- var client = new Client(), script = 'calipso', scriptWithName = {key:'calipso', url:'calipso.js',weight:-50, name:'calipso.js'};
- client.addScript(script);
- client.scripts.length.should.equal(1);
- client.scripts[0].should.eql(scriptWithName);
- done();
- });
-
- it('I can add a script just by name', function(done){
- var client = new Client(), script = '/myscript.js', scriptWithName = {url:'/myscript.js',weight:0, name:'/myscript.js'};
- client.addScript(script);
- client.scripts.length.should.equal(1);
- client.scripts[0].should.eql(scriptWithName);
- done();
- });
+ helper = require('./helpers/calipsoHelper');
+helper.finalize(function (err, calipsoHelper) {
+ var calipso = calipsoHelper.calipso,
+ Client = require('./helpers/require')('client/Client');
- it('Adding a script twice does not duplicate it', function(done){
- var client = new Client(), script = {name:'test',url:'/test.js',weight:10};
-
- client.addScript(script);
- client.addScript(script);
-
- client.scripts.length.should.equal(1);
- client.scripts[0].should.equal(script);
- done();
-
- });
-
-
- });
-
- describe('Adding styles', function(){
-
- it('I can add a basic client style', function(done){
- var client = new Client(), style = {name:'test',url:'/test.css',weight:10};
- client.addStyle(style);
- client.styles.length.should.equal(1);
- client.styles[0].should.equal(style);
- done();
- });
-
- it('If there is no name, it assigns the url as the name', function(done){
- var client = new Client(), style = {url:'/test.css', weight:10}, styleWithName = {url:'/test.css',weight:10, name:'/test.css'};
- client.addStyle(style);
- client.styles.length.should.equal(1);
- client.styles[0].should.eql(styleWithName);
- done();
- });
-
- it('I can add a style by just passing in a url', function(done){
- var client = new Client(), style = '/test.css', styleWithName = {url:'/test.css',weight:0, name:'/test.css'};
- client.addStyle(style);
- client.styles.length.should.equal(1);
- client.styles[0].should.eql(styleWithName);
- done();
+ describe('Client', function(){
+
+ before(function(){
+ //
});
-
-
- });
-
- describe('Listing scripts and styles', function(){
-
- it('Listing scripts satisfies the ordering defined', function(done){
- var client = new Client(),
- s1 = {url:'/test1.js', weight:10},
- s2 = {url:'/test2.js', weight:-10};
-
- client.addScript(s1);
- client.addScript(s2);
-
- client.listScripts(function(err, scripts) {
- should.not.exist(err);
- scripts.should.match(/<script title=\"\/test2\.js\" src=\"\/test2\.js\"><\/script>\r\n<script title=\"\/test1\.js\" src=\"\/test1\.js\">/);
+
+ describe('Adding scripts', function(){
+
+ it('I can add a basic client script', function(done){
+ var client = new Client(), script = {name:'test',url:'/test.js',weight:10};
+ client.addScript(script);
+ client.scripts.length.should.equal(1);
+ client.scripts[0].should.equal(script);
done();
- })
-
+ });
+
+ it('If there is no name, it assigns the url as the name', function(done){
+ var client = new Client(), script = {url:'/test.js', weight:10}, scriptWithName = {url:'/test.js',weight:10, name:'/test.js'};
+ client.addScript(script);
+ client.scripts.length.should.equal(1);
+ client.scripts[0].should.eql(scriptWithName);
+ done();
+ });
+
+ it('I can add core scripts just by name', function(done){
+ var client = new Client(), script = 'calipso', scriptWithName = {key:'calipso', url:'calipso.js',weight:-50, name:'calipso.js'};
+ client.addScript(script);
+ client.scripts.length.should.equal(1);
+ client.scripts[0].should.eql(scriptWithName);
+ done();
+ });
+
+ it('I can add a script just by name', function(done){
+ var client = new Client(), script = '/myscript.js', scriptWithName = {url:'/myscript.js',weight:0, name:'/myscript.js'};
+ client.addScript(script);
+ client.scripts.length.should.equal(1);
+ client.scripts[0].should.eql(scriptWithName);
+ done();
+ });
+
+
+ it('Adding a script twice does not duplicate it', function(done){
+ var client = new Client(), script = {name:'test',url:'/test.js',weight:10};
+
+ client.addScript(script);
+ client.addScript(script);
+
+ client.scripts.length.should.equal(1);
+ client.scripts[0].should.equal(script);
+ done();
+
+ });
+
+
});
-
- it('Listing styles satisfies the ordering defined', function(done){
- var client = new Client(),
- s1 = {url:'/test1.css', weight:10},
- s2 = {url:'/test2.css', weight:-10};
-
- client.addStyle(s1);
- client.addStyle(s2);
-
- client.listStyles(function(err, styles) {
- should.not.exist(err);
- styles.should.match(/<link rel=\"stylesheet\" title=\"\/test2\.css\" href=\"\/test2\.css\"\/>\r\n<link rel=\"stylesheet\" title=\"\/test1\.css\" href=\"\/test1\.css\"\/>/);
+
+ describe('Adding styles', function(){
+
+ it('I can add a basic client style', function(done){
+ var client = new Client(), style = {name:'test',url:'/test.css',weight:10};
+ client.addStyle(style);
+ client.styles.length.should.equal(1);
+ client.styles[0].should.equal(style);
done();
- })
-
+ });
+
+ it('If there is no name, it assigns the url as the name', function(done){
+ var client = new Client(), style = {url:'/test.css', weight:10}, styleWithName = {url:'/test.css',weight:10, name:'/test.css'};
+ client.addStyle(style);
+ client.styles.length.should.equal(1);
+ client.styles[0].should.eql(styleWithName);
+ done();
+ });
+
+ it('I can add a style by just passing in a url', function(done){
+ var client = new Client(), style = '/test.css', styleWithName = {url:'/test.css',weight:0, name:'/test.css'};
+ client.addStyle(style);
+ client.styles.length.should.equal(1);
+ client.styles[0].should.eql(styleWithName);
+ done();
+ });
+
+
});
-
+
+ describe('Listing scripts and styles', function(){
+
+ it('Listing scripts satisfies the ordering defined', function(done){
+ var client = new Client(),
+ s1 = {url:'/test1.js', weight:10},
+ s2 = {url:'/test2.js', weight:-10};
+
+ client.addScript(s1);
+ client.addScript(s2);
+
+ client.listScripts(function(err, scripts) {
+ should.not.exist(err);
+ scripts.should.match(/<script title=\"\/test2\.js\" src=\"\/test2\.js\"><\/script>\r\n<script title=\"\/test1\.js\" src=\"\/test1\.js\">/);
+ done();
+ })
+
+ });
+
+ it('Listing styles satisfies the ordering defined', function(done){
+ var client = new Client(),
+ s1 = {url:'/test1.css', weight:10},
+ s2 = {url:'/test2.css', weight:-10};
+
+ client.addStyle(s1);
+ client.addStyle(s2);
+
+ client.listStyles(function(err, styles) {
+ should.not.exist(err);
+ styles.should.match(/<link rel=\"stylesheet\" title=\"\/test2\.css\" href=\"\/test2\.css\"\/>\r\n<link rel=\"stylesheet\" title=\"\/test1\.css\" href=\"\/test1\.css\"\/>/);
+ done();
+ })
+
+ });
+
+ });
+
+ after(function() {
+
+ })
+
});
-
- after(function() {
-
- })
-
});
-
View
383 test/lib.core.event.js
@@ -5,204 +5,207 @@ var should = require('should'),
fs = require('fs'),
rootpath = process.cwd() + '/',
path = require('path'),
- calipsoHelper = require('./helpers/calipsoHelper', true),
- calipso = calipsoHelper.calipso;
- Event = require('./helpers/require')('core/Event');
-
-describe('Events', function () {
-
- before(function () {
- //
- });
-
- describe('General Events', function () {
-
- it('I can create pre and post event emitters and emit an event, with no asynchronous callback', function (done) {
-
- var ee = new Event.CalipsoEventEmitter();
- ee.init();
-
- var eventCount = 0;
-
- ee.addEvent('TEST');
-
- ee.pre('TEST', 'myPreListener', function (event, data) {
- eventCount++;
- });
-
- ee.post('TEST', 'myPostListener', function (event, data) {
- eventCount++;
- });
-
- ee.pre_emit('TEST', {
- data: "data"
- });
- ee.post_emit('TEST', {
- data: "data"
- });
-
- eventCount.should.equal(2);
-
- done();
-
+ helper = require('./helpers/calipsoHelper', true);
+
+helper.finalize(function (err, calipsoHelper) {
+ var calipso = calipsoHelper.calipso;
+ Event = require('./helpers/require')('core/Event');
+
+ describe('Events', function () {
+
+ before(function () {
+ //
});
-
- it('I can create a pre and post event emitters and emit an event, with an asynchronous callback', function (done) {
-
- var ee = new Event.CalipsoEventEmitter();
- ee.init();
-
- var eventCount = 0;
-
- ee.addEvent('TEST');
-
- var callbackFn = function (err, data) {
+
+ describe('General Events', function () {
+
+ it('I can create pre and post event emitters and emit an event, with no asynchronous callback', function (done) {
+
+ var ee = new Event.CalipsoEventEmitter();
+ ee.init();
+
+ var eventCount = 0;
+
+ ee.addEvent('TEST');
+
+ ee.pre('TEST', 'myPreListener', function (event, data) {
eventCount++;
- }
-
- ee.pre('TEST', 'myPreListener', function (event, data, next) {
- eventCount++;
- data.newData = "Pre Hello World";
- next(data);
+ });
+
+ ee.post('TEST', 'myPostListener', function (event, data) {
+ eventCount++;
+ });
+
+ ee.pre_emit('TEST', {
+ data: "data"
+ });
+ ee.post_emit('TEST', {
+ data: "data"
+ });
+
+ eventCount.should.equal(2);
+
+ done();
+
});
-
- ee.post('TEST', 'myPostListener', function (event, data, next) {
- eventCount++;
- data.newData = "Post Hello World";
- next(data);
+
+ it('I can create a pre and post event emitters and emit an event, with an asynchronous callback', function (done) {
+
+ var ee = new Event.CalipsoEventEmitter();
+ ee.init();
+
+ var eventCount = 0;
+
+ ee.addEvent('TEST');
+
+ var callbackFn = function (err, data) {
+ eventCount++;
+ }
+
+ ee.pre('TEST', 'myPreListener', function (event, data, next) {
+ eventCount++;
+ data.newData = "Pre Hello World";
+ next(data);
+ });
+
+ ee.post('TEST', 'myPostListener', function (event, data, next) {
+ eventCount++;
+ data.newData = "Post Hello World";
+ next(data);
+ });
+
+ ee.pre_emit('TEST', {
+ data: "data"
+ }, function (data) {
+ data.newData.should.equal("Pre Hello World");
+ });
+
+ ee.post_emit('TEST', {
+ data: "data"
+ }, function (data) {
+ data.newData.should.equal("Post Hello World");
+ });
+
+ eventCount.should.equal(2);
+
+ done();
+
});
-
- ee.pre_emit('TEST', {
- data: "data"
- }, function (data) {
- data.newData.should.equal("Pre Hello World");
+
+ it('I can create custom events', function (done) {
+
+ var ee = new Event.CalipsoEventEmitter();
+ ee.init();
+
+ var eventCount = 0;
+
+ ee.addEvent('TEST');
+
+ ee.custom('TEST', 'START', 'startListener', function (event, data, next) {
+ eventCount++;
+ data.start = "Started";
+ next(data);
+ });
+
+ ee.custom('TEST', 'FINISH', 'finishListener', function (event, data, next) {
+ eventCount++;
+ data.finish = "Finished";
+ next(data);
+ });
+
+ ee.custom_emit('TEST', 'START', {
+ data: "data"
+ }, function (data) {
+ data.start.should.equal("Started");
+ });
+
+ ee.custom_emit('TEST', 'FINISH', {
+ data: "data"
+ }, function (data) {
+ data.finish.should.equal("Finished");
+ });
+
+ eventCount.should.equal(2);
+
+ done();
+
});
-
- ee.post_emit('TEST', {
- data: "data"
- }, function (data) {
- data.newData.should.equal("Post Hello World");
+
+ it('I can reload events e.g. after a config reload', function (done) {
+
+ var ee = new Event.CalipsoEventEmitter();
+ ee.init();
+
+ ee.addEvent('TEST2');
+ ee.events['TEST2'].should.exist;
+ ee.events['FORM'].should.exist;
+
+ // Re-initialise
+ ee.init();
+ ee.events['TEST2'].should.not.exist;
+ ee.events['FORM'].should.exist;
+
+ done();
+
});
-
- eventCount.should.equal(2);
-
- done();
-
+
});
-
- it('I can create custom events', function (done) {
-
- var ee = new Event.CalipsoEventEmitter();
- ee.init();
-
- var eventCount = 0;
-
- ee.addEvent('TEST');
-
- ee.custom('TEST', 'START', 'startListener', function (event, data, next) {
- eventCount++;
- data.start = "Started";
- next(data);
- });
-
- ee.custom('TEST', 'FINISH', 'finishListener', function (event, data, next) {
- eventCount++;
- data.finish = "Finished";
- next(data);
+
+ describe('Module initialisation events', function () {
+
+ it('I can add a module event listener to a module', function (done) {
+
+ var module = {
+ moduleName: 'test'
+ };
+
+ Event.addModuleEventListener(module);
+
+ module.event._events.should.exist;
+ module.event.init_start.should.exist;
+ module.event.init_finish.should.exist;
+
+ done();
+
});
-
- ee.custom_emit('TEST', 'START', {
- data: "data"
- }, function (data) {
- data.start.should.equal("Started");
- });
-
- ee.custom_emit('TEST', 'FINISH', {
- data: "data"
- }, function (data) {
- data.finish.should.equal("Finished");
- });
-
- eventCount.should.equal(2);
-
- done();
-
- });
-
- it('I can reload events e.g. after a config reload', function (done) {
-
- var ee = new Event.CalipsoEventEmitter();
- ee.init();
-
- ee.addEvent('TEST2');
- ee.events['TEST2'].should.exist;
- ee.events['FORM'].should.exist;
-
- // Re-initialise
- ee.init();
- ee.events['TEST2'].should.not.exist;
- ee.events['FORM'].should.exist;
-
- done();
-
+
});
-
- });
-
- describe('Module initialisation events', function () {
-
- it('I can add a module event listener to a module', function (done) {
-
- var module = {
- moduleName: 'test'
- };
-
- Event.addModuleEventListener(module);
-
- module.event._events.should.exist;
- module.event.init_start.should.exist;
- module.event.init_finish.should.exist;
-
- done();
-
- });
-
- });
-
- describe('Module request events', function () {
-
- it('I can add a module event listener to a request object', function (done) {
-
- var notify = 0, register = 0, req = calipsoHelper.requests.testUser,
- res = calipsoHelper.response,
- re = new Event.RequestEventListener({
- notifyDependencyFn: function() { notify++ }, // Normally to calipso.module.notifyDependenciesOfRoute
- registerDependenciesFn: function() { register++ } // Normally to calipso.module.registerDependencies
- });
-
- re.registerModule(req, res, 'module_a');
-
- // We should be registered, no notifications.
- notify.should.equal(0);
- register.should.equal(1);
- re.modules.module_a.should.exist;
-
- // Fire route start
- re.modules.module_a.route_start();
- re.modules.module_a.route_finish();
-
- // Now have notifications
- notify.should.equal(1);
- re.modules.module_a.routed.should.equal(true);
-
- done();
-
+
+ describe('Module request events', function () {
+
+ it('I can add a module event listener to a request object', function (done) {
+
+ var notify = 0, register = 0, req = calipsoHelper.requests.testUser,
+ res = calipsoHelper.response,
+ re = new Event.RequestEventListener({
+ notifyDependencyFn: function() { notify++ }, // Normally to calipso.module.notifyDependenciesOfRoute
+ registerDependenciesFn: function() { register++ } // Normally to calipso.module.registerDependencies
+ });
+
+ re.registerModule(req, res, 'module_a');
+
+ // We should be registered, no notifications.
+ notify.should.equal(0);
+ register.should.equal(1);
+ re.modules.module_a.should.exist;
+
+ // Fire route start
+ re.modules.module_a.route_start();
+ re.modules.module_a.route_finish();
+
+ // Now have notifications
+ notify.should.equal(1);
+ re.modules.module_a.routed.should.equal(true);
+
+ done();
+
+ });
+
});
-
+
+ after(function () {
+
+ })
+
});
-
- after(function () {
-
- })
-
-});
+});
View
496 test/lib.core.menu.js
@@ -4,268 +4,270 @@
var should = require('should'),
rootpath = process.cwd() + '/',
path = require('path'),
- calipsoHelper = require('./helpers/calipsoHelper'),
- calipso = calipsoHelper.calipso,
- testPermit = calipsoHelper.testPermit,
- Menu = require('./helpers/require')('core/Menu');
-
-/**
- * Test data
- */
-var anonMenuBasic = {name:'Public Menu Item',path:'publicpath',url:'/public'};
-var simpleMenuBasic = {name:'Basic Menu Item',path:'simplepath',url:'/bob',permit:testPermit, order: 1};
-var simpleMenuFull = {name:'Full Menu Item',path:'fullpath',url:'/bill',description:'This is a simple menu',permit:testPermit, order: 2}
-var childMenuShort = {name:'Short Menu Item',path:'simplepath/child',url:'/bob/child',permit:testPermit};
-var childMenuDeep = {name:'Deep Menu Item',path:'simplepath/a/b',url:'/bob/a/b',permit:testPermit};
-var childMenuDeepLater = {name:'Later Menu Item',path:'simplepath/a/b/c',url:'/bob/a/b/c',permit:testPermit};
-
-describe('Menus', function(){
-
- before(function(done){
- calipsoHelper.calipso.loaded.should.equal(true);
- done();
- });
-
- describe('Creating items with correct permissons', function(){
-
- it('I can create a menu, it has default sortby and is root.', function(done){
- var tm = new Menu('MyMenu');
- tm.name.should.equal('MyMenu');
- tm.type.should.equal('root');
- done();
- });
-
- it('I can create a menu, with different sort by', function(done){
- var tm = new Menu('OtherMenu','key');
- tm.name.should.equal('OtherMenu');
- done();
- });
-
- it('I can add a menu item with no permission and it is visible to everyone', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.anonUser;
- tm.addMenuItem(req, anonMenuBasic);
- should.exist(tm.children[anonMenuBasic.path])
- tm.children[anonMenuBasic.path].name.should.equal(anonMenuBasic.name);
- tm.children[anonMenuBasic.path].url.should.equal(anonMenuBasic.url);
- tm.children[anonMenuBasic.path].path.should.equal(anonMenuBasic.path);
-
- done();
-
- });
-
- it('I can add a menu item and it is added to the menu correctly when user has the correct permission', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
- tm.addMenuItem(req, simpleMenuBasic);
- should.exist(tm.children[simpleMenuBasic.path])
- tm.children[simpleMenuBasic.path].name.should.equal(simpleMenuBasic.name);
- tm.children[simpleMenuBasic.path].url.should.equal(simpleMenuBasic.url);
- tm.children[simpleMenuBasic.path].path.should.equal(simpleMenuBasic.path);
- done();
-
- });
-
- it('Adding a menu item without the correct permission does not add the menu item', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.anonUser;
- tm.addMenuItem(req, simpleMenuBasic);
- should.not.exist(tm.children[simpleMenuBasic.path])
+ helper = require('./helpers/calipsoHelper');
+
+helper.finalize(function (err, calipsoHelper) {
+ var calipso = calipsoHelper.calipso,
+ testPermit = calipsoHelper.testPermit,
+ Menu = require('./helpers/require')('core/Menu');
+
+ /**
+ * Test data
+ */
+ var anonMenuBasic = {name:'Public Menu Item',path:'publicpath',url:'/public'};
+ var simpleMenuBasic = {name:'Basic Menu Item',path:'simplepath',url:'/bob',permit:testPermit, order: 1};
+ var simpleMenuFull = {name:'Full Menu Item',path:'fullpath',url:'/bill',description:'This is a simple menu',permit:testPermit, order: 2}
+ var childMenuShort = {name:'Short Menu Item',path:'simplepath/child',url:'/bob/child',permit:testPermit};
+ var childMenuDeep = {name:'Deep Menu Item',path:'simplepath/a/b',url:'/bob/a/b',permit:testPermit};
+ var childMenuDeepLater = {name:'Later Menu Item',path:'simplepath/a/b/c',url:'/bob/a/b/c',permit:testPermit};
+
+ describe('Menus', function(){
+
+ before(function(done){
+ calipsoHelper.calipso.loaded.should.equal(true);
done();
-
- });
-
- it('Administrators can see all menu items', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.adminUser;
- tm.addMenuItem(req, simpleMenuBasic);
- should.exist(tm.children[simpleMenuBasic.path])
- done();
-
- });
-
- it('Admin menus are invisible by default if they have no permit fn defined', function(done){
-
- var tm = new Menu('admin'), req = calipsoHelper.requests.testUser;
- tm.addMenuItem(req, anonMenuBasic);
- should.not.exist(tm.children[anonMenuBasic.path])
- done();
-
- });
-
- it('I can add the same menu twice without adverse effects', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
-
- tm.addMenuItem(req, simpleMenuBasic);
- tm.addMenuItem(req, simpleMenuBasic);
-
- tm.children[simpleMenuBasic.path].name.should.equal(simpleMenuBasic.name);
- tm.children[simpleMenuBasic.path].url.should.equal(simpleMenuBasic.url);
- tm.children[simpleMenuBasic.path].path.should.equal(simpleMenuBasic.path);
-
- done();
-
- });
-
- });
-
- describe('Creating hierarchical menus', function(){
-
- it('I can add a menu with a heirarchical path and get a hierarchy', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
-
- tm.addMenuItem(req, simpleMenuBasic);
- tm.addMenuItem(req, childMenuShort);
-
- // Check created deep heirarchy
- tm.children.simplepath.children.child.name.should.equal(childMenuShort.name);
-
- // Check parent still matches parent url
- tm.children.simplepath.url.should.equal(simpleMenuBasic.url);
-
- done();
-
- });
-
-
- it('I can add a menu with an overlapping heirarchical path and get a hierarchy', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
-
- tm.addMenuItem(req, simpleMenuBasic);
- tm.addMenuItem(req, childMenuShort);
- tm.addMenuItem(req, childMenuDeep);
-
- // Check created deep heirarchy
- tm.children.simplepath.children.child.name.should.equal(childMenuShort.name);
- tm.children.simplepath.children.a.children.b.name.should.equal(childMenuDeep.name);
-
- // Check parent has still has first child url, it is not updated by second menu
- tm.children.simplepath.url.should.equal(simpleMenuBasic.url);
- done();
-
- });
-
-
- it('Creating menus in the wrong order is ok, they get updated', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
-
- tm.addMenuItem(req, childMenuShort);
- tm.addMenuItem(req, simpleMenuBasic);
-
- // Check created deep heirarchy
- tm.children.simplepath.children.child.name.should.equal(childMenuShort.name);
-
- // Check that parent url is set correctly
- tm.children.simplepath.url.should.equal(simpleMenuBasic.url);
-
- done();
-
});
-
- it('Creating menus with an invalid sort defaults to sorting by item name', function(done){
-
- var tm = new Menu('MyMenu','invalid'), req = calipsoHelper.requests.testUser;
-
- // Add in reverse order to what we expect
- tm.addMenuItem(req, simpleMenuFull);
- tm.addMenuItem(req, simpleMenuBasic);
-
- tm.sortedChildren.should.eql([simpleMenuBasic.path, simpleMenuFull.path])
-
- done();
-
- });
-
- it('Creating menus with a non string sort sorts by that directly', function(done){
-
- var tm = new Menu('MyMenu','order'), req = calipsoHelper.requests.testUser;
-
- // Add in reverse order to what we expect
- tm.addMenuItem(req, simpleMenuFull);
- tm.addMenuItem(req, simpleMenuBasic);
-
- tm.sortedChildren.should.eql([simpleMenuBasic.path, simpleMenuFull.path])
-
- done();
-
- });
-
-
-
-
- });
-
- describe('Recursing and displaying menus', function(){
-
- it('I can recursively scan the menu tree', function(done){
-
- var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
- tm.addMenuItem(req, simpleMenuBasic);
- tm.addMenuItem(req, childMenuShort);
- tm.addMenuItem(req, childMenuDeep);
- tm.addMenuItem(req, childMenuDeepLater);
-
- var output = [];
- var menuFn = function(menu) {
- return menu.path;
- }
- tm.fnRecurse(tm,menuFn,output);
-
- output.length.should.equal(5);
- output[0].should.equal(simpleMenuBasic.path);
-
- done();
-
+
+ describe('Creating items with correct permissons', function(){
+
+ it('I can create a menu, it has default sortby and is root.', function(done){
+ var tm = new Menu('MyMenu');
+ tm.name.should.equal('MyMenu');
+ tm.type.should.equal('root');
+ done();
+ });
+
+ it('I can create a menu, with different sort by', function(done){
+ var tm = new Menu('OtherMenu','key');
+ tm.name.should.equal('OtherMenu');
+ done();
+ });
+
+ it('I can add a menu item with no permission and it is visible to everyone', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.anonUser;
+ tm.addMenuItem(req, anonMenuBasic);
+ should.exist(tm.children[anonMenuBasic.path])
+ tm.children[anonMenuBasic.path].name.should.equal(anonMenuBasic.name);
+ tm.children[anonMenuBasic.path].url.should.equal(anonMenuBasic.url);
+ tm.children[anonMenuBasic.path].path.should.equal(anonMenuBasic.path);
+
+ done();
+
+ });
+
+ it('I can add a menu item and it is added to the menu correctly when user has the correct permission', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
+ tm.addMenuItem(req, simpleMenuBasic);
+ should.exist(tm.children[simpleMenuBasic.path])
+ tm.children[simpleMenuBasic.path].name.should.equal(simpleMenuBasic.name);
+ tm.children[simpleMenuBasic.path].url.should.equal(simpleMenuBasic.url);
+ tm.children[simpleMenuBasic.path].path.should.equal(simpleMenuBasic.path);
+ done();
+
+ });
+
+ it('Adding a menu item without the correct permission does not add the menu item', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.anonUser;
+ tm.addMenuItem(req, simpleMenuBasic);
+ should.not.exist(tm.children[simpleMenuBasic.path])
+ done();
+
+ });
+
+ it('Administrators can see all menu items', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.adminUser;
+ tm.addMenuItem(req, simpleMenuBasic);
+ should.exist(tm.children[simpleMenuBasic.path])
+ done();
+
+ });
+
+ it('Admin menus are invisible by default if they have no permit fn defined', function(done){
+
+ var tm = new Menu('admin'), req = calipsoHelper.requests.testUser;
+ tm.addMenuItem(req, anonMenuBasic);
+ should.not.exist(tm.children[anonMenuBasic.path])
+ done();
+
+ });
+
+ it('I can add the same menu twice without adverse effects', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
+
+ tm.addMenuItem(req, simpleMenuBasic);
+ tm.addMenuItem(req, simpleMenuBasic);
+
+ tm.children[simpleMenuBasic.path].name.should.equal(simpleMenuBasic.name);
+ tm.children[simpleMenuBasic.path].url.should.equal(simpleMenuBasic.url);
+ tm.children[simpleMenuBasic.path].path.should.equal(simpleMenuBasic.path);
+
+ done();
+
+ });
+
});
-
- it('I can highlight selected menu items in a tree based on current url matching', function(done){
-
+
+ describe('Creating hierarchical menus', function(){
+
+ it('I can add a menu with a heirarchical path and get a hierarchy', function(done){
+
var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
-
- // Over-ride the url
- req.url = '/bob/child';
-
+
+ tm.addMenuItem(req, simpleMenuBasic);
+ tm.addMenuItem(req, childMenuShort);
+
+ // Check created deep heirarchy
+ tm.children.simplepath.children.child.name.should.equal(childMenuShort.name);
+
+ // Check parent still matches parent url
+ tm.children.simplepath.url.should.equal(simpleMenuBasic.url);
+
+ done();
+
+ });
+
+
+ it('I can add a menu with an overlapping heirarchical path and get a hierarchy', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
+
tm.addMenuItem(req, simpleMenuBasic);
tm.addMenuItem(req, childMenuShort);
tm.addMenuItem(req, childMenuDeep);
- tm.addMenuItem(req, childMenuDeepLater);
-
- var selected = tm.selected(req);
- selected.length.should.equal(2);
- selected[0].should.equal(simpleMenuBasic.path);
- selected[1].should.equal(childMenuShort.path);
+
+ // Check created deep heirarchy
+ tm.children.simplepath.children.child.name.should.equal(childMenuShort.name);
+ tm.children.simplepath.children.a.children.b.name.should.equal(childMenuDeep.name);
+
+ // Check parent has still has first child url, it is not updated by second menu
+ tm.children.simplepath.url.should.equal(simpleMenuBasic.url);
done();
-
+
+ });
+
+
+ it('Creating menus in the wrong order is ok, they get updated', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
+
+ tm.addMenuItem(req, childMenuShort);
+ tm.addMenuItem(req, simpleMenuBasic);
+
+ // Check created deep heirarchy
+ tm.children.simplepath.children.child.name.should.equal(childMenuShort.name);
+
+ // Check that parent url is set correctly
+ tm.children.simplepath.url.should.equal(simpleMenuBasic.url);
+
+ done();
+
+ });
+
+ it('Creating menus with an invalid sort defaults to sorting by item name', function(done){
+
+ var tm = new Menu('MyMenu','invalid'), req = calipsoHelper.requests.testUser;
+
+ // Add in reverse order to what we expect
+ tm.addMenuItem(req, simpleMenuFull);
+ tm.addMenuItem(req, simpleMenuBasic);
+
+ tm.sortedChildren.should.eql([simpleMenuBasic.path, simpleMenuFull.path])
+
+ done();
+
+ });
+
+ it('Creating menus with a non string sort sorts by that directly', function(done){
+
+ var tm = new Menu('MyMenu','order'), req = calipsoHelper.requests.testUser;
+
+ // Add in reverse order to what we expect
+ tm.addMenuItem(req, simpleMenuFull);
+ tm.addMenuItem(req, simpleMenuBasic);
+
+ tm.sortedChildren.should.eql([simpleMenuBasic.path, simpleMenuFull.path])
+
+ done();
+
+ });
+
+
+
+
});
-
- it('I can render a menu as html', function(done){
-
+
+ describe('Recursing and displaying menus', function(){
+
+ it('I can recursively scan the menu tree', function(done){
+
var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
-
tm.addMenuItem(req, simpleMenuBasic);
tm.addMenuItem(req, childMenuShort);
tm.addMenuItem(req, childMenuDeep);
tm.addMenuItem(req, childMenuDeepLater);
-
- // Mock request object
- var html = tm.render(req);
-
- html.should.match(/MyMenu/);
-
+
+ var output = [];
+ var menuFn = function(menu) {
+ return menu.path;
+ }
+ tm.fnRecurse(tm,menuFn,output);
+
+ output.length.should.equal(5);
+ output[0].should.equal(simpleMenuBasic.path);
+
done();
-
+
+ });
+
+ it('I can highlight selected menu items in a tree based on current url matching', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
+
+ // Over-ride the url
+ req.url = '/bob/child';
+
+ tm.addMenuItem(req, simpleMenuBasic);
+ tm.addMenuItem(req, childMenuShort);
+ tm.addMenuItem(req, childMenuDeep);
+ tm.addMenuItem(req, childMenuDeepLater);
+
+ var selected = tm.selected(req);
+ selected.length.should.equal(2);
+ selected[0].should.equal(simpleMenuBasic.path);
+ selected[1].should.equal(childMenuShort.path);
+ done();
+
+ });
+
+ it('I can render a menu as html', function(done){
+
+ var tm = new Menu('MyMenu'), req = calipsoHelper.requests.testUser;
+
+ tm.addMenuItem(req, simpleMenuBasic);
+ tm.addMenuItem(req, childMenuShort);
+ tm.addMenuItem(req, childMenuDeep);
+ tm.addMenuItem(req, childMenuDeepLater);
+
+ // Mock request object
+ var html = tm.render(req);
+
+ html.should.match(/MyMenu/);
+
+ done();
+
+ });
+
+
});
-
-
+
+ after(function() {
+
+ })
+
});
-
- after(function() {
-
- })
-
});
-
View
144 test/lib.core.storage.js-disabled
@@ -5,87 +5,89 @@ var should = require('should'),
fs = require('fs'),
rootpath = process.cwd() + '/',
path = require('path'),
- calipsoHelper = require('./helpers/calipsoHelper'),
- calipso = calipsoHelper.calipso,
+ helper = require('./helpers/calipsoHelper');
+
+helper.finalize(function (err, calipsoHelper) {
+ var calipso = calipsoHelper.calipso,
dbUri,
Storage = require('./helpers/require')('core/Storage');
-describe('Storage', function(){
-
- before(function(done) {
- // These have been disabled due to the linked dependency on calipso itself.
- done();
- });
-
- describe('Core', function(){
-
- it('I can connect to local mongodb in install mode', function(done){
- Storage.mongoConnect('mongodb://localhost/mocha', true, function(err, connected) {
- should.not.exist(err);
- connected.should.equal(false);
+ describe('Storage', function(){
+
+ before(function(done) {
+ // These have been disabled due to the linked dependency on calipso itself.
done();
- });
});
-
- it('Connecting to an invalid server in install mode results in an error', function(done){
- Storage.mongoConnect('mongodb://invalid/mocha', true, function(err, connected) {
- err.should.exist; // Dont check content as this is from Mongoose and may change
- connected.should.equal(false);
- done();
+
+ describe('Core', function(){
+
+ it('I can connect to local mongodb in install mode', function(done){
+ Storage.mongoConnect('mongodb://localhost/mocha', true, function(err, connected) {
+ should.not.exist(err);
+ connected.should.equal(false);
+ done();
+ });
});
- });
-
- it('If not installed, it doesnt actually connect using just mongoConnect but doesnt raise an error', function(done){
- Storage.mongoConnect(function(err, connected) {
- should.not.exist(err);
- connected.should.equal(false);
- done();
+
+ it('Connecting to an invalid server in install mode results in an error', function(done){
+ Storage.mongoConnect('mongodb://invalid/mocha', true, function(err, connected) {
+ err.should.exist; // Dont check content as this is from Mongoose and may change
+ connected.should.equal(false);
+ done();
+ });
});
- });
-
- it('If installed, it does actually connect using just mongoConnect', function(done){
-
- calipso.config.set('installed',true);
- Storage.mongoConnect(function(err, connected) {
- should.not.exist(err);
- connected.should.equal(true);
- done();
+
+ it('If not installed, it doesnt actually connect using just mongoConnect but doesnt raise an error', function(done){
+ Storage.mongoConnect(function(err, connected) {
+ should.not.exist(err);
+ connected.should.equal(false);
+ done();
+ });
});
-
- });
-
- it('If it cant find the session middleware to replace, it fails', function(done){
-
- calipso.config.set('installed',true);
- calipso.app.stack = [];
- Storage.mongoConnect(function(err, connected) {
- should.exist(err);
- err.message.should.equal('Unable to load the MongoDB backed session, please check your session and db configuration');
- connected.should.equal(false);
- done();
+
+ it('If installed, it does actually connect using just mongoConnect', function(done){
+
+ calipso.config.set('installed',true);
+ Storage.mongoConnect(function(err, connected) {
+ should.not.exist(err);
+ connected.should.equal(true);
+ done();
+ });
+
});
-
- });
-
-
- it('If the installed and the server doesnt exist, it fails', function(done){
-
- calipso.config.set('installed',true);
- calipso.config.set('database:uri','mongodb://invalid/mocha');
-
- Storage.mongoConnect(function(err, connected) {
- should.exist(err);
- connected.should.equal(false);
- done();
+
+ it('If it cant find the session middleware to replace, it fails', function(done){
+
+ calipso.config.set('installed',true);
+ calipso.app.stack = [];
+ Storage.mongoConnect(function(err, connected) {
+ should.exist(err);
+ err.message.should.equal('Unable to load the MongoDB backed session, please check your session and db configuration');
+ connected.should.equal(false);
+ done();
+ });
+
});
- });
-
- });
-
- after(function() {
- })
-
+ it('If the installed and the server doesnt exist, it fails', function(done){
+
+ calipso.config.set('installed',true);
+ calipso.config.set('database:uri','mongodb://invalid/mocha');
+
+ Storage.mongoConnect(function(err, connected) {
+ should.exist(err);
+ connected.should.equal(false);
+ done();
+ });
+
+ });
+
+
+ });
+
+ after(function() {
+ })
+
+ });
});
-
View
86 test/lib.core.table.js
@@ -5,50 +5,52 @@ var should = require('should'),
fs = require('fs'),
rootpath = process.cwd() + '/',
path = require('path'),
- calipsoHelper = require('./helpers/calipsoHelper'),
- calipso = calipsoHelper.calipso,
+ helper = require('./helpers/calipsoHelper');
+
+helper.finalize(function (err, calipsoHelper) {
+ var calipso = calipsoHelper.calipso,
table = require('./helpers/require')('core/Table', true);
-var table1 = {id:'1',
- cls:'my-table',
- sort:true,
- columns:[{name:'id',label:'ID'},{name:'name',label:'Name'},{name:'data',label:'Data'}],
- data:[{id:'1',name:'Hello',data:'World'},{id:'2',name:'Goodbye',data:'Again'}],
- view:{
- pager:true,
- from:0,
- limit:10,
- total:50,
- url:'/data',
- sort:[{name:'name',dir:'asc'}]
- }
- };
-
-
-describe('Table', function(){
-
- before(function(){
- // Nothing
- });
-
- describe('Core', function(){
-
-
- it('I can create a table and render it', function(){
-
- var req = calipsoHelper.requests.testUser,
- output = table.render(req, table1);
-
- output.should.match(/my-table/);
- output.should.match(/\/data/);
-
+ var table1 = {id:'1',
+ cls:'my-table',
+ sort:true,
+ columns:[{name:'id',label:'ID'},{name:'name',label:'Name'},{name:'data',label:'Data'}],
+ data:[{id:'1',name:'Hello',data:'World'},{id:'2',name:'Goodbye',data:'Again'}],
+ view:{
+ pager:true,
+ from:0,
+ limit:10,
+ total:50,
+ url:'/data',
+ sort:[{name:'name',dir:'asc'}]
+ }
+ };
+
+
+ describe('Table', function(){
+
+ before(function(){
+ // Nothing
});
-
+
+ describe('Core', function(){
+
+
+ it('I can create a table and render it', function(){
+
+ var req = calipsoHelper.requests.testUser,
+ output = table.render(req, table1);
+
+ output.should.match(/my-table/);
+ output.should.match(/\/data/);
+
+ });
+
+ });
+
+ after(function() {
+
+ })
+
});
-
- after(function() {
-
- })
-
});
-
Please sign in to comment.
Something went wrong with that request. Please try again.