Skip to content

Commit

Permalink
Merge pull request #202 from SparkPost/ignore-empty-sugar
Browse files Browse the repository at this point in the history
added check around cc and test
  • Loading branch information
avigoldman committed Jan 9, 2017
2 parents 13f0c4d + c0a984a commit 5455ad2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]
### Fixed
- Empty CC sugar method no longer triggers an API error.

## [2.1.0] - 2016-12-20
### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/transmissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function formatPayload(originalTransmission) {
});

// add the CC headers
if (_.isArray(transmission.cc)) {
if (_.isArray(transmission.cc) && transmission.cc.length > 0) {
_.set(transmission, 'content.headers.CC', generateCCHeader(transmission));
}

Expand Down
25 changes: 25 additions & 0 deletions test/spec/transmissions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,31 @@ describe('Transmissions Library', function() {
});
});

it('should ignore empty bcc and cc', function() {
var transmission = {
recipients: [
{
address: {
name: "Bob",
email: "recipient1@gmail.com"
}
},
],
cc: [],
bcc: [],
content: {
template_id: 'my-template-id'
}
};

return transmissions.send(transmission)
.then(function() {
delete transmission.cc;
delete transmission.bcc;

expect(client.post.firstCall.args[0].json).to.deep.equal(transmission);
});
});

it('should convert cc to the correct recipients and headers', function() {
return transmissions.send(ccTransmission)
Expand Down

0 comments on commit 5455ad2

Please sign in to comment.