-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added json flag to base request and tests to check for JSON response #123
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,7 @@ describe('SparkPost Library', function() { | |
expect(err).to.be.null; | ||
expect(data.statusCode).to.equal(200); | ||
expect(data.body).to.equal(TEST_MESSAGE + TEST_MESSAGE); | ||
|
||
// finish async test | ||
done(); | ||
}); | ||
|
@@ -227,11 +227,18 @@ describe('SparkPost Library', function() { | |
}); | ||
|
||
describe('get method', function() { | ||
it('should deliver a GET + response', function(done) { | ||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
var client; | ||
|
||
before(function() { | ||
// setting up a client for all tests to use | ||
var key = '12345678901234567890'; | ||
var client = new SparkPost(key); | ||
var options = {}; | ||
|
||
client = new SparkPost(key, options); | ||
}); | ||
|
||
it('should deliver a GET + response', function(done) { | ||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
|
||
nock('https://api.sparkpost.com') | ||
.get('/api/v1/get/test') | ||
|
@@ -248,14 +255,41 @@ describe('SparkPost Library', function() { | |
done(); | ||
}); | ||
}); | ||
|
||
it('should return a parsed JSON object', function(done) { | ||
nock('https://test.sparkpost.com') | ||
.get('/test') | ||
.reply(200, '{ "ok": true }'); | ||
|
||
var options = { | ||
method: 'GET' | ||
, uri: 'https://test.sparkpost.com/test' | ||
}; | ||
|
||
client.request(options, function(err, data) { | ||
expect(data.body).to.not.be.a('string'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need both !string and ==object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Belt and suspenders. Also I didn't know if it was like "a function is an object, a string is an object, I'm javascript and I treat everything as an object" |
||
expect(data.body).to.be.an('object'); | ||
expect(data.body).to.deep.equal({ok: true}); | ||
|
||
// finish async test | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('post method', function() { | ||
it('should deliver a POST', function(done) { | ||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
var client; | ||
|
||
before(function() { | ||
// setting up a client for all tests to use | ||
var key = '12345678901234567890'; | ||
var client = new SparkPost(key); | ||
var options = {}; | ||
|
||
client = new SparkPost(key, options); | ||
}); | ||
|
||
it('should deliver a POST', function(done) { | ||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
|
||
nock('https://api.sparkpost.com') | ||
.post('/api/v1/post/test') | ||
|
@@ -279,14 +313,44 @@ describe('SparkPost Library', function() { | |
done(); | ||
}); | ||
}); | ||
|
||
it('should return a parsed JSON object', function(done) { | ||
nock('https://test.sparkpost.com') | ||
.post('/test') | ||
.reply(200, '{ "ok": true }'); | ||
|
||
var options = { | ||
method: 'POST' | ||
, uri: 'https://test.sparkpost.com/test' | ||
, json: { | ||
testingData: 'test data' | ||
} | ||
}; | ||
|
||
client.request(options, function(err, data) { | ||
expect(data.body).to.not.be.a('string'); | ||
expect(data.body).to.be.an('object'); | ||
expect(data.body).to.deep.equal({ok: true}); | ||
|
||
// finish async test | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('put method', function() { | ||
it('should deliever a PUT/UPDATE', function(done) { | ||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
var client; | ||
|
||
before(function() { | ||
// setting up a client for all tests to use | ||
var key = '12345678901234567890'; | ||
var client = new SparkPost(key); | ||
var options = {}; | ||
|
||
client = new SparkPost(key, options); | ||
}); | ||
|
||
it('should deliever a PUT/UPDATE', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delivier -> deliver There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't even consistently spell something wrong. |
||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
|
||
nock('https://api.sparkpost.com') | ||
.put('/api/v1/put/test') | ||
|
@@ -310,14 +374,44 @@ describe('SparkPost Library', function() { | |
done(); | ||
}); | ||
}); | ||
|
||
it('should return a parsed JSON object', function(done) { | ||
nock('https://test.sparkpost.com') | ||
.put('/test') | ||
.reply(200, '{ "ok": true }'); | ||
|
||
var options = { | ||
method: 'PUT' | ||
, uri: 'https://test.sparkpost.com/test' | ||
, json: { | ||
testingData: 'test data' | ||
} | ||
}; | ||
|
||
client.request(options, function(err, data) { | ||
expect(data.body).to.not.be.a('string'); | ||
expect(data.body).to.be.an('object'); | ||
expect(data.body).to.deep.equal({ok: true}); | ||
|
||
// finish async test | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('delete method', function() { | ||
it('should deliever a DELETE', function(done) { | ||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
var client; | ||
|
||
before(function() { | ||
// setting up a client for all tests to use | ||
var key = '12345678901234567890'; | ||
var client = new SparkPost(key); | ||
var options = {}; | ||
|
||
client = new SparkPost(key, options); | ||
}); | ||
|
||
it('should deliever a DELETE', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delivier -> deliver There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow... that's been in there forever. Ha |
||
var requestSpy = sinon.spy(SparkPost.prototype, 'request'); | ||
|
||
nock('https://api.sparkpost.com') | ||
.delete('/api/v1/delete/test') | ||
|
@@ -341,5 +435,28 @@ describe('SparkPost Library', function() { | |
done(); | ||
}); | ||
}); | ||
|
||
it('should return a parsed JSON object', function(done) { | ||
nock('https://test.sparkpost.com') | ||
.delete('/test') | ||
.reply(200, '{ "ok": true }'); | ||
|
||
var options = { | ||
method: 'DELETE' | ||
, uri: 'https://test.sparkpost.com/test' | ||
, json: { | ||
testingData: 'test data' | ||
} | ||
}; | ||
|
||
client.request(options, function(err, data) { | ||
expect(data.body).to.not.be.a('string'); | ||
expect(data.body).to.be.an('object'); | ||
expect(data.body).to.deep.equal({ok: true}); | ||
|
||
// finish async test | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor: Do we need separate string and an object versions of the response object? We could just keep it in a var and encode/decode/compare as necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you give nock and object to return, it will do stuff on it's side. I wanted to make sure that the response was a string and was being manipulated by the request lib.