-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db1ad43
commit f78ec62
Showing
8 changed files
with
76 additions
and
4 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* globals describe, beforeEach, afterEach, it */ | ||
var assert = require('assert'); | ||
var request = require('request'); | ||
var Q = require('q'); | ||
var fs = require('fs'); | ||
|
||
request = request.defaults({ | ||
json: true | ||
}); | ||
|
||
var get = Q.denodeify(request.get); | ||
var post = Q.denodeify(request.post); | ||
var put = Q.denodeify(request.put); | ||
var del = Q.denodeify(request.del); | ||
var patch = Q.denodeify(request.patch); | ||
|
||
// The thing we're testing | ||
var Interfake = require('..'); | ||
var interfake; | ||
|
||
describe('Interfake File Response Tests', function() { | ||
beforeEach(function() { | ||
interfake = new Interfake(); | ||
}); | ||
afterEach(function() { | ||
if (interfake) { | ||
interfake.stop(); | ||
} | ||
}); | ||
|
||
// Testing the fluent interface | ||
describe('#get()', function() { | ||
describe('#image()', function() { | ||
it('should respond with the same image', function(done) { | ||
interfake.get('/image').image('./tests/assets/10x10-imagejpg.jpg'); | ||
interfake.listen(3000); | ||
|
||
request({ | ||
url: 'http://localhost:3000/image', | ||
json: true | ||
}, function(error, response, body) { | ||
assert.equal(response.statusCode, 200); | ||
assert.equal(response.headers['content-type'], 'image/jpeg'); | ||
fs.readFile('./tests/assets/10x10-imagejpg.jpg', function(err, correctData) { | ||
if (err) throw err; | ||
assert.equal(correctData, body); | ||
fs.readFile('./tests/assets/20x20-image-redjpg.jpg', function(err, incorrectData) { | ||
if (err) throw err; | ||
assert.notEqual(incorrectData, body); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |