Skip to content

Commit

Permalink
add postmark stub so env var not required. closes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
timwis committed Sep 22, 2016
1 parent 404089f commit 5631a61
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
17 changes: 9 additions & 8 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const POSTMARK_SERVER_TOKEN = process.env.POSTMARK_SERVER_TOKEN
const http = require('http')
const assert = require('assert')
const nano = require('nano')
const postmark = require('postmark')
const serverRouter = require('server-router')
const bankai = require('bankai')
const browserify = require('browserify')
Expand All @@ -31,20 +30,22 @@ const addAuthToUrl = require('./util').addAuthToUrl
const parseBody = require('./util').parseBody
const pipeToResponse = require('./util').pipeToResponse

// Setup twilio client (or stub)
let twilio
// Setup twilio and postmark client (or stubs)
let twilio, emailClient
if (DEV) {
twilio = require('../test/fixtures/twilio/stub')
twilio = require('../test/helpers/twilio')
const postmark = require('../test/helpers/postmark')
emailClient = new postmark.Client()
} else {
assert(TWILIO_ACCOUNT_SID, 'TWILIO_ACCOUNT_SID environment variable is not defined')
assert(TWILIO_AUTH_TOKEN, 'TWILIO_AUTH_TOKEN environment variable is not defined')
assert(TWILIO_PHONE, 'TWILIO_PHONE environment variable is not defined')
twilio = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
}

// Setup postmark client
assert(POSTMARK_SERVER_TOKEN, 'POSTMARK_SERVER_TOKEN environment variable is not defined')
const emailClient = new postmark.Client(POSTMARK_SERVER_TOKEN)
assert(POSTMARK_SERVER_TOKEN, 'POSTMARK_SERVER_TOKEN environment variable is not defined')
const postmark = require('postmark')
emailClient = new postmark.Client(POSTMARK_SERVER_TOKEN)
}

// Setup CouchDB
assert(COUCHDB_HOST, 'COUCHDB_HOST environment variable is not defined')
Expand Down
10 changes: 10 additions & 0 deletions test/helpers/postmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = { Client }

function Client (token) {
this.token = token
}

Client.prototype.sendEmail = (config, cb) => {
console.log('Simulating email', config)
cb(null, {})
}
4 changes: 2 additions & 2 deletions test/fixtures/twilio/stub.js → test/helpers/twilio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const messages = require('./messages.json')
const outbound = require('./outbound.json')
const messages = require('../fixtures/twilio/messages.json')
const outbound = require('../fixtures/twilio/outbound.json')

module.exports = {
messages: {
Expand Down

0 comments on commit 5631a61

Please sign in to comment.