From 7107bab6147977c600a5768b69afc9aed6272c97 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Tue, 21 Nov 2017 09:58:44 -0800 Subject: [PATCH] added support for custom smtp server in setup script --- app/libs/constants.js | 38 +++++ config/env/all.js | 2 +- config/express.js | 1 - package-lock.json | 5 + scripts/setup.js | 215 ++++++++++++++++++---------- selenium/.editorconfig | 17 +++ selenium/.gitignore | 9 ++ selenium/.vscode/launch.json | 27 ++++ selenium/README.md | 28 ++++ selenium/commons/commons.md | 1 + selenium/config.json | 14 ++ selenium/hosts | 0 selenium/install.sh | 4 + selenium/package.json | 25 ++++ selenium/run.bat | 7 + selenium/run.sh | 5 + selenium/screenshots/screenshots.md | 1 + selenium/uploadfiles/uploadfiles.md | 1 + 18 files changed, 321 insertions(+), 79 deletions(-) create mode 100644 selenium/.editorconfig create mode 100644 selenium/.gitignore create mode 100644 selenium/.vscode/launch.json create mode 100644 selenium/README.md create mode 100644 selenium/commons/commons.md create mode 100644 selenium/config.json create mode 100644 selenium/hosts create mode 100644 selenium/install.sh create mode 100644 selenium/package.json create mode 100644 selenium/run.bat create mode 100644 selenium/run.sh create mode 100644 selenium/screenshots/screenshots.md create mode 100644 selenium/uploadfiles/uploadfiles.md diff --git a/app/libs/constants.js b/app/libs/constants.js index 9b64918c..3771e0db 100644 --- a/app/libs/constants.js +++ b/app/libs/constants.js @@ -1,6 +1,44 @@ 'use strict'; module.exports = { + + + nodemailer_providers: [ + '1und1', + 'AOL', + 'DebugMail.io', + 'DynectEmail', + 'FastMail', + 'GandiMail', + 'Gmail', + 'Godaddy', + 'GodaddyAsia', + 'GodaddyEurope', + 'hot.ee', + 'Hotmail', + 'iCloud', + 'mail.ee', + 'Mail.ru', + 'Mailgun', + 'Mailjet', + 'Mandrill', + 'Naver', + 'OpenMailBox', + 'Postmark', + 'QQ', + 'QQex', + 'SendCloud', + 'SendGrid', + 'SES', + 'SES-US-EAST-1', + 'SES-US-WEST-1', + 'SES-EU-WEST-1', + 'Sparkpost', + 'Yahoo', + 'Yandex', + 'Zoho' + ], + extraneousFormFieldProps: [ 'validFieldTypes', 'disabled', diff --git a/config/env/all.js b/config/env/all.js index bf0cc22b..27dd00d2 100755 --- a/config/env/all.js +++ b/config/env/all.js @@ -17,7 +17,7 @@ module.exports = { }, - admin:{ + admin: { email: process.env.ADMIN_EMAIL || 'admin@admin.com', username: process.env.ADMIN_USERNAME || 'root', password: process.env.ADMIN_PASSWORD || 'root', diff --git a/config/express.js b/config/express.js index febb14c1..87b84bd7 100755 --- a/config/express.js +++ b/config/express.js @@ -232,7 +232,6 @@ module.exports = function(db) { // CookieParser should be above session app.use(cookieParser()); - debugger; // Express MongoDB session storage app.use(session({ saveUninitialized: true, diff --git a/package-lock.json b/package-lock.json index 8516edc5..ebd0238c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9857,6 +9857,11 @@ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.0.1.tgz", "integrity": "sha1-uVhksH+s7oKH6CMu/9bx1W7HWrI=" }, + "nodemailer-wellknown": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/nodemailer-wellknown/-/nodemailer-wellknown-0.2.3.tgz", + "integrity": "sha1-ZA7SBKAWYnZD+Yc5qU+O+dOcoKk=" + }, "nodemon": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.12.1.tgz", diff --git a/scripts/setup.js b/scripts/setup.js index 1fb48f61..d8be5236 100644 --- a/scripts/setup.js +++ b/scripts/setup.js @@ -10,7 +10,8 @@ var config = require('../config/config'), inquirer = require('inquirer'), envfile = require('envfile'), fs = require('fs-extra'), - chalk = require('chalk'); + chalk = require('chalk'), + _ = require('lodash'); // Bootstrap db connection var db = mongoose.connect(config.db.uri, config.db.options, function(err) { @@ -34,6 +35,7 @@ var User = mongoose.model('User'); require('../app/models/user.server.model.js'); var nodemailer_providers = [ + 'Custom Mailserver', '1und1', 'AOL', 'DebugMail.io', @@ -69,16 +71,20 @@ var nodemailer_providers = [ 'Zoho' ]; -var bool_options = [ - "TRUE", - "FALSE" -]; +var replaceENVQuestion = { + type: 'confirm', + name: 'replaceENVFile', + message: 'An older .env file already exists. Do you want to replace it?', + default: false +}; -var questions = [ +var questionsPart1 = [ { - type: 'confirm', - name: 'shouldContinue', - message: 'Do you wish to configure your deployment now?' + type: 'list', + name: 'NODE_ENV', + message: 'What mode do you want to run TellForm in?', + choices: ['development', 'production', 'test'], + default: 'development' }, { type: 'input', @@ -90,26 +96,63 @@ var questions = [ name: 'APP_DESC', message: 'Describe your project (for SEO) (optional)' }, - { - type: 'input', - name: 'APP_KEYWORDS', - message: 'What keywords are relevant to your project (seperate by commas) (optional)' - }, { type: 'confirm', name: 'SIGNUP_DISABLED', - message: 'Do you want to disable signups?' + message: 'Do you want to disable signups?', + default: false }, { type: 'confirm', name: 'SUBDOMAINS_DISABLED', - message: 'Do you want to have subdomains? (i.e. are you using a custom domain)' + message: 'Do you want to disable subdomains? (i.e. are you using a custom domain)' }, { type: 'list', name: 'MAILER_SERVICE_PROVIDER', message: 'What email service provider are you using?', choices: nodemailer_providers + } +] + +var mailerWellKnownQuestions = [ + { + type: 'input', + name: 'MAILER_EMAIL_ID', + message: 'What is your SMTP username?' + }, + { + type: 'password', + name: 'MAILER_PASSWORD', + message: 'What is your SMTP password?' + }, + { + type: 'input', + name: 'MAILER_FROM', + message: 'What do you want the default "from" email address to be?' + } +]; + +var mailerCustomQuestions = [ + { + type: 'input', + name: 'MAILER_SMTP_HOST', + message: 'What is your SMTP server url?' + }, + { + type: 'input', + name: 'MAILER_SMTP_PORT', + message: 'What is your SMTP server port?' + }, + { + type: 'confirm', + name: 'MAILER_SMTP_SECURE', + message: 'Is your SMTP server using SSL/TLS?' + }, + { + type: 'input', + name: 'MAILER_SMTP_HOST', + message: 'What is your SMTP host domain?' }, { type: 'input', @@ -125,11 +168,26 @@ var questions = [ type: 'input', name: 'MAILER_FROM', message: 'What do you want the default "from" email address to be?' + } +]; + +var questionsPart2 = [ + { + type: 'input', + name: 'MONGODB_URI', + message: 'What is the URI of your Mongo database?', + default: 'mongodb://localhost/mean' + }, + { + type: 'input', + name: 'MONGODB_URI', + message: 'What is the URI of your Redis installation?', + default: 'redis://127.0.0.1:6379' }, { type: 'input', name: 'BASE_URL', - message: 'What is the url your TellForm will be hosted at?', + message: 'What is the (root) url your TellForm will be hosted at?', default: 'localhost' }, { @@ -138,26 +196,6 @@ var questions = [ message: 'What port should the TellForm server run on?', default: '3000' }, - { - type: 'input', - name: 'GOOGLE_ANALYTICS_ID', - message: 'What is your Google Analytics Tag? (optional)' - }, - { - type: 'input', - name: 'RAVEN_DSN', - message: 'What is your Private Raven DSN key? (optional)' - }, - { - type: 'input', - name: 'PRERENDER_TOKEN', - message: 'What is your Prerender.io token? (optional)' - }, - { - type: 'input', - name: 'COVERALLS_REPO_TOKEN', - message: 'What is your Coveralls.io token? (optional)' - }, { type: 'input', name: 'email', @@ -175,60 +213,83 @@ var questions = [ } ]; -if(!fs.existsSync('./\.env')) { - console.log(chalk.green('\n\nHi, welcome to TellForm Setup')); +var exitProcess = function() { + console.log(chalk.green('Have fun using TellForm!')); + process.exit(1); +} - console.log(chalk.green('You should only run this the first time you run TellForm\n--------------------------------------------------\n\n')); +var removeENVFile = function(){ + fs.unlinkSync('./\.env') +} - inquirer.prompt([questions[0]]).then(function (confirmAns) { - if (confirmAns['shouldContinue']) { +var createENVFile = function() { + inquirer.prompt(questionsPart1).then(function (answersPart1) { + var nextQuestions = mailerWellKnownQuestions.concat(questionsPart2); + if(answersPart1['MAILER_SERVICE_PROVIDER'] === 'Custom Mailserver'){ + nextQuestions = mailerCustomQuestions.concat(questionsPart2); + } - inquirer.prompt(questions.slice(1)).then(function (answers) { - answers['NODE_ENV'] = 'production'; + inquirer.prompt(nextQuestions).then(function (answersPart2) { + var answers = _.extend(answersPart1, answersPart2); + answers = _.mapValues(answers, function(val){ + if(_.isBoolean(val)){ + return val ? 'TRUE' : 'FALSE'; + } + return val; + }); - var email = answers['email']; - var username = answers['username']; - var pass = answers['password']; - delete answers['email']; - delete answers['password']; + var email = answers['email']; + var username = answers['username']; + var pass = answers['password']; + delete answers['email']; + delete answers['password']; - envfile.stringify(answers, function (err, str) { - try { - fs.outputFileSync('./\.env', str); - } catch (fileErr) { - return console.error(chalk.red(fileErr)); - } + envfile.stringify(answers, function (err, str) { + try { + fs.outputFileSync('./\.env', str); + } catch (fileErr) { + return console.error(chalk.red(fileErr)); + } - console.log(chalk.green('Successfully created .env file')); + console.log(chalk.green('Successfully created .env file')); - user = new User({ - firstName: 'Admin', - lastName: 'Account', - email: email, - username: username, - password: pass, - provider: 'local', - roles: ['admin', 'user'] - }); + user = new User({ + firstName: 'Admin', + lastName: 'Account', + email: email, + username: username, + password: pass, + provider: 'local', + roles: ['admin', 'user'] + }); - user.save(function (userSaveErr) { - if (err) { - return console.error(chalk.red(userSaveErr)); - } + user.save(function (userSaveErr) { + if (err) { + return console.error(chalk.red(userSaveErr)); + } - console.log(chalk.green('Successfully created user')); + console.log(chalk.green('Successfully created user')); - console.log(chalk.green('Have fun using TellForm!')); - process.exit(1); - }); + exitProcess(); }); }); + }); + }); +} + +console.log(chalk.green('\n\nWelcome to TellForm Setup')); + +console.log(chalk.green('You should only need to run this script the first time you run TellForm\n------------------------------------------------------------------------\n\n')); + +if(fs.existsSync('./\.env')) { + inquirer.prompt([replaceENVQuestion]).then(function (envAnswer) { + if (envAnswer['replaceENVFile']) { + removeENVFile(); + createENVFile(); } else { - console.log(chalk.green('Have fun using TellForm!')); - process.exit(1); + exitProcess(); } }); } else { - console.log(chalk.red('You already have a .env file')); - process.exit(1); + createENVFile(); } diff --git a/selenium/.editorconfig b/selenium/.editorconfig new file mode 100644 index 00000000..5a13b97d --- /dev/null +++ b/selenium/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +# Apply for all files +[*] + +charset = utf-8 + +indent_style = space +indent_size = 4 + +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/selenium/.gitignore b/selenium/.gitignore new file mode 100644 index 00000000..704c683c --- /dev/null +++ b/selenium/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.idea +node_modules +npm-debug.log +uirecorder.log +reports +screenshots/**/*.png +screenshots/**/*.html +screenshots/**/*.json diff --git a/selenium/.vscode/launch.json b/selenium/.vscode/launch.json new file mode 100644 index 00000000..ec025318 --- /dev/null +++ b/selenium/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible Node.js debug attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Debug UIRecorder Local", + "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", + "cwd": "${workspaceRoot}", + "args": ["--reporter", "mochawesome-uirecorder", "${file}"], + "env": { + "webdriver": "127.0.0.1" + } + }, + { + "type": "node", + "request": "launch", + "name": "Debug UIRecorder Default", + "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", + "cwd": "${workspaceRoot}", + "args": ["--reporter", "mochawesome-uirecorder", "${file}"] + } + ] +} \ No newline at end of file diff --git a/selenium/README.md b/selenium/README.md new file mode 100644 index 00000000..62ab2ba6 --- /dev/null +++ b/selenium/README.md @@ -0,0 +1,28 @@ +UI Recorder test sample project +================ + +It's a UI Recorder test sample project. + +Save your test code here. + +Get more info: [http://uirecorder.com/](http://uirecorder.com/) + +How to run test case? +================ + +1. npm install +2. source run.sh ( Linux|Mac ) or run.bat ( Windows ) + +How to dock jenkins? +================ + +1. Add commands + + source ./install.sh + source ./run.sh + +2. Add reports + + > JUnit: reports/index.xml + + > HTML: reports/ diff --git a/selenium/commons/commons.md b/selenium/commons/commons.md new file mode 100644 index 00000000..730f82ee --- /dev/null +++ b/selenium/commons/commons.md @@ -0,0 +1 @@ +Please save common test case here. \ No newline at end of file diff --git a/selenium/config.json b/selenium/config.json new file mode 100644 index 00000000..a6e6c57a --- /dev/null +++ b/selenium/config.json @@ -0,0 +1,14 @@ +{ + "webdriver": { + "host": "127.0.0.1", + "port": "4444", + "browsers": "chrome" + }, + "vars": {}, + "recorder": { + "pathAttrs": "data-id,data-name,type,data-type,role,data-role,data-value", + "attrValueBlack": "", + "classValueBlack": "", + "hideBeforeExpect": "" + } +} \ No newline at end of file diff --git a/selenium/hosts b/selenium/hosts new file mode 100644 index 00000000..e69de29b diff --git a/selenium/install.sh b/selenium/install.sh new file mode 100644 index 00000000..67759d80 --- /dev/null +++ b/selenium/install.sh @@ -0,0 +1,4 @@ +ls ~/nvm || git clone https://github.com/creationix/nvm.git ~/nvm +source ~/nvm/nvm.sh +nvm install v7.10.0 +npm install diff --git a/selenium/package.json b/selenium/package.json new file mode 100644 index 00000000..03727c90 --- /dev/null +++ b/selenium/package.json @@ -0,0 +1,25 @@ +{ + "name": "uirecorderTest", + "version": "1.0.0", + "description": "", + "main": "", + "dependencies": { + "chai": "3.5.0", + "jwebdriver": "2.2.4", + "mocha": "3.1.2", + "mocha-parallel-tests": "1.2.4", + "mochawesome-uirecorder": "1.5.22", + "resemblejs-node": "1.0.0", + "selenium-standalone": "6.x.x" + }, + "devDependencies": { + }, + "scripts": { + "installdriver": "./node_modules/.bin/selenium-standalone install --drivers.firefox.baseURL=http://npm.taobao.org/mirrors/geckodriver --baseURL=http://npm.taobao.org/mirrors/selenium --drivers.chrome.baseURL=http://npm.taobao.org/mirrors/chromedriver --drivers.ie.baseURL=http://npm.taobao.org/mirrors/selenium", + "server": "./node_modules/.bin/selenium-standalone start", + "test": "./node_modules/.bin/mocha \"*/**/*.spec.js\" --reporter mochawesome-uirecorder --bail", + "singletest": "./node_modules/.bin/mocha --reporter mochawesome-uirecorder --bail", + "paralleltest": "./node_modules/.bin/mocha-parallel-tests \"*/**/*.spec.js\" --reporter mochawesome-uirecorder --max-parallel 5 --bail" + }, + "author": "" +} diff --git a/selenium/run.bat b/selenium/run.bat new file mode 100644 index 00000000..da1ec242 --- /dev/null +++ b/selenium/run.bat @@ -0,0 +1,7 @@ +@echo off + +if "%1" neq "" ( + npm run singletest %1 %2 +) else ( + npm run paralleltest +) diff --git a/selenium/run.sh b/selenium/run.sh new file mode 100644 index 00000000..6f479e13 --- /dev/null +++ b/selenium/run.sh @@ -0,0 +1,5 @@ +if [ "$1" = "" ]; then + npm run paralleltest +else + npm run singletest $1 $2 +fi diff --git a/selenium/screenshots/screenshots.md b/selenium/screenshots/screenshots.md new file mode 100644 index 00000000..ec2da3ba --- /dev/null +++ b/selenium/screenshots/screenshots.md @@ -0,0 +1 @@ +Test screenshots saved here. \ No newline at end of file diff --git a/selenium/uploadfiles/uploadfiles.md b/selenium/uploadfiles/uploadfiles.md new file mode 100644 index 00000000..b9f2a65c --- /dev/null +++ b/selenium/uploadfiles/uploadfiles.md @@ -0,0 +1 @@ +Please save upload files here.