Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper-body-parser-1.17.2
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Jul 6, 2017
2 parents 207da43 + 70b0aea commit 71562b8
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 147 deletions.
4 changes: 3 additions & 1 deletion lib/users/routes.js
Expand Up @@ -65,9 +65,11 @@ const setup = (req, res, next) => {
* @param {object} res - HTTP Response
* @param {object} next - Express callback
*
* @returns {promise} database promise
*
*/
const all = (req, res, next) => {
database.select('*').from('users').then(rows => {
return database.select('*').from('users').then(rows => {
res.render('users/all', {
title: config.users.base,
users: rows,
Expand Down
26 changes: 13 additions & 13 deletions package.json
Expand Up @@ -53,10 +53,10 @@
"connect-ensure-login": "^0.1.1",
"connect-multiparty": "^2.0.0",
"connect-session-knex": "^1.0.23",
"debug": "^2.4.5",
"debug": "^2.6.8",
"express": "^4.14.0",
"express-session": "^1.13.0",
"ibm-design-colors": "^1.8.0",
"express-session": "^1.15.3",
"ibm-design-colors": "^2.0.4",
"input-plugin-checkbox": "^0.3.1",
"input-plugin-email": "^0.2.0",
"input-plugin-file": "^1.2.1",
Expand All @@ -68,38 +68,38 @@
"input-plugin-textarea": "^0.1.3",
"input-plugin-url": "^0.3.0",
"js-yaml": "^3.6.1",
"knex": "^0.12.6",
"knex": "^0.13.0",
"lodash": "^4.17.2",
"map-stream": "^0.0.6",
"mkdirp": "^0.5.1",
"modularscale-sass": "^2.1.1",
"moment": "^2.15.0",
"moment-timezone": "^0.5.4",
"morgan": "^1.6.1",
"morgan": "^1.8.2",
"multer": "^1.2.1",
"multiparty": "^4.1.2",
"node-dir": "^0.1.11",
"node-schedule": "^1.1.1",
"node-dir": "^0.1.17",
"node-schedule": "^1.2.3",
"nodemon": "^1.10.0",
"nunjucks": "^3.0.0",
"nunjucks": "^3.0.1",
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"pg": "^6.0.1",
"pg": "^6.2.3",
"punchcard-content-types": "^6.1.15",
"request": "^2.75.0",
"sass-toolkit": "^2.10.0",
"serve-favicon": "^2.3.0",
"stream-from-array": "^1.0.0",
"underscore.string": "^3.3.4",
"url-join": "^1.1.0",
"url-join": "^2.0.1",
"uuid": "^2.0.2",
"validator": "^6.0.0",
"vinyl": "^2.0.0",
"vinyl-fs": "^2.4.4"
},
"devDependencies": {
"ava": "^0.16.0",
"coveralls": "^2.11.9",
"coveralls": "^2.13.1",
"del": "^2.2.2",
"eslint-config-punchcard": "^1.1.1",
"ghooks": "^2.0.0",
Expand All @@ -108,14 +108,14 @@
"lorem-ipsum": "^1.0.3",
"mock-express-response": "^0.1.2",
"nock": "^9.0.0",
"node-mocks-http": "^1.5.3",
"node-mocks-http": "^1.6.3",
"nyc": "^10.0.0",
"punchcard-commit-msg": "^1.0.0",
"punchcard-runner": "^2.1.2",
"punchcard-semantic-release": "^2.0.3",
"punchcard-shared-tests": "^1.3.0",
"reparo": "^1.1.1-0",
"semantic-release": "^6.3.2",
"semantic-release": "^6.3.6",
"supertest": "^2.0.1",
"tap-difflet": "^0.7.0",
"uuid": "^2.0.2"
Expand Down
2 changes: 1 addition & 1 deletion src/js/app.js
@@ -1,5 +1,5 @@
(function app() {
'use strict';

console.log('Hello World');
console.log('Hello World'); // eslint-disable-line no-console
}());
85 changes: 31 additions & 54 deletions tests/applications.js
Expand Up @@ -356,60 +356,53 @@ test('Send - bad urls', t => {
//////////////////////////////
// Routes - Applications landing
//////////////////////////////
test.cb('All applications route', t => {
test('All applications route', t => {
const request = httpMocks.createRequest(reqObj);

const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
applications.routes.all(request, response);
response.render();
const data = response._getRenderData();
const app = data.applications.find((ap) => {
return ap.name === 'Foo First Application';
});

response.on('end', () => {
const data = response._getRenderData();
const app = data.applications.find((ap) => {
return ap.name === 'Foo First Application';
});

t.is(response.statusCode, 200, 'Should be a 200 response');
t.is(app.name, 'Foo First Application', 'includes form with inputs');

t.is(_.get(app, 'responses.live[0].response', null), 200, 'includes live response');
t.true(_.isDate(new Date(_.get(app, 'responses.live[0].timestamp', null))), 'includes live timestamp which is a date');
t.is(_.get(app, 'responses.updated[0].response', null), 200, 'includes updated response');
t.true(_.isDate(new Date(_.get(app, 'responses.updated[0].timestamp', null))), 'includes updated timestamp which is a date');
t.is(_.get(app, 'responses.sunset[0].response', null), 200, 'includes sunset response');
t.true(_.isDate(new Date(_.get(app, 'responses.sunset[0].timestamp', null))), 'includes sunset timestamp which is a date');
t.is(response.statusCode, 200, 'Should be a 200 response');
t.is(app.name, 'Foo First Application', 'includes form with inputs');

t.end();
});
response.end();
t.is(_.get(app, 'responses.live[0].response', null), 200, 'includes live response');
t.true(_.isDate(new Date(_.get(app, 'responses.live[0].timestamp', null))), 'includes live timestamp which is a date');
t.is(_.get(app, 'responses.updated[0].response', null), 200, 'includes updated response');
t.true(_.isDate(new Date(_.get(app, 'responses.updated[0].timestamp', null))), 'includes updated timestamp which is a date');
t.is(_.get(app, 'responses.sunset[0].response', null), 200, 'includes sunset response');
t.true(_.isDate(new Date(_.get(app, 'responses.sunset[0].timestamp', null))), 'includes sunset timestamp which is a date');
});

//////////////////////////////
// Routes - New Application
//////////////////////////////
test.cb('New application route', t => {
test('New application route', t => {
const req = _.cloneDeep(reqObj);
req.url = '/applications/add';

const request = httpMocks.createRequest(req);

const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
applications.routes.add(request, response);
const resp = applications.routes.add(request, response);
response.render();

response.on('end', () => {
return resp.then(() => {
const data = response._getRenderData();

t.is(response.statusCode, 200, 'Should be a 200 response');
t.true(_.includes(data.form.html, 'name="sunset-endpoint--url"'), 'includes form with inputs');
t.end();
});
});

//////////////////////////////
// Routes - Single application
//////////////////////////////
test.cb('Single application route', t => {
test('Single application route', t => {
const req = _.cloneDeep(reqObj);
req.url = '/applications/1';
req.params.id = 1;
Expand All @@ -420,7 +413,7 @@ test.cb('Single application route', t => {
const resp = applications.routes.one(request, response);
response.render();

response.on('end', () => {
return resp.then(() => {
const data = response._getRenderData();

t.is(response.statusCode, 200, 'Should be a 200 response');
Expand All @@ -435,11 +428,6 @@ test.cb('Single application route', t => {
t.is(data.config.toString(), config.applications.toString(), 'includes config for applications');
t.is(data.app.name, 'Foo First Application', 'includes data from database');
t.is(data.button, 'update', 'includes `update` as text for button');

return resp.then(res => {
t.is(res, true, 'should return true');
t.end();
});
});
});

Expand All @@ -464,7 +452,7 @@ test.cb('Single application route - bad id', t => {
response.render();
});

test.cb('Single application route - error on save', t => {
test('Single application route - error on save', t => {
const req = _.cloneDeep(reqObj);
req.url = '/applications/3';
req.params.id = 3;
Expand All @@ -482,25 +470,23 @@ test.cb('Single application route - error on save', t => {
const request = httpMocks.createRequest(req);

const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
applications.routes.one(request, response);
const resp = applications.routes.one(request, response);
response.render();

response.on('end', () => {
return resp.then(() => {
const data = response._getRenderData();

t.is(response.statusCode, 200, 'Should be a 200 response');

// form shows error
t.regex(data.form.html, /<p class="form--alert" role="alert" for="([0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})">Field is required to be saved!<\/p>/g, 'includes form alert');

t.end();
});
});

//////////////////////////////
// Routes - Secret
//////////////////////////////
test.cb('Create new secret', t => {
test('Create new secret', t => {
const req = _.cloneDeep(reqObj);
req.method = 'POST';
req.headers.referrer = '/applications/1';
Expand All @@ -518,12 +504,11 @@ test.cb('Create new secret', t => {

return resp.then(res => {
t.not(res, dbmocks.rows[0]['client-secret'], 'should be a new client secret');
t.end();
});
});
});

test.cb('Create new secret - bad id kills db', t => {
test('Create new secret - bad id kills db', t => {
const req = _.cloneDeep(reqObj);
req.method = 'POST';
req.headers.referrer = '/applications/break';
Expand All @@ -534,9 +519,8 @@ test.cb('Create new secret - bad id kills db', t => {
const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
const resp = applications.routes.secret(request, response, next);

resp.then(res => {
return resp.then(res => {
t.true(_.includes(res.message, 'update "applications" set "client-secret"'), 'postgres error');
t.end();
});
});

Expand Down Expand Up @@ -565,7 +549,7 @@ test.cb('Create new secret - bad referrer', t => {
//////////////////////////////
// Routes - Save application
//////////////////////////////
test.cb('Save new app: name required', t => {
test('Save new app: name required', t => {
const req = _.cloneDeep(reqObj);
req.method = 'POST';
req.session.referrer = '/applications/add';
Expand All @@ -577,16 +561,13 @@ test.cb('Save new app: name required', t => {

const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
applications.routes.save(request, response);

response.on('end', () => {
t.is(response.statusCode, 302, 'Should be a 302 response');
t.is(response._getRedirectUrl(), '/applications/add');
t.end();
});
response.render();

t.is(response.statusCode, 302, 'Should be a 302 response');
t.is(response._getRedirectUrl(), '/applications/add');
});

test.cb('Save existing app: name required', t => {
test('Save existing app: name required', t => {
const req = _.cloneDeep(reqObj);
req.method = 'POST';
req.session.referrer = '/applications/123';
Expand All @@ -599,12 +580,8 @@ test.cb('Save existing app: name required', t => {
const response = httpMocks.createResponse({ eventEmitter: EventEmitter });
applications.routes.save(request, response);

response.on('end', () => {
t.is(response.statusCode, 302, 'Should be a 302 response');
t.is(response._getRedirectUrl(), '/applications/123');
t.end();
});
response.render();
t.is(response.statusCode, 302, 'Should be a 302 response');
t.is(response._getRedirectUrl(), '/applications/123');
});

test.cb('Delete existing application', t => {
Expand Down

0 comments on commit 71562b8

Please sign in to comment.