1 |
|
2 | var should = require('should');
|
3 | var through = require('through');
|
4 | var _ = require('lodash');
|
5 |
|
6 | var Waif = require('../');
|
7 |
|
8 | describe('request local service', function() {
|
9 | var waif = null;
|
10 |
|
11 | before(function() {
|
12 | waif = Waif.createInstance();
|
13 | this.service = waif('local')
|
14 | .use(_middleware)
|
15 | .listen();
|
16 |
|
17 | waif.start();
|
18 | });
|
19 |
|
20 | after(function() { waif.stop(); });
|
21 |
|
22 | it('request helper', function(doneFn) {
|
23 | var local = waif('local');
|
24 |
|
25 | local('/path/here', test);
|
26 | function test(err, resp, body) {
|
27 | should.not.exist(err);
|
28 |
|
29 | doneFn();
|
30 | }
|
31 | });
|
32 |
|
33 | it('pipe a file from a file hosting service', function(doneFn) {
|
34 | var local = waif('local');
|
35 |
|
36 | local('/filename.jpg')
|
37 | .pipe(through(pipeFn))
|
38 | .on('error', doneFn)
|
39 | .on('close', doneFn);
|
40 |
|
41 | function pipeFn(data) {
|
42 | this.queue(data);
|
43 | }
|
44 | });
|
45 | });
|
46 |
|
47 |
|
48 | function _middleware() {
|
49 | return function(req, res, next) {
|
50 | res.send({msg: 'ok'});
|
51 | };
|
52 | }
|