UNPKG

fluentnode

Version:

Fluent apis for node (based on the concepts used in C#'s FluentSharp

390 lines (263 loc) 13.6 kB
<!DOCTYPE html> <html> <head> <title>http.GET.test.coffee</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <ul id="jump_to"> <li> <a class="large" href="javascript:void(0);">Jump To &hellip;</a> <a class="small" href="javascript:void(0);">+</a> <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="assert_Array.html"> assert_Array.litcoffee </a> <a class="source" href="assert_Boolean.html"> assert_Boolean.litcoffee </a> <a class="source" href="assert_Function.html"> assert_Function.litcoffee </a> <a class="source" href="assert_Number.html"> assert_Number.litcoffee </a> <a class="source" href="assert_Object.html"> assert_Object.litcoffee </a> <a class="source" href="assert_String.html"> assert_String.litcoffee </a> <a class="source" href="fluentnode.html"> fluentnode.coffee </a> <a class="source" href="index.html"> index.md </a> <a class="source" href="Array.html"> Array.litcoffee </a> <a class="source" href="Boolean.html"> Boolean.litcoffee </a> <a class="source" href="Function.html"> Function.litcoffee </a> <a class="source" href="Number.html"> Number.litcoffee </a> <a class="source" href="Object.html"> Object.litcoffee </a> <a class="source" href="String.html"> String.litcoffee </a> <a class="source" href="console.html"> console.litcoffee </a> <a class="source" href="crypto.html"> crypto.litcoffee </a> <a class="source" href="fs.html"> fs.litcoffee </a> <a class="source" href="http.GET.html"> http.GET.litcoffee </a> <a class="source" href="http.POST.html"> http.POST.litcoffee </a> <a class="source" href="http.Server.html"> http.Server.litcoffee </a> <a class="source" href="http.html"> http.litcoffee </a> <a class="source" href="path.html"> path.litcoffee </a> <a class="source" href="process.html"> process.litcoffee </a> <a class="source" href="encoding.html"> encoding.litcoffee </a> <a class="source" href="globals.html"> globals.litcoffee </a> <a class="source" href="assert_Array.test.html"> assert_Array.test.coffee </a> <a class="source" href="assert_Boolean.test.html"> assert_Boolean.test.coffee </a> <a class="source" href="assert_Function.test.html"> assert_Function.test.coffee </a> <a class="source" href="assert_Number.test.html"> assert_Number.test.coffee </a> <a class="source" href="assert_Object.test.html"> assert_Object.test.coffee </a> <a class="source" href="assert_String.test.html"> assert_String.test.coffee </a> <a class="source" href="fluentnode.test.html"> fluentnode.test.coffee </a> <a class="source" href="Array.test.html"> Array.test.coffee </a> <a class="source" href="Boolean.test.html"> Boolean.test.coffee </a> <a class="source" href="Function.test.html"> Function.test.coffee </a> <a class="source" href="Number.test.html"> Number.test.coffee </a> <a class="source" href="Object.test.html"> Object.test.coffee </a> <a class="source" href="String.test.html"> String.test.coffee </a> <a class="source" href="console.test.html"> console.test.coffee </a> <a class="source" href="crypto.test.html"> crypto.test.coffee </a> <a class="source" href="fs.test.html"> fs.test.coffee </a> <a class="source" href="http.GET.test.html"> http.GET.test.coffee </a> <a class="source" href="http.POST.test.html"> http.POST.test.coffee </a> <a class="source" href="http.Server.test.html"> http.Server.test.coffee </a> <a class="source" href="http.test.html"> http.test.coffee </a> <a class="source" href="path.test.html"> path.test.coffee </a> <a class="source" href="process.test.html"> process.test.coffee </a> <a class="source" href="encoding.test.html"> encoding.test.coffee </a> <a class="source" href="globals.test.html"> globals.test.coffee </a> </div> </li> </ul> <ul class="sections"> <li id="title"> <div class="annotation"> <h1>http.GET.test.coffee</h1> </div> </li> <li id="section-1"> <div class="annotation"> <div class="pilwrap "> <a class="pilcrow" href="#section-1">&#182;</a> </div> </div> <div class="content"><div class='highlight'><pre><span class="hljs-built_in">require</span>(<span class="hljs-string">'../../src/fluentnode'</span>) http = <span class="hljs-built_in">require</span> <span class="hljs-string">'http'</span> describe <span class="hljs-string">'| http.GET'</span>,<span class="hljs-function">-&gt;</span> test_Port = <span class="hljs-number">45566</span> + Math.floor((Math.random() * <span class="hljs-number">100</span>) + <span class="hljs-number">1</span>) test_Ip = <span class="hljs-string">'127.0.0.1'</span> test_Data = <span class="hljs-string">'hello from web'</span> url = <span class="hljs-string">"http://<span class="hljs-subst">#{test_Ip}</span>:<span class="hljs-subst">#{test_Port}</span>"</span> bad_Url = <span class="hljs-string">'http://aaaa.cccc.aaaa.dddd'</span> server = <span class="hljs-literal">null</span> before (done)-&gt; server = http.createServer(<span class="hljs-literal">null</span>) server.listen_OnPort_Saying test_Port, test_Data, <span class="hljs-function"><span class="hljs-params">()</span>=&gt;</span> <span class="hljs-built_in">global</span>.__fluentnode.http.HTTP_GET_TIMEOUT = <span class="hljs-number">30</span> done() after (done)-&gt; server.close_And_Destroy_Sockets ()-&gt; <span class="hljs-built_in">global</span>.__fluentnode.http.HTTP_GET_TIMEOUT = <span class="hljs-number">500</span> done() it <span class="hljs-string">'GET_Json, json_GET'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> <span class="hljs-string">''</span>.json_GET.assert_Is <span class="hljs-string">''</span>.GET_Json data = { a : <span class="hljs-number">42</span>} server.respond_With_Object_As_Json data url.json_GET (json)-&gt; json .assert_Is data json.a.assert_Is <span class="hljs-number">42</span> done() it <span class="hljs-string">'json_GET (bad url)'</span>, <span class="hljs-function">-&gt;</span> bad_Url.GET_Json (json)-&gt; json.assert_Is {} it <span class="hljs-string">'json_GET_With_Timeout'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> data = { a : <span class="hljs-number">42</span>} server.respond_With_Object_As_Json data url.json_GET_With_Timeout (data)-&gt; data.assert_Is data done() it <span class="hljs-string">'json_GET_With_Timeout (bad url)'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> bad_Url.json_GET_With_Timeout (data)-&gt; data.assert_Is {} done() it <span class="hljs-string">'http_GET'</span> , <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> server.respond_With_String_As_Text test_Data req = url.http_GET (err, data, res)-&gt; assert_Is_Null(err) data.assert_Is_String() req.assert_Instance_Of(http.ClientRequest) res.assert_Instance_Of(http.IncomingMessage) data.assert_Is(test_Data) done() it <span class="hljs-string">'http_GET bad port)'</span> , <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> (<span class="hljs-function">-&gt;</span> url.append(<span class="hljs-number">1</span>).http_GET()).assert_Throws (error)-&gt; error.message.assert_Contains <span class="hljs-string">"port should be &gt;= 0 and &lt; 65536: "</span> done() it <span class="hljs-string">'http_GET_Wait_For_Null'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> url.http_GET_Wait_For_Null (err)-&gt; assert_Is_Null err done() <span class="hljs-number">20.</span>wait -&gt; server.respond_With_String_As_Text <span class="hljs-literal">null</span> it <span class="hljs-string">'http_GET_Wait_For_Null (no null is returned from server)'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> server.respond_With_String_As_Text <span class="hljs-string">'123'</span> attempts = ~~(<span class="hljs-built_in">global</span>.__fluentnode.http.HTTP_GET_TIMEOUT / <span class="hljs-built_in">global</span>.__fluentnode.http.HTTP_GET_DELAY) <span class="hljs-function"> <span class="hljs-title">check</span> = <span class="hljs-params">(err)</span>-&gt;</span> err.message.assert_Is <span class="hljs-string">"[http_GET_Wait_For_Null] never got a null from server <span class="hljs-subst">#{url}</span> after <span class="hljs-subst">#{attempts}</span> attempts"</span> done() url.http_GET_Wait_For_Null check, attempts it <span class="hljs-string">'http_GET_With_Timeout'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> value = <span class="hljs-string">'asd'</span>.add_5_Random_Letters() server.respond_With_String_As_Text <span class="hljs-literal">null</span> url.http_GET_With_Timeout (data)-&gt; data.assert_Is value done() <span class="hljs-number">20.</span>wait -&gt; server.respond_With_String_As_Text value it <span class="hljs-string">'http_GET_With_Timeout (null is always returned from server)'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-&gt;</span> server.respond_With_String_As_Text <span class="hljs-literal">null</span> url.http_GET_With_Timeout (data)-&gt; assert_Is_Null data done()</pre></div></div> </li> </ul> </div> </body> </html>