2022-05-04 21:02:29 +00:00
|
|
|
import { Readable } from "stream";
|
|
|
|
|
|
|
|
export const mockRequestImpl = httpVersion => method => url => body => headers => () => {
|
|
|
|
const stream = new Readable({
|
|
|
|
read: function (size) {
|
|
|
|
this.push(body);
|
|
|
|
this.push(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stream.method = method;
|
|
|
|
stream.url = url;
|
|
|
|
stream.headers = headers;
|
|
|
|
stream.httpVersion = httpVersion;
|
|
|
|
|
|
|
|
return stream;
|
2017-07-18 05:25:14 +00:00
|
|
|
};
|
|
|
|
|
2022-05-04 21:02:29 +00:00
|
|
|
export const mockResponse = () => ({
|
2017-07-20 22:48:59 +00:00
|
|
|
body: "",
|
|
|
|
headers: {},
|
2017-07-17 23:42:13 +00:00
|
|
|
|
2022-05-04 21:02:29 +00:00
|
|
|
write: function (str, encoding, callback) {
|
|
|
|
this.body = this.body + str;
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2021-06-25 17:58:16 +00:00
|
|
|
},
|
|
|
|
|
2022-05-04 21:02:29 +00:00
|
|
|
end: function (str, encoding, callback) {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2017-07-20 22:48:59 +00:00
|
|
|
},
|
2017-07-17 23:42:13 +00:00
|
|
|
|
2022-05-04 21:02:29 +00:00
|
|
|
on: function () {},
|
|
|
|
once: function () {},
|
|
|
|
emit: function () {},
|
2017-07-17 23:42:13 +00:00
|
|
|
|
2022-05-04 21:02:29 +00:00
|
|
|
setHeader: function (header, val) {
|
|
|
|
this.headers[header] = val;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const stringToStream = str => {
|
|
|
|
const stream = new Readable();
|
|
|
|
stream._read = function () {};
|
|
|
|
stream.push(str);
|
|
|
|
stream.push(null);
|
|
|
|
return stream;
|
2018-08-30 22:01:49 +00:00
|
|
|
}
|