@@ -4,36 +4,28 @@ pragma solidity ^0.8.13;
44import "forge-std/Test.sol " ;
55
66import {HTTP} from "@src/HTTP.sol " ;
7- import {HTTPBuilder} from "@src/HTTPBuilder.sol " ;
8- import {strings} from "solidity-stringutils/strings.sol " ;
9- import {StringMap} from "@src/StringMap.sol " ;
107import {strings} from "solidity-stringutils/strings.sol " ;
118import {stdJson} from "forge-std/StdJson.sol " ;
129
1310contract HTTPTest is Test {
11+ using HTTP for HTTP.Builder;
1412 using HTTP for HTTP.Request;
15- using HTTPBuilder for HTTP.Request;
16- using StringMap for StringMap.StringToStringMap;
1713 using strings for * ;
1814 using stdJson for string ;
1915
20- HTTP.Request req;
21- StringMap.StringToStringMap headers;
22- StringMap.StringToStringMap query;
16+ HTTP.Builder http;
2317
2418 function test_HTTP_GET () public {
25- req.withUrl ("https://jsonplaceholder.typicode.com/todos/1 " ).withMethod (HTTP.Method.GET);
26- HTTP.Response memory res = req.request ();
19+ HTTP.Response memory res = http.build ().GET ("https://jsonplaceholder.typicode.com/todos/1 " ).request ();
2720
2821 assertEq (res.status, 200 );
2922 assertEq (res.data, '{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false} ' );
3023 }
3124
3225 function test_HTTP_GET_options () public {
33- req.withUrl ("https://httpbin.org/headers " ).withHeader ("accept " , "application/json " ).withHeader (
34- "Authorization " , "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== "
35- ).withMethod (HTTP.Method.GET);
36- HTTP.Response memory res = req.request ();
26+ HTTP.Response memory res = http.build ().GET ("https://httpbin.org/headers " ).withHeader (
27+ "accept " , "application/json "
28+ ).withHeader ("Authorization " , "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== " ).request ();
3729
3830 assertEq (res.status, 200 );
3931
@@ -42,8 +34,8 @@ contract HTTPTest is Test {
4234 }
4335
4436 function test_HTTP_POST_form_data () public {
45- req. withUrl ( " https://httpbin.org/post " ). withMethod ( HTTP.
Method.POST). withBody ( " [email protected] " ); 46- HTTP.Response memory res = req .request ();
37+ HTTP.Response memory res =
38+ http. build (). POST ( " https://httpbin.org/post " ). withBody ( " [email protected] " ) .
request ();
4739
4840 assertEq (res.status, 200 );
4941
@@ -52,40 +44,35 @@ contract HTTPTest is Test {
5244 }
5345
5446 function test_HTTP_POST_json () public {
55- req.withUrl ("https://httpbin.org/post " ).withMethod (HTTP.Method.POST).withBody ('{"foo": "bar"} ' );
56- HTTP.Response memory res = req.request ();
47+ HTTP.Response memory res = http.build ().POST ("https://httpbin.org/post " ).withBody ('{"foo": "bar"} ' ).request ();
5748
5849 assertEq (res.status, 200 );
5950 assertTrue (res.data.toSlice ().contains (("foo " ).toSlice ()));
6051 assertTrue (res.data.toSlice ().contains (("bar " ).toSlice ()));
6152 }
6253
6354 function test_HTTP_PUT () public {
64- req.withUrl ("https://httpbin.org/put " ).withMethod (HTTP.Method.PUT);
65- HTTP.Response memory res = req.request ();
55+ HTTP.Response memory res = http.build ().PUT ("https://httpbin.org/put " ).request ();
6656 assertEq (res.status, 200 );
6757 }
6858
6959 function test_HTTP_PUT_json () public {
70- req. withUrl ( "https://httpbin.org/put " ). withMethod (HTTP.Method.PUT ).withBody ('{"foo": "bar"} ' ).withHeader (
60+ HTTP.Response memory res = http. build (). PUT ( "https://httpbin.org/put " ).withBody ('{"foo": "bar"} ' ).withHeader (
7161 "Content-Type " , "application/json "
72- );
73- HTTP.Response memory res = req.request ();
62+ ).request ();
7463
7564 assertEq (res.status, 200 );
7665 assertTrue (res.data.toSlice ().contains (('"foo" ' ).toSlice ()));
7766 assertTrue (res.data.toSlice ().contains (('"bar" ' ).toSlice ()));
7867 }
7968
8069 function test_HTTP_DELETE () public {
81- req.withUrl ("https://httpbin.org/delete " ).withMethod (HTTP.Method.DELETE);
82- HTTP.Response memory res = req.request ();
70+ HTTP.Response memory res = http.build ().DELETE ("https://httpbin.org/delete " ).request ();
8371 assertEq (res.status, 200 );
8472 }
8573
8674 function test_HTTP_PATCH () public {
87- req.withUrl ("https://httpbin.org/patch " ).withMethod (HTTP.Method.PATCH);
88- HTTP.Response memory res = req.request ();
75+ HTTP.Response memory res = http.build ().PATCH ("https://httpbin.org/patch " ).request ();
8976 assertEq (res.status, 200 );
9077 }
9178}
0 commit comments