|
2 | 2 | var should = require('should'), // jshint ignore:line |
3 | 3 | AV = require('../lib/av-extra'); |
4 | 4 |
|
| 5 | +var express = require('express'); |
| 6 | +var bodyParser = require('body-parser'); |
| 7 | +var app = express(); |
| 8 | +app.use(bodyParser.json()); |
| 9 | +app.use(bodyParser.urlencoded({ extended: false })); |
| 10 | + |
| 11 | +app.get('/hello', function (req, res) { |
| 12 | + res.send('Hello, ' + req.query.name); |
| 13 | +}); |
| 14 | + |
| 15 | +app.post('/hello', function (req, res) { |
| 16 | + res.send('Hello, ' + req.body.name); |
| 17 | +}); |
| 18 | + |
| 19 | +var server = app.listen(3333, function () {}); |
| 20 | + |
| 21 | +after(function() { |
| 22 | + server.close(); |
| 23 | +}); |
| 24 | + |
5 | 25 | describe('av-extra', function() { |
6 | 26 | it('httpRequest', function(done) { |
7 | 27 | AV.Cloud.httpRequest({ |
8 | | - url: 'https://www.bing.com/search', |
9 | | - params: { q : 'leancloud怎么样' }, |
10 | | - success: function(httpResponse) { |
11 | | - httpResponse.status.should.equal(200); |
12 | | - done(); |
| 28 | + url: 'http://localhost:3333/hello', |
| 29 | + params: { name : '张三' }, |
| 30 | + success: function(res) { |
| 31 | + res.status.should.equal(200); |
| 32 | + res.text.should.equal('Hello, 张三'); |
| 33 | + done(); |
| 34 | + }, |
| 35 | + error: function(httpResponse) { |
| 36 | + throw httpResponse.text; |
| 37 | + } |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + it('httpRequest', function(done) { |
| 42 | + AV.Cloud.httpRequest({ |
| 43 | + url: 'http://localhost:3333/hello', |
| 44 | + method: 'POST', |
| 45 | + body: { |
| 46 | + name: "张三" |
| 47 | + }, |
| 48 | + success: function(res) { |
| 49 | + res.status.should.equal(200); |
| 50 | + res.text.should.equal('Hello, 张三'); |
| 51 | + done(); |
13 | 52 | }, |
14 | 53 | error: function(httpResponse) { |
15 | 54 | throw httpResponse.text; |
|
0 commit comments