Skip to content

Commit

Permalink
Add unit test for schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
alinex committed Apr 22, 2016
1 parent 7fc9eff commit b347d21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
# include base modules
debug = require('debug')('mail')
chalk = require 'chalk'
util = require 'util'
nodemailer = require 'nodemailer'
inlineBase64 = require 'nodemailer-plugin-inline-base64'
moment = require 'moment'
fspath = require 'path'
# include alinex modules
config = require 'alinex-config'
async = require 'alinex-async'
{object} = require 'alinex-util'
Report = require 'alinex-report'
util = require 'alinex-util'
Report = null # load on demand
# internal helpers
schema = require './configSchema'

Expand All @@ -39,15 +37,13 @@ exports.resolve = (setup) ->
debug chalk.grey "loading base template #{setup.base}"
base = config.get "/email/#{setup.base}"
delete setup.base
setup = object.extend {}, base, setup
setup = util.extend 'MODE CLONE', base, setup
setup


# Send Email
# -------------------------------------------------
exports.send = (setup, context, cb) ->
# configure email
setup = object.clone setup
# use base settings
setup = exports.resolve setup
# support handlebars
Expand All @@ -65,7 +61,8 @@ exports.send = (setup, context, cb) ->
debug chalk.grey "sending email to #{mails?.join ', '}..."
# setup transporter
transporter = nodemailer.createTransport setup.transport ? 'direct:?name=hostname'
transporter.use 'compile', inlineBase64
if ~setup.html.indexOf "src=\"data:"
transporter.use 'compile', require 'nodemailer-plugin-inline-base64'
debug chalk.grey "using #{transporter.transporter.name}"
# try to send email
transporter.sendMail setup, (err, info) ->
Expand All @@ -88,6 +85,7 @@ exports.send = (setup, context, cb) ->
addBody= (setup, context, cb) ->
return cb() unless setup.body
source = if typeof setup.body is 'function' then setup.body(context) else setup.body
Report ?= require 'alinex-report'
report = new Report
source: source
report.toHtml
Expand Down
7 changes: 5 additions & 2 deletions test/mocha/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

describe "Base", ->

it "should run empty test", (cb) ->
cb()
it "should run the selfcheck on the schema", (cb) ->
validator = require 'alinex-validator'
schema = require '../../src/configSchema'
validator.selfcheck schema.email, ->
validator.selfcheck schema.templates, cb

0 comments on commit b347d21

Please sign in to comment.