Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Commit

Permalink
style: run prettier
Browse files Browse the repository at this point in the history
[changelog skip]
  • Loading branch information
williamdes committed May 8, 2019
1 parent 5f743b5 commit 1546321
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 100 deletions.
8 changes: 2 additions & 6 deletions db/migrations/20190121114759-data-public-token-alias.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__TokenAliases = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenaliases'
);
const Api__TokenAliases = queryInterface.sequelize.import(__dirname + '/../models/api__tokenaliases');
return Api__TokenAliases.create({
token: 'PuBlIcWGESsra7tbxYsDQ8PQOhMT0KeN',
alias: 'public',
});
},

down: (queryInterface, Sequelize) => {
const Api__TokenAliases = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenaliases'
);
const Api__TokenAliases = queryInterface.sequelize.import(__dirname + '/../models/api__tokenaliases');
return Api__TokenAliases.findOne({
where: {
token: 'PuBlIcWGESsra7tbxYsDQ8PQOhMT0KeN',
Expand Down
8 changes: 2 additions & 6 deletions db/migrations/20190121120428-data-public-api-scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__Scopes = queryInterface.sequelize.import(
__dirname + '/../models/api__scopes'
);
const Api__Scopes = queryInterface.sequelize.import(__dirname + '/../models/api__scopes');
return Api__Scopes.create({
name: 'api.index',
description: 'Api description and status',
});
},

down: (queryInterface, Sequelize) => {
const Api__Scopes = queryInterface.sequelize.import(
__dirname + '/../models/api__scopes'
);
const Api__Scopes = queryInterface.sequelize.import(__dirname + '/../models/api__scopes');
return Api__Scopes.findByPk('api.index').then(model => {
model.destroy();
});
Expand Down
8 changes: 2 additions & 6 deletions db/migrations/20190121122225-data-public-api-token-scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__TokenScopes = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenscopes'
);
const Api__TokenScopes = queryInterface.sequelize.import(__dirname + '/../models/api__tokenscopes');
return Api__TokenScopes.create({
name: 'api.index',
groupName: 'public',
});
},

down: (queryInterface, Sequelize) => {
const Api__TokenScopes = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenscopes'
);
const Api__TokenScopes = queryInterface.sequelize.import(__dirname + '/../models/api__tokenscopes');
return Api__TokenScopes.findOne({
where: {
name: 'api.index',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ module.exports = {
},

down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.query(
'DROP PROCEDURE percentageOfStatusCodesByServer'
);
return queryInterface.sequelize.query('DROP PROCEDURE percentageOfStatusCodesByServer');
},
};
8 changes: 2 additions & 6 deletions db/migrations/20190123151028-data-api-add-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__Scopes = queryInterface.sequelize.import(
__dirname + '/../models/api__scopes'
);
const Api__Scopes = queryInterface.sequelize.import(__dirname + '/../models/api__scopes');
return Api__Scopes.create({
name: 'server.laststatuscode',
description: 'Get last status code from a server',
});
},

down: (queryInterface, Sequelize) => {
const Api__Scopes = queryInterface.sequelize.import(
__dirname + '/../models/api__scopes'
);
const Api__Scopes = queryInterface.sequelize.import(__dirname + '/../models/api__scopes');
return Api__Scopes.findByPk('server.laststatuscode').then(model => {
model.destroy();
});
Expand Down
8 changes: 2 additions & 6 deletions db/migrations/20190123151314-data-api-add-token-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

module.exports = {
up: (queryInterface, Sequelize) => {
const Api__TokenScopes = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenscopes'
);
const Api__TokenScopes = queryInterface.sequelize.import(__dirname + '/../models/api__tokenscopes');
return Api__TokenScopes.create({
name: 'server.laststatuscode',
groupName: 'public',
});
},

down: (queryInterface, Sequelize) => {
const Api__TokenScopes = queryInterface.sequelize.import(
__dirname + '/../models/api__tokenscopes'
);
const Api__TokenScopes = queryInterface.sequelize.import(__dirname + '/../models/api__tokenscopes');
return Api__TokenScopes.findOne({
where: {
name: 'server.laststatuscode',
Expand Down
6 changes: 1 addition & 5 deletions src/api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const serverExists = require('@middlewares/serverExists');
* "statusCode": 200
* }
*/
app.get('/api/10/server/lastStatusCode', serverExists('query', 'id'), function(
req,
res,
next
) {
app.get('/api/10/server/lastStatusCode', serverExists('query', 'id'), function(req, res, next) {
Servers.lastStatusCode(req.query.id)
.then(statusCode => {
res.send({ statusCode: statusCode });
Expand Down
14 changes: 2 additions & 12 deletions src/lib/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ module.exports = {
.then(servers => {
servers.forEach(server => {
if (cron.validate(server.monitoringInterval)) {
logger.debug(
'Server',
server.id,
'scheduled:',
server.monitoringInterval
);
logger.debug('Server', server.id, 'scheduled:', server.monitoringInterval);
serversTasks.push(
cron.schedule(server.monitoringInterval, () => {
Status.getServerStatus(server.url, 'HEAD')
Expand Down Expand Up @@ -63,12 +58,7 @@ module.exports = {
})
);
} else {
logger.debug(
'Server',
server.id,
'has a bad monitoring interval',
server.monitoringInterval
);
logger.debug('Server', server.id, 'has a bad monitoring interval', server.monitoringInterval);
}
});
})
Expand Down
10 changes: 2 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ global.Sentry = require('@sentry/node');

// https://devcenter.heroku.com/articles/dyno-metadata
//TODO: if env empty no append if not empty join array using dash (-)
const envDesc =
'-' +
(process.env.HEROKU_APP_NAME || '') +
'-' +
(process.env.HEROKU_RELEASE_VERSION || '');
const envDesc = '-' + (process.env.HEROKU_APP_NAME || '') + '-' + (process.env.HEROKU_RELEASE_VERSION || '');
const sentryconfig = {
release: packageJson.name + '@' + packageJson.version,
environment: process.env.NODE_ENV + envDesc,
Expand Down Expand Up @@ -68,9 +64,7 @@ app.all('/*', function(req, res, next) {
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(
require('vhost')(process.env.APIDOCS_DOMAIN, express.static(__dirname + '/../apidocs'))
);
app.use(require('vhost')(process.env.APIDOCS_DOMAIN, express.static(__dirname + '/../apidocs')));
app.use(express.static(__dirname + '/../public'));

require('glob')
Expand Down
10 changes: 2 additions & 8 deletions src/static/RequestMid.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,13 @@ const RequestMid = {
},
function(code) {
if (code === 500) {
Sentry.captureMessage(
'Token verification failed.',
Sentry.Severity.Critical
);
Sentry.captureMessage('Token verification failed.', Sentry.Severity.Critical);
return res.status(500).send({
success: false,
message: 'Token verification failed.',
});
} else if (code === 498) {
Sentry.captureMessage(
'Invalid token for requested scope.',
Sentry.Severity.Debug
);
Sentry.captureMessage('Invalid token for requested scope.', Sentry.Severity.Debug);
return res.status(498).send({
success: false,
message: 'Invalid token for requested scope.',
Expand Down
7 changes: 1 addition & 6 deletions src/util/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
const recordStat = function(basicDB, idServer, totalTime, statusCode, onError) {
let d = new Date();
d.setTimezone('UTC');
basicDB.Procedure(
'recordStat(?,?,?,?)',
[idServer, d, totalTime, statusCode],
() => {},
err => onError(err)
);
basicDB.Procedure('recordStat(?,?,?,?)', [idServer, d, totalTime, statusCode], () => {}, err => onError(err));
};

module.exports = {
Expand Down
42 changes: 14 additions & 28 deletions test/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,18 @@ module.exports = function() {
'Test message\nzd\nza\n',
'random\ndata\n',
'Èval\n^ëçç\nza\nsde\n',
'ab'
'ab',
]);
timers.tick('01:00');
sinon.assert.calledTwice(spyTimer);
expect(spyTimer.getCalls()[0].args).to.deep.equal([

]);
expect(spyTimer.getCalls()[0].args).to.deep.equal([]);
expect(spy.getCalls()[0].args).to.deep.equal([
[
"Test message\nzd\nza\n\n--\nrandom\n",
"data\n\n--\nÈval\n^ëçç\nza\nsde\n\n--\n",
"ab"
]
['Test message\nzd\nza\n\n--\nrandom\n', 'data\n\n--\nÈval\n^ëçç\nza\nsde\n\n--\n', 'ab'],
]);
spy.getCalls()[0].args[0].forEach(arg => {
expect(arg.length).to.be.below(31);
});
expect(spy.getCalls()[1].args).to.deep.equal([
[
]
]);
expect(spy.getCalls()[1].args).to.deep.equal([[]]);

done();
});
Expand All @@ -130,30 +121,25 @@ module.exports = function() {
stack.addToStack('[Stats] Just a ping.');
stack.addToStack('[Stats] Just a pong.');
expect(stack.getTasks()).to.deep.equal([
"[Stats] A message for you, server: x is now down.\nAt 01:01:00 YYYY-MM-DD\nBye.",
"[Stats] A message for you, server: x is now up.\nAt 01:02:00 YYYY-MM-DD\nBye.",
"[Stats] Just a ping.",
"[Stats] Just a pong."
'[Stats] A message for you, server: x is now down.\nAt 01:01:00 YYYY-MM-DD\nBye.',
'[Stats] A message for you, server: x is now up.\nAt 01:02:00 YYYY-MM-DD\nBye.',
'[Stats] Just a ping.',
'[Stats] Just a pong.',
]);
timers.tick('01:00');
sinon.assert.calledTwice(spyTimer);
expect(spyTimer.getCalls()[0].args).to.deep.equal([

]);
expect(spyTimer.getCalls()[0].args).to.deep.equal([]);
expect(spy.getCalls()[0].args).to.deep.equal([
[
"[Stats] A message for you, server: x is now down.\nAt 01:01:00 YYYY-MM-DD\nBye.\n--\n[Stats] A message f",
"or you, server: x is now up.\nAt 01:02:00 YYYY-MM-DD\nBye.\n--\n[Stats] Just a ping.\n--\n[Stats] Just a p",
"ong."
]
'[Stats] A message for you, server: x is now down.\nAt 01:01:00 YYYY-MM-DD\nBye.\n--\n[Stats] A message f',
'or you, server: x is now up.\nAt 01:02:00 YYYY-MM-DD\nBye.\n--\n[Stats] Just a ping.\n--\n[Stats] Just a p',
'ong.',
],
]);
spy.getCalls()[0].args[0].forEach(arg => {
expect(arg.length).to.be.below(101);
});
expect(spy.getCalls()[1].args).to.deep.equal([
[
]
]);
expect(spy.getCalls()[1].args).to.deep.equal([[]]);

done();
});
Expand Down

0 comments on commit 1546321

Please sign in to comment.