smtpapi
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -110,5 +110,13 @@ "use strict"; | ||
return json; | ||
return escapeUnicode(json); | ||
}; | ||
function escapeUnicode(str) { | ||
return str.replace(/[^ -~]|\\/g, function(m0) { | ||
var code = m0.charCodeAt(0); | ||
return '\\u' + ((code < 0x10)? '000' : | ||
(code < 0x100)? '00' : | ||
(code < 0x1000)? '0' : '') + code.toString(16); | ||
}); | ||
} | ||
@@ -115,0 +123,0 @@ function smtpapi() { |
{ | ||
"name": "smtpapi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Build SendGrid X-SMTPAPI headers in nodejs.", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
@@ -30,3 +30,3 @@ # smtpapi-nodejs | ||
... | ||
"smtpapi": "0.0.1" | ||
"smtpapi": "0.0.2" | ||
} | ||
@@ -33,0 +33,0 @@ } |
@@ -1,4 +0,5 @@ | ||
var assert = require('assert'), | ||
should = require('should'), | ||
smtpapi = require('../lib/main'); | ||
var assert = require('assert'); | ||
var should = require('should'); | ||
var smtpapi = require('../lib/main'); | ||
var t = require('./smtpapi_test_strings.json'); | ||
@@ -13,3 +14,3 @@ var result; | ||
it('version should be set', function() { | ||
result.version.should.eql("0.0.1"); | ||
result.version.should.eql("0.0.2"); | ||
}); | ||
@@ -21,3 +22,3 @@ | ||
header.jsonString().should.eql('{}'); | ||
header.jsonString().should.eql(t.json_string); | ||
}); | ||
@@ -29,5 +30,12 @@ | ||
header.addTo('addTo@mailinator.com'); | ||
header.jsonString().should.eql('{"to":["addTo@mailinator.com"]}'); | ||
header.jsonString().should.eql(t.add_to); | ||
}); | ||
it('setTos', function() { | ||
var header = new smtpapi.Header(); | ||
header.setTos(['setTos@mailinator.com']); | ||
header.jsonString().should.eql(t.set_tos); | ||
}); | ||
it('addSubstitution', function() { | ||
@@ -37,10 +45,10 @@ var header = new smtpapi.Header(); | ||
header.addSubstitution('sub', 'val'); | ||
header.jsonString().should.eql('{"sub":{"sub":["val"]}}'); | ||
header.jsonString().should.eql(t.add_substitution); | ||
}); | ||
it('setUniqueArgs', function() { | ||
it('setSubstitutions', function() { | ||
var header = new smtpapi.Header(); | ||
header.setUniqueArgs({set_unique_argument_key: 'set_unique_argument_value'}); | ||
header.jsonString().should.eql('{"unique_args":{"set_unique_argument_key":"set_unique_argument_value"}}'); | ||
header.setSubstitutions({'sub': ['val']}); | ||
header.jsonString().should.eql(t.set_substitutions); | ||
}); | ||
@@ -53,10 +61,10 @@ | ||
header.addUniqueArg({add_unique_argument_key_2: 'add_unique_argument_value_2'}); | ||
header.jsonString().should.eql('{"unique_args":{"add_unique_argument_key":"add_unique_argument_value","add_unique_argument_key_2":"add_unique_argument_value_2"}}'); | ||
header.jsonString().should.eql(t.add_unique_arg); | ||
}); | ||
it('setCategories', function() { | ||
it('setUniqueArgs', function() { | ||
var header = new smtpapi.Header(); | ||
header.setCategories(['setCategory']); | ||
header.jsonString().should.eql('{"category":["setCategory"]}'); | ||
header.setUniqueArgs({set_unique_argument_key: 'set_unique_argument_value'}); | ||
header.jsonString().should.eql(t.set_unique_args); | ||
}); | ||
@@ -69,12 +77,20 @@ | ||
header.addCategory('addCategory2'); | ||
header.jsonString().should.eql('{"category":["addCategory","addCategory2"]}'); | ||
header.jsonString().should.eql(t.add_category); | ||
}); | ||
it('setSections', function() { | ||
it('addCategoryUnicode', function() { | ||
var header = new smtpapi.Header(); | ||
header.setSections({'set_section_key': 'set_section_value'}); | ||
header.jsonString().should.eql('{"section":{"set_section_key":"set_section_value"}}'); | ||
header.addCategory('カテゴリUnicode'); | ||
header.addCategory('カテゴリ2Unicode'); | ||
header.jsonString().should.eql(t.add_category_unicode); | ||
}); | ||
it('setCategories', function() { | ||
var header = new smtpapi.Header(); | ||
header.setCategories(['setCategories']); | ||
header.jsonString().should.eql(t.set_categories); | ||
}); | ||
it('addSection', function() { | ||
@@ -85,5 +101,19 @@ var header = new smtpapi.Header(); | ||
header.addSection({'set_section_key_2': 'set_section_value_2'}); | ||
header.jsonString().should.eql('{"section":{"set_section_key":"set_section_value","set_section_key_2":"set_section_value_2"}}'); | ||
header.jsonString().should.eql(t.add_section); | ||
}); | ||
it('setSections', function() { | ||
var header = new smtpapi.Header(); | ||
header.setSections({'set_section_key': 'set_section_value'}); | ||
header.jsonString().should.eql(t.set_sections); | ||
}); | ||
it('addFilter', function() { | ||
var header = new smtpapi.Header(); | ||
header.addFilter('footer', 'text/html', '<strong>boo</strong>'); | ||
header.jsonString().should.eql(t.add_filter); | ||
}); | ||
it('setFilters', function() { | ||
@@ -102,13 +132,5 @@ var header = new smtpapi.Header(); | ||
header.setFilters(filter); | ||
header.jsonString().should.eql('{"filters":{"footer":{"setting":{"enable":1,"text/plain":"You can haz footers!"}}}}'); | ||
header.jsonString().should.eql(t.set_filters); | ||
}); | ||
it('addFilter', function() { | ||
var header = new smtpapi.Header(); | ||
header.addFilter('footer', 'text/html', '<strong>boo</strong>'); | ||
header.jsonString().should.eql('{"filters":{"footer":{"settings":{"text/html":"<strong>boo</strong>"}}}}'); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
13851
7
219