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
|
||||
buf <- ST.newSTRef ""
|
||||
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
|
||||
|
||||
-- | 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
|
||||
case response of
|
||||
(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.it "is a Put" do
|
||||
@ -90,7 +92,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
||||
response <- mock "PUT" "" "test" StrMap.empty
|
||||
case response of
|
||||
(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.it "is a Delete" do
|
||||
@ -149,7 +153,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
||||
response <- mock "CONNECT" "" "test" StrMap.empty
|
||||
case response of
|
||||
(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.it "is a Options" do
|
||||
@ -208,7 +214,9 @@ fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
||||
response <- mock "PATCH" "" "test" StrMap.empty
|
||||
case response of
|
||||
(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.it "is a Get" do
|
||||
|
@ -1,40 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
exports.mockRequest = function(method) {
|
||||
return function(url) {
|
||||
return function(body) {
|
||||
return function(headers) {
|
||||
return function() {
|
||||
var stream = new require('stream').Readable({
|
||||
read: function(size) {
|
||||
this.push(body);
|
||||
this.push(null);
|
||||
}
|
||||
});
|
||||
stream.method = method;
|
||||
stream.url = url;
|
||||
stream.headers = headers;
|
||||
return function(url) {
|
||||
return function(body) {
|
||||
return function(headers) {
|
||||
return function() {
|
||||
var stream = new require('stream').Readable({
|
||||
read: function(size) {
|
||||
this.push(body);
|
||||
this.push(null);
|
||||
}
|
||||
});
|
||||
stream.method = method;
|
||||
stream.url = url;
|
||||
stream.headers = headers;
|
||||
|
||||
return stream;
|
||||
};
|
||||
};
|
||||
return stream;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
exports.mockResponse = function() {
|
||||
return {
|
||||
body: "",
|
||||
headers: {},
|
||||
return {
|
||||
body: "",
|
||||
headers: {},
|
||||
|
||||
write: function(str) {
|
||||
this.body = this.body + str;
|
||||
},
|
||||
write: function(str) {
|
||||
this.body = this.body + str;
|
||||
},
|
||||
|
||||
end: function() { },
|
||||
end: function() { },
|
||||
|
||||
setHeader: function(header, val) {
|
||||
this.headers[header] = val;
|
||||
}
|
||||
};
|
||||
setHeader: function(header, val) {
|
||||
this.headers[header] = val;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -100,7 +100,7 @@ post :: forall e.
|
||||
String ->
|
||||
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
|
||||
-- | value.
|
||||
|
Loading…
Reference in New Issue
Block a user