Skip to content

Commit

Permalink
♻️ Rename all things to camelCase 🐫
Browse files Browse the repository at this point in the history
  • Loading branch information
jh0ker committed Mar 22, 2018
1 parent 083a8ef commit 5f93c69
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fetch_users.js
fetchUsers.js
coverage
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"no-console": "off",
"no-extra-parens": "error",
"valid-jsdoc": [
2,
"error",
{
"requireParamDescription": false,
"requireReturnDescription": false,
Expand Down Expand Up @@ -56,7 +56,7 @@
"always"
],
"brace-style": "error",
"camelcase": 0,
"camelcase": "error",
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
Expand All @@ -67,7 +67,7 @@
"keyword-spacing": "error",
"linebreak-style": "error",
"max-len": [
"error",
"error",
{
"code": 100,
"ignoreUrls": true,
Expand Down
18 changes: 9 additions & 9 deletions config/env.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const { tableEnv } = require('./dynamodb');
const { fetch_env, getStage, required_env } = require('./util');
const { fetchEnv, getStage, requiredEnv } = require('./util');
const resources = require('./resources');

module.exports.env = () => {
let env_cache;
return fetch_env()
let envCache;
return fetchEnv()
.then(env => {
const missing_env = required_env.filter(name => !(name in env));
if (missing_env.length > 0) {
throw new Error(`Missing environment variables: ${missing_env.join(', ')}`);
const missingEnv = requiredEnv.filter(name => !(name in env));
if (missingEnv.length > 0) {
throw new Error(`Missing environment variables: ${missingEnv.join(', ')}`);
}
env_cache = env;
envCache = env;
return getStage();
})
.then(tableEnv)
.then(tableEnv => Object.assign(env_cache, tableEnv));
.then(tableEnv => Object.assign(envCache, tableEnv));
};

module.exports.stage = getStage;

module.exports.enableDomain = () => fetch_env()
module.exports.enableDomain = () => fetchEnv()
.then(env => 'DEPLOY_ALIAS' in env || 'SLS_STAGE' in process.env);

module.exports.resources = resources;
12 changes: 6 additions & 6 deletions config/prepare-ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

const fs = require('fs');
const path = require('path');
const { load_s3 } = require('./util');
const { loadS3 } = require('./util');

const df_service_account = () => {
const save_file = content => fs.writeFile(
const dfServiceAccount = () => {
const saveFile = content => fs.writeFile(
path.resolve(__dirname, '../.df_id.json'),
content,
{ encoding: 'UTF-8' },
() => console.log("DF Service Account written.")
);

if ('CI' in process.env){
return load_s3('df_id.json').then(save_file);
return loadS3('df_id.json').then(saveFile);
}

if (!('DF_SERVICE_ACCOUNT' in process.env)) {
throw new Error("DF Service Account JSON is missing!");
}
save_file(process.env.DF_SERVICE_ACCOUNT);
saveFile(process.env.DF_SERVICE_ACCOUNT);
};

const prepare = function() {
df_service_account();
dfServiceAccount();
};

module.exports = prepare;
Expand Down
34 changes: 17 additions & 17 deletions config/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const request = require('request-promise-native');
const S3 = require('aws-sdk/clients/s3');

const required_env = [
const requiredEnv = [
'FB_PAGETOKEN',
'FB_VERIFYTOKEN',
'DF_PROJECTID',
Expand All @@ -23,7 +23,7 @@ const loadConfig = () => {
});
};

const load_s3 = (filename, json = false) => {
const loadS3 = (filename, json = false) => {
const branch = process.env.TRAVIS_BRANCH || process.env.BRANCH;
const s3client = new S3({ region: 'eu-central-1' });
const s3path = `${branch}/${filename}`;
Expand All @@ -38,44 +38,44 @@ const load_s3 = (filename, json = false) => {
});
};

let env_cache = null;
const fetch_env = () => {
if (env_cache) {
return Promise.resolve(env_cache);
let envCache = null;
const fetchEnv = () => {
if (envCache) {
return Promise.resolve(envCache);
}

if ('CI' in process.env){
return load_s3('env.json', true)
return loadS3('env.json', true)
.then(env => {
env_cache = env;
envCache = env;
return env;
});
}

const dotenv_path = path.resolve(__dirname, "../.env.yml");
const dotenvPath = path.resolve(__dirname, "../.env.yml");
const environment = {};
if (fs.existsSync(dotenv_path)) {
Object.assign(environment, yaml.safeLoad(fs.readFileSync(dotenv_path, 'utf8')));
if (fs.existsSync(dotenvPath)) {
Object.assign(environment, yaml.safeLoad(fs.readFileSync(dotenvPath, 'utf8')));
}

required_env.forEach(key => {
requiredEnv.forEach(key => {
if (key in process.env) {
environment[key] = process.env[key];
}
});

env_cache = environment;
envCache = environment;
return Promise.resolve(environment);
};

const getStage = () => {
return fetch_env().then(env => process.env.SLS_STAGE || env['DEPLOY_ALIAS'] || 'dev');
return fetchEnv().then(env => process.env.SLS_STAGE || env['DEPLOY_ALIAS'] || 'dev');
};

module.exports = {
fetch_env,
fetchEnv: fetchEnv,
loadConfig,
load_s3,
loadS3: loadS3,
getStage,
required_env,
requiredEnv: requiredEnv,
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { Expect } = require("../../lib/testing");
const facebook = require("../../lib/facebook");

const current_news = require("../action_current_news");
const currentNews = require("../actionCurrentNews");

describe("action_current_news", () => {
describe("actionCurrentNews", () => {
it("sends a specific message with a button", () => {
// e4d4c2941dd54f549393e9c3384e2d10900d36c7
const chat = new facebook.Chat();
return current_news(chat).then(() => {
return currentNews(chat).then(() => {
new Expect(chat).buttons(
"Hey, alles klar bei dir? Dein Informant ist wieder hier - und das habe ich für dich:\n" +
"➡ Luft in einigen NRW-Städten ist besser geworden\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { Expect } = require("../../lib/testing");
const facebook = require("../../lib/facebook");

const current_time = require("../action_current_time");
const currentTime = require("../actionCurrentTime");

describe("action_current_time", () => {
describe("actionCurrentTime", () => {
it("sends a message that contains a time", () => {
const chat = new facebook.Chat();
return current_time(chat).then(() => {
return currentTime(chat).then(() => {
new Expect(chat).text(/Die exakte Uhrzeit lautet: \d\d:\d\d:\d\d/);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { Expect } = require("../../lib/testing");
const facebook = require("../../lib/facebook");

const payload_faq = require("../payload_faq");
const payloadFaq = require("../payloadFaq");

describe("payload_faq", () => {
describe("payloadFaq", () => {
it("sends a specific faq", () => {
// 371aead7acd8321bb6e576903f06a60f429ab295
const chat = new facebook.Chat();
return payload_faq(chat, {slug: "foo"}).then(() => {
return payloadFaq(chat, {slug: "foo"}).then(() => {
new Expect(chat).text("Foo", []);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { Expect } = require("../../lib/testing");
const facebook = require("../../lib/facebook");
const payloadSubscribe = require("../payload_subscribe");
const payloadSubscribe = require("../payloadSubscribe");

const tableName = process.env.DYNAMODB_SUBSCRIPTIONS;

describe("payload_subscribe.subscribe", () => {
describe("payloadSubscribe.subscribe", () => {
// dynamodb: c3a20f370fae4beafdde6af472ff8bf63da9ef9b
it("adds appropriate labels and replies with the correct text", () => {
const chat = new facebook.Chat({sender: {id: "1"}});
Expand Down Expand Up @@ -33,7 +33,7 @@ describe("payload_subscribe.subscribe", () => {
});
});

describe("payload_subscribe.unsubscribe", () => {
describe("payloadSubscribe.unsubscribe", () => {
// dynamodb.update: 67136336f73537cfd8a1fede6db932bd94d20423
// dynamodb.delete: 8779f7a74ed5e22f4aa569488b6779eb2bd1618f
it("removes appropriate labels and replies with the correct text", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const request = require('request-promise-native');
const urls = require('../lib/urls');


const current_news = chat => {
const currentNews = chat => {
return request({
uri: urls.pushes,
json: true,
Expand All @@ -29,4 +29,4 @@ const current_news = chat => {
});
};

module.exports = current_news;
module.exports = currentNews;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const moment = require('moment-timezone');

const current_time = chat => {
const currentTime = chat => {
const time = moment.tz('Europe/Berlin').format('HH:mm:ss');
return chat.sendText(`Die exakte Uhrzeit lautet: ${time}`);
};

module.exports = current_time;
module.exports = currentTime;
24 changes: 12 additions & 12 deletions handler/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

module.exports = {
actions: {
current_time: require('./action_current_time'),
current_news: require('./action_current_news'),
subscriptions: require('./payload_subscribe').subscriptions,
'current_time': require('./actionCurrentTime'),
'current_news': require('./actionCurrentNews'),
'subscriptions': require('./payloadSubscribe').subscriptions,
},
payloads: {
report_start: require('./payload_report_start'),
fragment_next: require('./payload_fragment_next'),
faq: require('./payload_faq'),
pushOutro: require('./payloadPushOutro'),
subscriptions: require('./payload_subscribe').subscriptions,
subscribe: require('./payload_subscribe').subscribe,
unsubscribe: require('./payload_subscribe').unsubscribe,
share: require('./payload_share.js'),
current_news: require('./action_current_news'),
'report_start': require('./payloadReportStart'),
'fragment_next': require('./payloadFragmentNext'),
'faq': require('./payloadFaq'),
'push_outro': require('./payloadPushOutro'),
'subscriptions': require('./payloadSubscribe').subscriptions,
'subscribe': require('./payloadSubscribe').subscribe,
'unsubscribe': require('./payloadSubscribe').unsubscribe,
'share': require('./payloadShare.js'),
'current_news': require('./actionCurrentNews'),
},
};
6 changes: 3 additions & 3 deletions handler/payload_faq.js → handler/payloadFaq.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const request = require('request-promise-native');
const urls = require('../lib/urls');
const fragmentSender = require('../lib/fragmentSender');

const faq_start = (chat, payload) => {
const faqStart = (chat, payload) => {
const url = `${urls.faqBySlug(payload.slug)}`;

return request({uri: url, json: true}).then( faq => {

if (typeof faq[0] == 'undefined') {
if (faq[0] === undefined) {
chat.sendText(`Dazu habe ich noch keine Info...🤔`);
return;
}
Expand All @@ -17,4 +17,4 @@ const faq_start = (chat, payload) => {
});
};

module.exports = faq_start;
module.exports = faqStart;
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const request = require('request');
const urls = require('../lib/urls');
const fragmentSender = require('../lib/fragmentSender');

const fragment_next = (chat, payload) => {
const fragmentNext = (chat, payload) => {
let url = null;
if (payload.type == 'push') {
if (payload.type === 'push') {
url = `${urls.reportFragment(payload.fragment)}?withNext=yes`;
} else if (payload.type == 'faq') {
} else if (payload.type === 'faq') {
url = `${urls.faqFragment(payload.fragment)}?withNext=yes`;
}

Expand All @@ -22,4 +22,4 @@ const fragment_next = (chat, payload) => {
}
};

module.exports = fragment_next;
module.exports = fragmentNext;
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const request = require('request');
const urls = require('../lib/urls');
const fragmentSender = require('../lib/fragmentSender');

const report_start = (chat, payload) => {
const reportStart = (chat, payload) => {
request(`${urls.report(payload.report)}?withFragments=1`, (error, res, body) => {
const report = JSON.parse(body);

fragmentSender(chat, report.next_fragments, payload, report.text, report.media);
})
};

module.exports = report_start;
module.exports = reportStart;
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5f93c69

Please sign in to comment.