Skip to content

Commit

Permalink
adding in check for deprecated .setStatusProperties()
Browse files Browse the repository at this point in the history
  • Loading branch information
awei01 committed Sep 6, 2016
2 parents 89b35ec + 537bc15 commit d56ac75
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions lib/superagent-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ function mock (superagent, config, logger) {
this.params = data;

return this;
} else {
return oldSend.call(this, data);
}

return oldSend.call(this, data);
};

/**
Expand All @@ -91,20 +90,20 @@ function mock (superagent, config, logger) {
}

var parser = testUrlForPatterns(this.url);
if (parser) {
if (isObject(field)) {
if (!parser) {
return oldSet.apply(this, arguments);
}

if (isObject(field)) {
for (var key in field) {
this.set(key, field[key]);
}
} else {
} else {
this.headers = this.headers || {};
this.headers[field] = val;
}

return this;
} else {
return oldSet.apply(this, arguments);
}

return this;
};

/**
Expand Down Expand Up @@ -142,16 +141,19 @@ function mock (superagent, config, logger) {
flushLog();
}

if (parser) {
var match = new RegExp(parser.pattern, 'g').exec(path);
if (!parser) {
return oldEnd.call(this, fn);
}

var match = new RegExp(parser.pattern, 'g').exec(path);

try {
var fixtures = parser.fixtures(match, this.params, this.headers);
var method = this.method.toLocaleLowerCase();
var parserMethod = parsers[this.url][method] ? parsers[this.url][method] : parsers[this.url].callback;
try {
var fixtures = parser.fixtures(match, this.params, this.headers);
var method = this.method.toLocaleLowerCase();
var parserMethod = parsers[this.url][method] ? parsers[this.url][method] : parsers[this.url].callback;

response = parserMethod(match, fixtures);
} catch(err) {
response = parserMethod(match, fixtures);
} catch(err) {
error = err;
response = new superagent.Response({
res: {
Expand All @@ -170,19 +172,16 @@ function mock (superagent, config, logger) {
getAllResponseHeaders: function () {return 'a header';},
getResponseHeader: function () {return err.responseHeader || 'a header';}
}
});
if (response._setStatusProperties) {
response._setStatusProperties(err.message);
} else {
response.setStatusProperties(err.message);
}
});
if (response._setStatusProperties) {
response._setStatusProperties(err.message);
} else {
response.setStatusProperties(err.message);
}

fn(error, response);
return this;
} else {
oldEnd.call(this, fn);
}

fn(error, response);
return this;
};

Request.prototype.abort = function () {
Expand Down

0 comments on commit d56ac75

Please sign in to comment.