Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
calidion committed Nov 15, 2015
1 parent ffc0de3 commit fe887aa
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module.exports = {
file: function (url, file, cb) {
fs.stat(file, function (err) {
if (err) {
return cb(true, {message: 'File not exist'});
return cb(true, {message: 'File not exist!'});
}
var media = fs.createReadStream(file);
request.post({
Expand Down
78 changes: 78 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,82 @@ describe('node-weixin-request node module', function () {
done();
});
});

it("should not be able to post xml data", function (done) {
var nock = require('nock');
var url = 'https://domain.com';

nock(url)
.post('/')
.reply(200, 'sdfosffd');
nodeWeixinRequest.xml(url, '<xml><a>sfdsf<sdf>sdfosd</sdf></a></xml>', function (error) {
assert.equal(true, error);
done();
});
});

it("should not be able to post file", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var path = require('path');
var file = path.resolve(__dirname, './cert/none.p12');

nock(url)
.post('/')
.reply(200, 'sdfosffd');
nodeWeixinRequest.file(url, file, function (error, json) {
assert.equal(true, error);
assert.equal(true, json.message === "File not exist!");
done();
});
});

it("should be able to post file", function (done) {
var nock = require('nock');
var url = 'https://domain.com';
var path = require('path');
var file = path.resolve(__dirname, './cert/a.p12');

nock(url)
.post('/')
.reply(200, 'sdfosffd');
nodeWeixinRequest.file(url, file, function (error, json) {
assert.equal(true, !error);
assert.equal(true, json === "sdfosffd");
done();
});
});

it("should not be able to post file", function (done) {
var nock = require('nock');
var url = 'https://domain1.com';
var path = require('path');
var file = path.resolve(__dirname, './cert/a.p12');

nock(url)
.post('/')
.reply(500, 'sdfosffd');
nodeWeixinRequest.file(url, file, function (error, json) {
assert.equal(true, error);
assert.equal(true, json.message === "sdfosffd");
done();
});
});

it("should not be able to download file", function (done) {
var nock = require('nock');
var url = 'https://download.domain.com';
var path = require('path');
var fs = require('fs');
var file = path.resolve(__dirname, './cert/a.p12');
var file1 = path.resolve(__dirname, './output/new.p12');

nock(url)
.get('/')
.reply(200, fs.createWriteStream(file));
nodeWeixinRequest.download(url, {hel:'sdfsfd'}, file1, function () {
assert.equal(true, true);
done();
});
});
});

0 comments on commit fe887aa

Please sign in to comment.