Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing an HTTP client: Part I
var request = require('superagent');
/**
* @constructor
*/
module.exports = Client;
function Client(api_key) {
this.params = {};
this.params.api_key = api_key;
this.params.format = 'json';
this.params.nojsoncallback = 1;
}
Client.prototype = Object.create(null);
Client.prototype.search = function (text, done) {
request('GET', 'https://api.flickr.com/services/rest')
.query('method=flickr.photos.search')
.query('text=' + text)
.query(this.params)
.end(done);
};
var Client = require('./client');
var assert = require('assert');
describe('Client', function () {
it('calls flickr.photos.search', function (done) {
var subject = new Client(process.env.API_KEY);
subject.search('coffee', function (err, res) {
assert.ifError(err);
assert.equal(res.statusCode, 200);
assert.equal(res.body.stat, 'ok');
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.