Code cleanup (#50)
This commit is contained in:
parent
930130b624
commit
008924e861
@ -25,7 +25,7 @@ read request = Aff.makeAff \_ success -> do
|
|||||||
let stream = HTTP.requestAsStream request
|
let stream = HTTP.requestAsStream request
|
||||||
buf <- ST.newSTRef ""
|
buf <- ST.newSTRef ""
|
||||||
Stream.onDataString stream Encoding.UTF8 \str ->
|
Stream.onDataString stream Encoding.UTF8 \str ->
|
||||||
ST.modifySTRef buf (\old -> old <> str) >>= (\_ -> pure unit)
|
ST.modifySTRef buf ((<>) str) >>= \_ -> pure unit
|
||||||
Stream.onEnd stream $ ST.readSTRef buf >>= success
|
Stream.onEnd stream $ ST.readSTRef buf >>= success
|
||||||
|
|
||||||
-- | Write a body to the given HTTP Response and close it.
|
-- | Write a body to the given HTTP Response and close it.
|
||||||
|
@ -67,7 +67,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
|||||||
response <- mock "POST" "" "test" StrMap.empty
|
response <- mock "POST" "" "test" StrMap.empty
|
||||||
case response of
|
case response of
|
||||||
(Request.Post _ _ "test") -> pure unit
|
(Request.Post _ _ "test") -> pure unit
|
||||||
a -> Assertions.fail $ "expected the body 'test', got " <> show a
|
(Request.Post _ _ body) ->
|
||||||
|
Assertions.fail $ "expected the body 'test', got " <> body
|
||||||
|
a -> Assertions.fail $ "expected a post, got " <> show a
|
||||||
|
|
||||||
Spec.describe "with a PUT" do
|
Spec.describe "with a PUT" do
|
||||||
Spec.it "is a Put" do
|
Spec.it "is a Put" do
|
||||||
@ -90,7 +92,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
|||||||
response <- mock "PUT" "" "test" StrMap.empty
|
response <- mock "PUT" "" "test" StrMap.empty
|
||||||
case response of
|
case response of
|
||||||
(Request.Put _ _ "test") -> pure unit
|
(Request.Put _ _ "test") -> pure unit
|
||||||
a -> Assertions.fail $ "expected the body 'test', got " <> show a
|
(Request.Put _ _ body) ->
|
||||||
|
Assertions.fail $ "expected the body 'test', got " <> body
|
||||||
|
a -> Assertions.fail $ "expected a put, got " <> show a
|
||||||
|
|
||||||
Spec.describe "with a DELETE" do
|
Spec.describe "with a DELETE" do
|
||||||
Spec.it "is a Delete" do
|
Spec.it "is a Delete" do
|
||||||
@ -149,7 +153,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
|||||||
response <- mock "CONNECT" "" "test" StrMap.empty
|
response <- mock "CONNECT" "" "test" StrMap.empty
|
||||||
case response of
|
case response of
|
||||||
(Request.Connect _ _ "test") -> pure unit
|
(Request.Connect _ _ "test") -> pure unit
|
||||||
a -> Assertions.fail $ "expected the body 'test', got " <> show a
|
(Request.Connect _ _ body) ->
|
||||||
|
Assertions.fail $ "expected the body 'test', got " <> body
|
||||||
|
a -> Assertions.fail $ "expected a connect, got " <> show a
|
||||||
|
|
||||||
Spec.describe "with a OPTIONS" do
|
Spec.describe "with a OPTIONS" do
|
||||||
Spec.it "is a Options" do
|
Spec.it "is a Options" do
|
||||||
@ -208,7 +214,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
|||||||
response <- mock "PATCH" "" "test" StrMap.empty
|
response <- mock "PATCH" "" "test" StrMap.empty
|
||||||
case response of
|
case response of
|
||||||
(Request.Patch _ _ "test") -> pure unit
|
(Request.Patch _ _ "test") -> pure unit
|
||||||
a -> Assertions.fail $ "expected the body 'test', got " <> show a
|
(Request.Patch _ _ body) ->
|
||||||
|
Assertions.fail $ "expected the body 'test', got " <> body
|
||||||
|
a -> Assertions.fail $ "expected a patch, got " <> show a
|
||||||
|
|
||||||
Spec.describe "with a GET" do
|
Spec.describe "with a GET" do
|
||||||
Spec.it "is a Get" do
|
Spec.it "is a Get" do
|
||||||
|
@ -1,40 +1,40 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.mockRequest = function(method) {
|
exports.mockRequest = function(method) {
|
||||||
return function(url) {
|
return function(url) {
|
||||||
return function(body) {
|
return function(body) {
|
||||||
return function(headers) {
|
return function(headers) {
|
||||||
return function() {
|
return function() {
|
||||||
var stream = new require('stream').Readable({
|
var stream = new require('stream').Readable({
|
||||||
read: function(size) {
|
read: function(size) {
|
||||||
this.push(body);
|
this.push(body);
|
||||||
this.push(null);
|
this.push(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
stream.method = method;
|
stream.method = method;
|
||||||
stream.url = url;
|
stream.url = url;
|
||||||
stream.headers = headers;
|
stream.headers = headers;
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.mockResponse = function() {
|
exports.mockResponse = function() {
|
||||||
return {
|
return {
|
||||||
body: "",
|
body: "",
|
||||||
headers: {},
|
headers: {},
|
||||||
|
|
||||||
write: function(str) {
|
write: function(str) {
|
||||||
this.body = this.body + str;
|
this.body = this.body + str;
|
||||||
},
|
},
|
||||||
|
|
||||||
end: function() { },
|
end: function() { },
|
||||||
|
|
||||||
setHeader: function(header, val) {
|
setHeader: function(header, val) {
|
||||||
this.headers[header] = val;
|
this.headers[header] = val;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -100,7 +100,7 @@ post :: forall e.
|
|||||||
String ->
|
String ->
|
||||||
String ->
|
String ->
|
||||||
Aff.Aff (HTTPRequestEffects e) String
|
Aff.Aff (HTTPRequestEffects e) String
|
||||||
post port headers path body = request port "POST" headers path body >>= toString
|
post port headers path = request port "POST" headers path >=> toString
|
||||||
|
|
||||||
-- | Convert a request to an Aff containing the string with the given header
|
-- | Convert a request to an Aff containing the string with the given header
|
||||||
-- | value.
|
-- | value.
|
||||||
|
Loading…
Reference in New Issue
Block a user