Skip to content

Commit 804e287

Browse files
committed
Upgraded deps, Fixed tests
2 parents ffcc91b + 834d718 commit 804e287

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1351
-1229
lines changed

.remarkignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
test/snapshots/**/*.md
2+
template/test/snapshots/**/*.md
3+
template/test/**/snapshots/**/*.md
24
template/README.md
35
template/locales/README.md

package.json

+25-16
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,22 @@
2020
"template/**/*.test.js"
2121
]
2222
},
23+
"prettier": {
24+
"parser": "babylon",
25+
"printWidth": 100,
26+
"tabWidth": 2,
27+
"useTabs": false,
28+
"semi": true,
29+
"singleQuote": true,
30+
"bracketSpacing": true,
31+
"jsxBracketSameLine": true,
32+
"trailingComma": "none"
33+
},
2334
"bugs": {
2435
"url": "https://github.com/ladjs/lad/issues",
2536
"email": "[email protected]"
2637
},
27-
"contributors": [
28-
"Nick Baugh <[email protected]> (http://niftylettuce.com)"
29-
],
38+
"contributors": ["Nick Baugh <[email protected]> (http://niftylettuce.com)"],
3039
"dependencies": {
3140
"cac": "^4.2.2",
3241
"camelcase": "^4.1.0",
@@ -35,26 +44,26 @@
3544
"is-url": "^1.2.2",
3645
"is-valid-npm-name": "^0.0.4",
3746
"npm-conf": "^1.1.2",
38-
"sao": "^0.22.2",
47+
"sao": "^0.22.3",
3948
"semver": "^5.4.1",
4049
"speakingurl": "^14.0.1",
41-
"superb": "^1.3.0",
42-
"update-notifier": "^2.2.0",
50+
"superb": "^2.0.0",
51+
"update-notifier": "^2.3.0",
4352
"uppercamelcase": "^3.0.0"
4453
},
4554
"devDependencies": {
4655
"ava": "^0.22.0",
4756
"codecov": "^2.3.0",
4857
"cross-env": "^5.0.5",
49-
"eslint": "^4.7.2",
58+
"eslint": "^4.8.0",
5059
"eslint-config-prettier": "^2.6.0",
51-
"eslint-plugin-compat": "^1.0.4",
60+
"eslint-plugin-compat": "^2.0.1",
5261
"eslint-plugin-prettier": "^2.3.1",
5362
"gulp-swagger-js-codegen": "^1.0.0",
5463
"husky": "^0.14.3",
55-
"lint-staged": "^4.2.2",
64+
"lint-staged": "^4.2.3",
5665
"nyc": "^11.2.1",
57-
"prettier": "^1.7.0",
66+
"prettier": "^1.7.4",
5867
"remark-cli": "^4.0.0",
5968
"remark-preset-github": "^0.0.7",
6069
"supertest": "^3.0.0",
@@ -95,11 +104,11 @@
95104
],
96105
"license": "MIT",
97106
"lint-staged": {
98-
"*.{js,jsx,mjs,ts,tsx,css,less,scss,json,graphql}": [
99-
"prettier --write --single-quote --trailing-comma none",
100-
"git add"
101-
],
102-
"*.md": ["remark . -qfo", "git add"]
107+
"*.{js,jsx,mjs,ts,tsx,css,less,scss,json,graphql}": ["prettier --write", "git add"],
108+
"*.md": ["git add"],
109+
"*.md,!test/snapshots/**/*.md,!template/test/snapshots/**/*.md,!template/test/**/*snapshots/**/*.md,!template/README.md,!template/locales/README.md": [
110+
"remark . -qfo"
111+
]
103112
},
104113
"main": "sao.js",
105114
"nyc": {
@@ -137,7 +146,7 @@
137146
"max-len": [
138147
"error",
139148
{
140-
"code": 120,
149+
"code": 100,
141150
"ignoreUrls": true
142151
}
143152
],

sao.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,12 @@ module.exports = {
6060
message: 'What is your GitHub username or organization',
6161
default: ':gitUser:',
6262
store: true,
63-
validate: val =>
64-
githubUsernameRegex.test(val) ? true : 'Invalid GitHub username'
63+
validate: val => (githubUsernameRegex.test(val) ? true : 'Invalid GitHub username')
6564
},
6665
repo: {
6766
message: "What is your GitHub repository's URL",
6867
default(answers) {
69-
return `https://github.com/${slug(answers.username)}/${slug(
70-
slug(answers.name)
71-
)}`;
68+
return `https://github.com/${slug(answers.username)}/${slug(slug(answers.name))}`;
7269
},
7370
validate: val =>
7471
isURL(val) &&

template/.remarkignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
test/snapshots/**/*.md
2+
test/**/snapshots/**/*.md
23
locales/README.md

template/api.js

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env node
12
const http = require('http');
23
const https = require('https');
34
const Koa = require('koa');
@@ -145,8 +146,7 @@ else server = https.createServer(config.ssl.api, app.callback());
145146
if (!module.parent)
146147
server = server.listen(config.ports.api, () =>
147148
logger.info(
148-
`api server listening on ${config.ports
149-
.api} (LAN: ${ip.address()}:${config.ports.api})`
149+
`api server listening on ${config.ports.api} (LAN: ${ip.address()}:${config.ports.api})`
150150
)
151151
);
152152

template/app/controllers/api/v1/users.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@ const retrieve = async ctx => {
88

99
const update = async ctx => {
1010
// set fields we allow to be updated
11-
const fields = [
12-
'email',
13-
'display_name',
14-
'given_name',
15-
'family_name',
16-
'avatar_url'
17-
];
11+
const fields = ['email', 'display_name', 'given_name', 'family_name', 'avatar_url'];
1812

1913
// extend the user object
2014
// (basically overwrites or "extends" the existing fields)

template/app/controllers/web/auth.js

+13-22
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ const signupOrLogin = async ctx => {
2020
// then set it as the returnTo value for when we log in
2121
if (_.isString(ctx.query.return_to) && !s.isBlank(ctx.query.return_to)) {
2222
ctx.session.returnTo = ctx.query.return_to;
23-
} else if (
24-
_.isString(ctx.query.redirect_to) &&
25-
!s.isBlank(ctx.query.redirect_to)
26-
) {
23+
} else if (_.isString(ctx.query.redirect_to) && !s.isBlank(ctx.query.redirect_to)) {
2724
// in case people had a typo, we should support redirect_to as well
2825
ctx.session.returnTo = ctx.query.redirect_to;
2926
}
@@ -34,16 +31,11 @@ const signupOrLogin = async ctx => {
3431
ctx.session.returnTo.indexOf('://') !== -1 &&
3532
ctx.session.returnTo.indexOf(config.urls.web) !== 0
3633
) {
37-
logger.warn(
38-
`Prevented abuse with returnTo hijacking to ${ctx.session.returnTo}`
39-
);
34+
logger.warn(`Prevented abuse with returnTo hijacking to ${ctx.session.returnTo}`);
4035
ctx.session.returnTo = null;
4136
}
4237

43-
ctx.state.verb =
44-
ctx.path.replace(`/${ctx.req.locale}`, '') === '/signup'
45-
? 'sign up'
46-
: 'log in';
38+
ctx.state.verb = ctx.path.replace(`/${ctx.req.locale}`, '') === '/signup' ? 'sign up' : 'log in';
4739

4840
await ctx.render('signup-or-login');
4941
};
@@ -54,8 +46,7 @@ const login = async (ctx, next) => {
5446
return new Promise(async (resolve, reject) => {
5547
if (err) return reject(err);
5648

57-
let redirectTo = `/${ctx.req.locale}${config.auth.callbackOpts
58-
.successReturnToOrRedirect}`;
49+
let redirectTo = `/${ctx.req.locale}${config.auth.callbackOpts.successReturnToOrRedirect}`;
5950

6051
if (ctx.session && ctx.session.returnTo) {
6152
redirectTo = ctx.session.returnTo;
@@ -69,7 +60,7 @@ const login = async (ctx, next) => {
6960
return reject(err);
7061
}
7162

72-
if (ctx.is('json')) {
63+
if (ctx.accepts('json')) {
7364
ctx.body = {
7465
message: ctx.translate('LOGGED_IN'),
7566
redirectTo,
@@ -96,6 +87,9 @@ const login = async (ctx, next) => {
9687
const register = async ctx => {
9788
const { body } = ctx.request;
9889

90+
if (Object.keys(body).length === 0)
91+
return ctx.throw(Boom.badData(ctx.translate('MISSING_REGISTER_FIELDS')));
92+
9993
if (!_.isString(body.email) || !validator.isEmail(body.email))
10094
return ctx.throw(Boom.badRequest(ctx.translate('INVALID_EMAIL')));
10195

@@ -119,7 +113,7 @@ const register = async ctx => {
119113
delete ctx.session.returnTo;
120114
}
121115

122-
if (ctx.is('json')) {
116+
if (ctx.accepts('json')) {
123117
ctx.body = {
124118
message: ctx.translate('REGISTERED'),
125119
redirectTo
@@ -161,7 +155,7 @@ const forgotPassword = async ctx => {
161155
// we always say "a password reset request has been sent to your email"
162156
// and if the email didn't exist in our system then we simply don't send it
163157
if (!user) {
164-
if (ctx.is('json')) {
158+
if (ctx.accepts('json')) {
165159
ctx.body = {
166160
message: ctx.translate('PASSWORD_RESET_SENT')
167161
};
@@ -180,10 +174,7 @@ const forgotPassword = async ctx => {
180174
)
181175
return ctx.throw(
182176
Boom.badRequest(
183-
ctx.translate(
184-
'PASSWORD_RESET_LIMIT',
185-
moment(user.reset_token_expires_at).fromNow()
186-
)
177+
ctx.translate('PASSWORD_RESET_LIMIT', moment(user.reset_token_expires_at).fromNow())
187178
)
188179
);
189180

@@ -195,7 +186,7 @@ const forgotPassword = async ctx => {
195186

196187
await user.save();
197188

198-
if (ctx.is('json')) {
189+
if (ctx.accepts('json')) {
199190
ctx.body = {
200191
message: ctx.translate('PASSWORD_RESET_SENT')
201192
};
@@ -259,7 +250,7 @@ const resetPassword = async ctx => {
259250
} finally {
260251
await user.save();
261252
await util.promisify(ctx.login).bind(ctx.req)(user);
262-
if (ctx.is('json')) {
253+
if (ctx.accepts('json')) {
263254
ctx.body = {
264255
message: ctx.translate('RESET_PASSWORD'),
265256
redirectTo: `/${ctx.req.locale}`

template/app/controllers/web/contact.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ const config = require('../../../config');
1111
module.exports = async function(ctx) {
1212
let { body } = ctx.request;
1313

14+
// @TODO: Remove this once store ip is fixed
15+
if (config.env === 'test') ctx.req.ip = ctx.req.ip || '127.0.0.1';
16+
1417
body = _.pick(body, ['email', 'message']);
1518

1619
if (!_.isString(body.email) || !validator.isEmail(body.email))
1720
return ctx.throw(Boom.badRequest(ctx.translate('INVALID_EMAIL')));
1821

19-
if (!_.isUndefined(body.message) && !_.isString(body.message))
20-
delete body.message;
22+
if (!_.isUndefined(body.message) && !_.isString(body.message)) delete body.message;
2123

2224
if (body.message)
2325
body.message = sanitize(body.message, {
@@ -36,9 +38,16 @@ module.exports = async function(ctx) {
3638
}
3739

3840
// check if we already sent a contact request in the past day
39-
// with this given ip address, otherwise create and email
41+
// with this given ip address or email, otherwise create and email
4042
const count = await Inquiries.count({
41-
ip: ctx.req.ip,
43+
$or: [
44+
{
45+
ip: ctx.req.ip
46+
},
47+
{
48+
email: body.email
49+
}
50+
],
4251
created_at: {
4352
$gte: moment()
4453
.subtract(1, 'day')
@@ -75,7 +84,7 @@ module.exports = async function(ctx) {
7584
ctx.logger.info('queued inquiry email', job);
7685

7786
const message = ctx.translate('CONTACT_REQUEST_SENT');
78-
if (ctx.is('json')) {
87+
if (ctx.accepts('json')) {
7988
ctx.body = { message };
8089
} else {
8190
ctx.flash('success', message);

template/app/models/inquiry.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ const Inquiry = new mongoose.Schema({
2121
message: {
2222
type: String,
2323
required: true,
24-
validate: val =>
25-
_.isString(val) && val.length <= config.contactRequestMaxLength
24+
validate: val => _.isString(val) && val.length <= config.contactRequestMaxLength
2625
},
2726
is_email_only: {
2827
type: Boolean,

template/app/models/plugins/slug.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function SlugPlugin(tmpl = '', ERROR_KEY = 'INVALID_SLUG') {
9393
this.slug = await getUniqueSlug(this.constructor, this._id, this.slug);
9494

9595
// create slug history if it does not exist yet
96-
if (!_.isArray(this.slug_history)) this.slug_history = [];
96+
if (!Array.isArray(this.slug_history)) this.slug_history = [];
9797

9898
// add the slug to the slug_history
9999
this.slug_history.push(this.slug);

template/app/models/user.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ User.pre('validate', function(next) {
102102
if (!_.isString(this.api_token) || s.isBlank(this.api_token))
103103
this.api_token = randomstring.token(24);
104104

105-
if (
106-
_.isString(this.email) &&
107-
(!_.isString(this.display_name) || s.isBlank(this.display_name))
108-
)
105+
if (_.isString(this.email) && (!_.isString(this.display_name) || s.isBlank(this.display_name)))
109106
this.display_name = this.email.split('@')[0];
110107

111108
next();

0 commit comments

Comments
 (0)