forked from sendgrid/sendgrid-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support of replyToList in the library, sendgrid#339:
- Use the replyToList header to set multiple emailIds in the reply-to section of an email - Fixed old test cases that were failing as SendGrid changed the acceptable response code to 202
- Loading branch information
Subinoy Ghosh
committed
Sep 23, 2021
1 parent
85b2c70
commit 1cb6525
Showing
3 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ before(() => { | |
* Default mock header | ||
*/ | ||
beforeEach(() => { | ||
sgClient.setDefaultHeader('X-Mock', 200); | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
}); | ||
|
||
/** | ||
|
@@ -38,12 +38,12 @@ describe('sgMail.send()', () => { | |
return expect(sgMail.send()).to.eventually.be.rejectedWith(Error); | ||
}); | ||
|
||
it('should send a basic email', () => { | ||
sgClient.setDefaultHeader('X-Mock', 201); | ||
it('should send a basic email', async () => { | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
return sgMail | ||
.send(data) | ||
.then(([response, body]) => { | ||
expect(response.statusCode).to.equal(201); | ||
expect(response.statusCode).to.equal(202); | ||
}); | ||
}); | ||
|
||
|
@@ -53,19 +53,84 @@ describe('sgMail.send()', () => { | |
}).to.throw(Error); | ||
}); | ||
|
||
it('should include custom headers to the request', () => { | ||
sgClient.setDefaultHeader('X-Mock', 201); | ||
it('should include custom headers to the request', async () => { | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
const clientSpy = sinon.spy(sgClient, "request") | ||
return sgMail | ||
.send(Object.assign(data, { headers: { customHeader: "Custom Header Content" } })) | ||
.then(([response, body]) => { | ||
expect(response.statusCode).to.equal(201); | ||
expect(response.statusCode).to.equal(202); | ||
expect(clientSpy).to.have.been.calledWith(sinon.match({ | ||
url: "/v3/mail/send", | ||
method: "POST", | ||
headers: { customHeader: "Custom Header Content" } | ||
})); | ||
}); | ||
}); | ||
|
||
it('should send email with correct replyToList format', async () => { | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
data["replyToList"] = [ | ||
{ | ||
"name": "Test Team", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Support Test Team", | ||
"email": "[email protected]" | ||
} | ||
]; | ||
return sgMail | ||
.send(data) | ||
.then(([response, body]) => { | ||
expect(response.statusCode).to.equal(202); | ||
}); | ||
}); | ||
|
||
it('should throw error with wrong replyToList format', async () => { | ||
sgClient.setDefaultHeader('X-Mock', 202); | ||
data["replyToList"] = { | ||
"name": "Support Test Team", | ||
"email": "[email protected]" | ||
}; | ||
return expect(function() { | ||
sgMail.send(data, false, {}); | ||
}).to.throw(Error); | ||
}); | ||
|
||
it('should throw error if any record in replyToList is without email', async () => { | ||
data["replyToList"] = [ | ||
{ | ||
"name": "Test Team", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Support Test Team" | ||
} | ||
]; | ||
return expect(function() { | ||
sgMail.send(data, false, {}); | ||
}).to.throw(Error); | ||
}); | ||
|
||
it('should throw error if both replyTo and replyToList are mentioned', async () => { | ||
data["replyTo"] = { | ||
"name": "Manual Tester", | ||
"email": "[email protected]" | ||
}; | ||
data["replyToList"] = [ | ||
{ | ||
"name": "Test Team", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Support Test Team", | ||
"email": "[email protected]" | ||
} | ||
]; | ||
return expect(function() { | ||
sgMail.send(data, false, {}); | ||
}).to.throw(Error); | ||
}); | ||
}); | ||
|