Simplify configuration for different environments
This commit is contained in:
@@ -5,14 +5,11 @@ require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
const request = require('supertest');
|
||||
const Mongo = require('../../src/dao/mongo');
|
||||
const nodemailer = require('nodemailer');
|
||||
const log = require('npmlog');
|
||||
const config = require('config');
|
||||
const fs = require('fs');
|
||||
const expect = require('chai').expect;
|
||||
const sinon = require('sinon');
|
||||
|
||||
log.level = config.log.level;
|
||||
|
||||
describe('Koa App (HTTP Server) Integration Tests', function() {
|
||||
this.timeout(20000);
|
||||
|
||||
@@ -26,17 +23,7 @@ describe('Koa App (HTTP Server) Integration Tests', function() {
|
||||
|
||||
before(function *() {
|
||||
publicKeyArmored = fs.readFileSync(__dirname + '/../key1.asc', 'utf8');
|
||||
let credentials;
|
||||
try {
|
||||
credentials = require('../../credentials.json');
|
||||
} catch(e) {
|
||||
log.info('app-test', 'No credentials.json found ... using environment vars.');
|
||||
}
|
||||
mongo = new Mongo({
|
||||
uri: process.env.MONGO_URI || credentials.mongo.uri,
|
||||
user: process.env.MONGO_USER || credentials.mongo.user,
|
||||
password: process.env.MONGO_PASS || credentials.mongo.pass
|
||||
});
|
||||
mongo = new Mongo(config.mongo);
|
||||
yield mongo.connect();
|
||||
|
||||
sendEmailStub = sinon.stub().returns(Promise.resolve({ response:'250' }));
|
||||
|
||||
@@ -3,49 +3,27 @@
|
||||
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const log = require('npmlog');
|
||||
const config = require('config');
|
||||
const Email = require('../../src/email/email');
|
||||
const nodemailer = require('nodemailer');
|
||||
const openpgpEncrypt = require('nodemailer-openpgp').openpgpEncrypt;
|
||||
const tpl = require('../../src/email/templates.json');
|
||||
|
||||
log.level = config.log.level;
|
||||
|
||||
describe('Email Integration Tests', function() {
|
||||
this.timeout(20000);
|
||||
|
||||
let email, credentials, userId, origin, publicKeyArmored;
|
||||
let email, userId, origin, publicKeyArmored;
|
||||
|
||||
const recipient = { name:'Test User', email:'safewithme.testuser@gmail.com' };
|
||||
|
||||
before(function() {
|
||||
try {
|
||||
credentials = require('../../credentials.json');
|
||||
} catch(e) {
|
||||
log.info('email-test', 'No credentials.json found ... using environment vars.');
|
||||
}
|
||||
publicKeyArmored = require('fs').readFileSync(__dirname + '/../key1.asc', 'utf8');
|
||||
origin = {
|
||||
protocol: 'http',
|
||||
host: 'localhost:' + config.server.port
|
||||
};
|
||||
email = new Email(nodemailer, openpgpEncrypt);
|
||||
email.init({
|
||||
host: process.env.SMTP_HOST || credentials.smtp.host,
|
||||
port: process.env.SMTP_PORT || credentials.smtp.port,
|
||||
tls: (process.env.SMTP_TLS || credentials.smtp.tls) === 'true',
|
||||
starttls: (process.env.SMTP_STARTTLS || credentials.smtp.starttls) === 'true',
|
||||
pgp: (process.env.SMTP_PGP || credentials.smtp.pgp) === 'true',
|
||||
auth: {
|
||||
user: process.env.SMTP_USER || credentials.smtp.user,
|
||||
pass: process.env.SMTP_PASS || credentials.smtp.pass
|
||||
},
|
||||
sender: {
|
||||
name: process.env.SENDER_NAME || credentials.sender.name,
|
||||
email: process.env.SENDER_EMAIL || credentials.sender.email
|
||||
}
|
||||
});
|
||||
email.init(config.email);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
|
||||
const log = require('npmlog');
|
||||
const config = require('config');
|
||||
const Mongo = require('../../src/dao/mongo');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
@@ -13,17 +13,7 @@ describe('Mongo Integration Tests', function() {
|
||||
let mongo;
|
||||
|
||||
before(function *() {
|
||||
let credentials;
|
||||
try {
|
||||
credentials = require('../../credentials.json');
|
||||
} catch(e) {
|
||||
log.info('mongo-test', 'No credentials.json found ... using environment vars.');
|
||||
}
|
||||
mongo = new Mongo({
|
||||
uri: process.env.MONGO_URI || credentials.mongo.uri,
|
||||
user: process.env.MONGO_USER || credentials.mongo.user,
|
||||
password: process.env.MONGO_PASS || credentials.mongo.pass
|
||||
});
|
||||
mongo = new Mongo(config.mongo);
|
||||
yield mongo.connect();
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
|
||||
const log = require('npmlog');
|
||||
const config = require('config');
|
||||
const openpgp = require('openpgp');
|
||||
const nodemailer = require('nodemailer');
|
||||
@@ -13,8 +12,6 @@ const PublicKey = require('../../src/service/public-key');
|
||||
const expect = require('chai').expect;
|
||||
const sinon = require('sinon');
|
||||
|
||||
log.level = config.log.level;
|
||||
|
||||
describe('Public Key Integration Tests', function() {
|
||||
this.timeout(20000);
|
||||
|
||||
@@ -28,17 +25,7 @@ describe('Public Key Integration Tests', function() {
|
||||
|
||||
before(function *() {
|
||||
publicKeyArmored = require('fs').readFileSync(__dirname + '/../key1.asc', 'utf8');
|
||||
let credentials;
|
||||
try {
|
||||
credentials = require('../../credentials.json');
|
||||
} catch(e) {
|
||||
log.info('mongo-test', 'No credentials.json found ... using environment vars.');
|
||||
}
|
||||
mongo = new Mongo({
|
||||
uri: process.env.MONGO_URI || credentials.mongo.uri,
|
||||
user: process.env.MONGO_USER || credentials.mongo.user,
|
||||
password: process.env.MONGO_PASS || credentials.mongo.pass
|
||||
});
|
||||
mongo = new Mongo(config.mongo);
|
||||
yield mongo.connect();
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require('co-mocha')(require('mocha')); // monkey patch mocha for generators
|
||||
|
||||
const log = require('npmlog');
|
||||
const config = require('config');
|
||||
const UserId = require('../../src/service/user-id');
|
||||
const Mongo = require('../../src/dao/mongo');
|
||||
const expect = require('chai').expect;
|
||||
@@ -15,17 +15,7 @@ describe('User ID Integration Tests', function() {
|
||||
let mongo, userId, uid1, uid2;
|
||||
|
||||
before(function *() {
|
||||
let credentials;
|
||||
try {
|
||||
credentials = require('../../credentials.json');
|
||||
} catch(e) {
|
||||
log.info('user-id-test', 'No credentials.json found ... using environment vars.');
|
||||
}
|
||||
mongo = new Mongo({
|
||||
uri: process.env.MONGO_URI || credentials.mongo.uri,
|
||||
user: process.env.MONGO_USER || credentials.mongo.user,
|
||||
password: process.env.MONGO_PASS || credentials.mongo.pass
|
||||
});
|
||||
mongo = new Mongo(config.mongo);
|
||||
yield mongo.connect();
|
||||
userId = new UserId(mongo);
|
||||
});
|
||||
|
||||
@@ -22,6 +22,30 @@ describe('Util Unit Tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isTrue', () => {
|
||||
it('should be true for "true"', () => {
|
||||
expect(util.isTrue('true')).to.be.true;
|
||||
});
|
||||
it('should be true for true', () => {
|
||||
expect(util.isTrue(true)).to.be.true;
|
||||
});
|
||||
it('should be false for "false"', () => {
|
||||
expect(util.isTrue('false')).to.be.false;
|
||||
});
|
||||
it('should be false for false', () => {
|
||||
expect(util.isTrue(false)).to.be.false;
|
||||
});
|
||||
it('should be true for a random string', () => {
|
||||
expect(util.isTrue('asdf')).to.be.false;
|
||||
});
|
||||
it('should be true for undefined', () => {
|
||||
expect(util.isTrue(undefined)).to.be.false;
|
||||
});
|
||||
it('should be true for null', () => {
|
||||
expect(util.isTrue(null)).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateKeyId', () => {
|
||||
it('should be true for 40 byte hex', () => {
|
||||
expect(util.validateKeyId('0123456789ABCDEF0123456789ABCDEF01234567')).to.be.true;
|
||||
|
||||
Reference in New Issue
Block a user