UNPKG

postage

Version:

Node.JS PostageApp API Client

174 lines (162 loc) 5.22 kB
/** * define this key if you are running tests! */ var vows = require('vows') , assert = require('assert') , key = process.env.POSTAGE_KEY; /** * spec */ vows.describe('postage test suite').addBatch({ 'when instantiating postage WITH a key':{ topic:function(){ var postage = require('../lib/postage')(key); return postage; }, 'postage should be a function':function(topic) { assert.isFunction(topic); } }, 'when instantiating postage WITHOUT a key':{ topic:function(){ var postage = require('../lib/postage')(); return postage; }, 'postage should throw an error':function(topic) { assert.throws(topic); } }, 'when sending a message with postage':{ topic:function(){ var self = this; var postage = require('../lib/postage')(key); var options = { recipients: 'hello@unfol.io', subject: 'Brought to you by unfolio!', from: 'hello@unfol.io', content: { 'text/html': '<h1><a href="http://unfol.io/">Check out http://unfol.io!</a></h1>', } }; postage.send(options, self.callback); }, 'postage should have no errors':function(error, message) { assert.isNull(error); }, 'message should be defined':function(error, message) { assert.isDefined(message); }, 'message status is defined':function(error, message) { assert.isDefined(message.response.status); }, 'message status should be "ok"':function(error, message) { assert.equal(message.response.status, 'ok'); }, 'message uid is defined':function(error, message) { assert.isDefined(message.response.uid); } }, 'when sending a message with postage':{ topic:function(){ var self = this; var postage = require('../lib/postage')(key); var options = { recipients: 'hello@unfol.io', subject: 'Brought to you by unfolio!', from: 'hello@unfol.io', content: { 'text/html': '<h1><a href="http://unfol.io/">Check out http://unfol.io!</a></h1>', } }; postage.send(options, self.callback); }, 'postage should have no errors':function(error, message) { assert.isNull(error); }, 'message should be defined':function(error, message) { assert.isDefined(message); }, 'message status is defined':function(error, message) { assert.isDefined(message.response.status); }, 'message status should be "ok"':function(error, message) { assert.equal(message.response.status, 'ok'); }, 'message uid is defined':function(error, message) { var uid = message.response.uid; assert.isDefined(uid); var postage = require('../lib/postage')(key); postage.get_message_receipt(uid, function(error, message) { assert.isNull(error); assert.isDefined(message); }); } }, 'when retrieving account information':{ topic:function(){ var self = this; var postage = require('../lib/postage')(key); postage.get_account_info(self.callback); }, 'account api call should have no errors':function(error, message) { assert.isNull(error); }, 'message should be defined':function(error, message) { assert.isDefined(message); }, 'message.data should be defined':function(error, message) { assert.isDefined(message.data); }, 'message.data.account should be defined':function(error, message) { assert.isDefined(message.data.account); } }, 'when retrieving project information information':{ topic:function(){ var self = this; var postage = require('../lib/postage')(key); postage.get_project_info(self.callback); }, 'account api call should have no errors':function(error, message) { assert.isNull(error); }, 'message should be defined':function(error, message) { assert.isDefined(message); }, 'message status is defined':function(error, message) { assert.isDefined(message.response.status); }, 'message status should be "ok"':function(error, message) { assert.equal(message.response.status, 'ok'); }, 'message data is defined':function(error, message) { assert.isDefined(message.data); } }, 'when retrieving the method list':{ topic:function(){ var self = this; var postage = require('../lib/postage')(key); postage.get_method_list(self.callback); }, 'api call should have no errors':function(error, message) { assert.isNull(error); }, 'message should be defined':function(error, message) { assert.isDefined(message); }, 'message status is defined':function(error, message) { assert.isDefined(message.response.status); }, 'message status should be "ok"':function(error, message) { assert.equal(message.response.status, 'ok'); }, 'message data should be defined':function(error, message) { assert.isDefined(message.data); }, 'there should be 10 available methods':function(error, message) { assert.equal(message.data.methods.split(',').length, 10); } } }).export(module); /* EOF */