Skip to content

Commit 0228da4

Browse files
committed
修改 AV.Cloud.httpRequest 的测试
1 parent 41adf5d commit 0228da4

1 file changed

Lines changed: 44 additions & 5 deletions

File tree

test/av-extra_test.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,53 @@
22
var should = require('should'), // jshint ignore:line
33
AV = require('../lib/av-extra');
44

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+
525
describe('av-extra', function() {
626
it('httpRequest', function(done) {
727
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();
1352
},
1453
error: function(httpResponse) {
1554
throw httpResponse.text;

0 commit comments

Comments
 (0)