Merge branch 'api-v3' into api-v3-i18n

This commit is contained in:
Blade Barringer
2015-11-13 10:49:21 -06:00
6 changed files with 40 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@ module.exports = {
strings: null,
translations: {},
t: function(stringName) {
var clonedVars, e, locale, string, stringNotFound, vars;
var clonedVars, e, error, error1, locale, string, stringNotFound, vars;
vars = arguments[1];
if (_.isString(arguments[1])) {
vars = null;
@@ -27,9 +27,9 @@ module.exports = {
clonedVars.locale = locale;
if (string) {
try {
return _.template(string, clonedVars);
} catch (_error) {
e = _error;
return _.template(string)(clonedVars);
} catch (error) {
e = error;
return 'Error processing the string. Please see Help > Report a Bug.';
}
} else {
@@ -39,11 +39,11 @@ module.exports = {
stringNotFound = module.exports.translations[locale] && module.exports.translations[locale].stringNotFound;
}
try {
return _.template(stringNotFound, {
return _.template(stringNotFound)({
string: stringName
});
} catch (_error) {
e = _error;
} catch (error1) {
e = error1;
return 'Error processing the string. Please see Help > Report a Bug.';
}
}

View File

@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import autoinc from 'mongoose-id-autoinc';
import logging from '../website/src/libs/api-v2/logging';
import logger from '../website/src/libs/api-v3/logger';
import nconf from 'nconf';
import utils from '../website/src/libs/utils';
import repl from 'repl';
@@ -36,7 +36,7 @@ let improveRepl = (context) => {
mongooseOptions,
function(err) {
if (err) throw err;
logging.info('Connected with Mongoose');
logger.info('Connected with Mongoose');
}
)
);

View File

@@ -5,10 +5,10 @@ import {
} from '../../../../helpers/api-unit.helper';
import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService'
import nconf from 'nconf';
import attachAnalytics from '../../../../../website/src/middlewares/api-v3/analytics';
describe('analytics middleware', function() {
let res, req, next;
let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics';
beforeEach(() => {
res = generateRes();
@@ -16,17 +16,40 @@ describe('analytics middleware', function() {
next = generateNext();
});
afterEach(() => {
// The nconf.get('IS_PROD') occurs when the file is required
// Since node caches IS_PROD, we have to delete it from the cache
// to test prod vs non-prod behaviors
delete require.cache[require.resolve(pathToAnalyticsMiddleware)];
});
it('attaches analytics object res.locals', function() {
let attachAnalytics = require(pathToAnalyticsMiddleware);
attachAnalytics(req, res, next);
expect(res.analytics).to.exist;
});
it('attaches stubbed methods for non-prod environments', () => {
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(false);
let attachAnalytics = require(pathToAnalyticsMiddleware);
attachAnalytics(req, res, next);
expect(res.analytics.track).to.eql(analyticsService.mockAnalyticsService.track);
expect(res.analytics.trackPurchase).to.eql(analyticsService.mockAnalyticsService.trackPurchase);
});
it('attaches real methods for prod environments', () => {
sandbox.stub(nconf, 'get').withArgs('IS_PROD').returns(true);
let attachAnalytics = require(pathToAnalyticsMiddleware);
attachAnalytics(req, res, next);
expect(res.analytics.track).to.eql(analyticsService.track);
expect(res.analytics.trackPurchase).to.eql(analyticsService.trackPurchase);
});
});

View File

@@ -4,7 +4,7 @@ require('babel/register');
// Only do the minimal amount of work before forking just in case of a dyno restart
var cluster = require('cluster');
var nconf = require('nconf');
var logging = require('./libs/api-v2/logging');
var logger = require('./libs/api-v3/logger');
// Initialize configuration
var setupNconf = require('./libs/api-v3/setupNconf');
@@ -26,7 +26,7 @@ if (cores !== 0 && cluster.isMaster && (IS_DEV || IS_PROD)) {
cluster.on('disconnect', (worker) => {
var w = cluster.fork(); // replace the dead worker
logging.info('[%s] [master:%s] worker:%s disconnect! new worker:%s fork', new Date(), process.pid, worker.process.pid, w.process.pid);
logger.info('[%s] [master:%s] worker:%s disconnect! new worker:%s fork', new Date(), process.pid, worker.process.pid, w.process.pid);
});
} else {
module.exports = require('./server.js');

View File

@@ -1,7 +1,7 @@
// TODO cleanup all comments when finished API v3
import nconf from 'nconf';
import logging from './libs/api-v2/logging';
import logger from './libs/api-v3/logger';
import utils from './libs/utils';
import express from 'express';
import http from 'http';
@@ -37,7 +37,7 @@ let mongooseOptions = !IS_PROD ? {} : {
};
let db = mongoose.connect(nconf.get('NODE_DB_URI'), mongooseOptions, (err) => {
if (err) throw err;
logging.info('Connected with Mongoose');
logger.info('Connected with Mongoose');
});
autoinc.init(db);
@@ -158,7 +158,7 @@ oldApp.use(require('./middlewares/errorHandler'));
server.on('request', app);
server.listen(app.get('port'), () => {
return logging.info(`Express server listening on port ${app.get('port')}`);
return logger.info(`Express server listening on port ${app.get('port')}`);
});
export default server;