aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChloe Kudryavtsev <code@toast.bunkerlabs.net>2023-03-28 17:10:07 -0400
committerChloe Kudryavtsev <code@toast.bunkerlabs.net>2023-03-28 17:10:07 -0400
commit2133d0d0d5df5fae9336e8b6a7107a0645643bca (patch)
treed5db4977991c446af0cf995a031b0ac979614d6b
parentmeta: depend on spork (diff)
meta: all the tests
ok not all the tests just testing the high level api the other top level things would be: 02-request and 01-native probably to be done native mostly useful for regression testing and seeing what went wrong where for example, if the high level api is what broke, and not request or if it was the native stuff that broke, and not anything else etc
-rw-r--r--README.md1
-rw-r--r--test/03-api/01-methods/connect.janet3
-rw-r--r--test/03-api/01-methods/delete.janet4
-rw-r--r--test/03-api/01-methods/get.janet4
-rw-r--r--test/03-api/01-methods/head.janet4
-rw-r--r--test/03-api/01-methods/options.janet4
-rw-r--r--test/03-api/01-methods/patch.janet4
-rw-r--r--test/03-api/01-methods/post.janet4
-rw-r--r--test/03-api/01-methods/put.janet4
-rw-r--r--test/03-api/01-methods/trace.janet3
-rw-r--r--test/03-api/02-body/delete.janet11
-rw-r--r--test/03-api/02-body/get.janet11
-rw-r--r--test/03-api/02-body/patch.janet11
-rw-r--r--test/03-api/02-body/post.janet11
-rw-r--r--test/03-api/02-body/put.janet11
-rw-r--r--test/03-api/03-fields/cookies.janet21
-rw-r--r--test/03-api/03-fields/files.janet44
-rw-r--r--test/03-api/03-fields/forms.janet53
-rw-r--r--test/03-api/03-fields/headers.janet28
19 files changed, 235 insertions, 1 deletions
diff --git a/README.md b/README.md
index 91108e9..ea295b8 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,6 @@ However, for 90+% of use-cases, it should be more than sufficient,
and is far more complete and convenient than most http clients I've worked with so far, including in other languages.
For examples of the various APIs, see the tests!
-P.S. There are no tests yet, soon though.
## Installation
`jpm install https://github.com/cosmictoast/jurl.git`
diff --git a/test/03-api/01-methods/connect.janet b/test/03-api/01-methods/connect.janet
new file mode 100644
index 0000000..db2e804
--- /dev/null
+++ b/test/03-api/01-methods/connect.janet
@@ -0,0 +1,3 @@
+(use ../../../jurl)
+# TODO
+(os/exit 0)
diff --git a/test/03-api/01-methods/delete.janet b/test/03-api/01-methods/delete.janet
new file mode 100644
index 0000000..3d0c663
--- /dev/null
+++ b/test/03-api/01-methods/delete.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/delete"
+ (http :delete))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/get.janet b/test/03-api/01-methods/get.janet
new file mode 100644
index 0000000..39da987
--- /dev/null
+++ b/test/03-api/01-methods/get.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/get"
+ (http :get))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/head.janet b/test/03-api/01-methods/head.janet
new file mode 100644
index 0000000..6b36654
--- /dev/null
+++ b/test/03-api/01-methods/head.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/anything"
+ (http :head))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/options.janet b/test/03-api/01-methods/options.janet
new file mode 100644
index 0000000..3f925b5
--- /dev/null
+++ b/test/03-api/01-methods/options.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/anything"
+ (http :options))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/patch.janet b/test/03-api/01-methods/patch.janet
new file mode 100644
index 0000000..8278392
--- /dev/null
+++ b/test/03-api/01-methods/patch.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/patch"
+ (http :patch))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/post.janet b/test/03-api/01-methods/post.janet
new file mode 100644
index 0000000..10ed088
--- /dev/null
+++ b/test/03-api/01-methods/post.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/post"
+ (http :post))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/put.janet b/test/03-api/01-methods/put.janet
new file mode 100644
index 0000000..87f151d
--- /dev/null
+++ b/test/03-api/01-methods/put.janet
@@ -0,0 +1,4 @@
+(use ../../../jurl)
+(def res ((->> "https://pie.dev/put"
+ (http :put))))
+(assert (= 200 (res :status)))
diff --git a/test/03-api/01-methods/trace.janet b/test/03-api/01-methods/trace.janet
new file mode 100644
index 0000000..db2e804
--- /dev/null
+++ b/test/03-api/01-methods/trace.janet
@@ -0,0 +1,3 @@
+(use ../../../jurl)
+# TODO
+(os/exit 0)
diff --git a/test/03-api/02-body/delete.janet b/test/03-api/02-body/delete.janet
new file mode 100644
index 0000000..6a4c395
--- /dev/null
+++ b/test/03-api/02-body/delete.janet
@@ -0,0 +1,11 @@
+(use ../../../jurl)
+(import spork/json)
+(def body "hi")
+(def res ((->> "https://pie.dev/anything"
+ (http :delete)
+ (body-plain body))))
+(assert (= 200 (res :status)))
+(def bres (json/decode (res :body) true))
+(assert (= "DELETE" (bres :method)))
+(assert (= body (bres :data)))
+(assert (= "text/plain" (get-in bres [:headers :Content-Type])))
diff --git a/test/03-api/02-body/get.janet b/test/03-api/02-body/get.janet
new file mode 100644
index 0000000..a713b39
--- /dev/null
+++ b/test/03-api/02-body/get.janet
@@ -0,0 +1,11 @@
+(use ../../../jurl)
+(import spork/json)
+(def body "hi")
+(def res ((->> "https://pie.dev/anything"
+ (http :get)
+ (body-plain body))))
+(assert (= 200 (res :status)))
+(def bres (json/decode (res :body) true))
+(assert (= "GET" (bres :method)))
+(assert (= "" (bres :data)))
+(assert (= "text/plain" (get-in bres [:headers :Content-Type])))
diff --git a/test/03-api/02-body/patch.janet b/test/03-api/02-body/patch.janet
new file mode 100644
index 0000000..3987f56
--- /dev/null
+++ b/test/03-api/02-body/patch.janet
@@ -0,0 +1,11 @@
+(use ../../../jurl)
+(import spork/json)
+(def body "hi")
+(def res ((->> "https://pie.dev/anything"
+ (http :patch)
+ (body-plain body))))
+(assert (= 200 (res :status)))
+(def bres (json/decode (res :body) true))
+(assert (= "PATCH" (bres :method)))
+(assert (= body (bres :data)))
+(assert (= "text/plain" (get-in bres [:headers :Content-Type])))
diff --git a/test/03-api/02-body/post.janet b/test/03-api/02-body/post.janet
new file mode 100644
index 0000000..7885e09
--- /dev/null
+++ b/test/03-api/02-body/post.janet
@@ -0,0 +1,11 @@
+(use ../../../jurl)
+(import spork/json)
+(def body "hi")
+(def res ((->> "https://pie.dev/anything"
+ (http :post)
+ (body-plain body))))
+(assert (= 200 (res :status)))
+(def bres (json/decode (res :body) true))
+(assert (= "POST" (bres :method)))
+(assert (= body (bres :data)))
+(assert (= "text/plain" (get-in bres [:headers :Content-Type])))
diff --git a/test/03-api/02-body/put.janet b/test/03-api/02-body/put.janet
new file mode 100644
index 0000000..d1ee49b
--- /dev/null
+++ b/test/03-api/02-body/put.janet
@@ -0,0 +1,11 @@
+(use ../../../jurl)
+(import spork/json)
+(def body "hi")
+(def res ((->> "https://pie.dev/anything"
+ (http :put)
+ (body-plain body))))
+(assert (= 200 (res :status)))
+(def bres (json/decode (res :body) true))
+(assert (= "PUT" (bres :method)))
+(assert (= body (bres :data)))
+(assert (= "text/plain" (get-in bres [:headers :Content-Type])))
diff --git a/test/03-api/03-fields/cookies.janet b/test/03-api/03-fields/cookies.janet
new file mode 100644
index 0000000..81909a5
--- /dev/null
+++ b/test/03-api/03-fields/cookies.janet
@@ -0,0 +1,21 @@
+(use ../../../jurl)
+(import spork/json)
+(def one (->> "https://pie.dev/cookies"
+ (http :get)
+ (cookies {:a :b})))
+(def two (->> one
+ (cookies {:a :c
+ :b :d})))
+
+(def rone (one))
+(assert (= 200 (rone :status)))
+
+(def rtwo (two))
+(assert (= 200 (rtwo :status)))
+
+(def jone ((json/decode (rone :body) true) :cookies))
+(def jtwo ((json/decode (rtwo :body) true) :cookies))
+
+(assert (= (freeze jone) {:a "b"}))
+(assert (= (freeze jtwo) {:a "c"
+ :b "d"}))
diff --git a/test/03-api/03-fields/files.janet b/test/03-api/03-fields/files.janet
new file mode 100644
index 0000000..ea015d2
--- /dev/null
+++ b/test/03-api/03-fields/files.janet
@@ -0,0 +1,44 @@
+(use ../../../jurl)
+(import spork/json)
+
+(def fone "file 1")
+(def ftwo "file 2")
+
+# POST
+(def one (->> "https://pie.dev/post"
+ (http :post)
+ # the way to do file uploads in post is with mime/multipart
+ (body [{:name "one"
+ :data fone
+ :filename "remote.file"}
+ {:name "two"
+ :data ftwo
+ :filename "other.remote"}])))
+(def two (->> one
+ # multipart mimes come as a bundle, so this overwrites
+ (body [{:name "one"
+ :data fone
+ :filename "remote.file"}])))
+
+(def rone (one))
+(assert (= 200 (rone :status)))
+
+(def rtwo (two))
+(assert (= 200 (rtwo :status)))
+
+(def jone ((json/decode (rone :body) true) :files))
+(def jtwo ((json/decode (rtwo :body) true) :files))
+
+(assert (= fone (jone :one)))
+(assert (= ftwo (jone :two)))
+(assert (= fone (jtwo :one)))
+(assert (= :nothing (get jtwo :two :nothing)))
+
+# PUT
+(def pst (->> "https://pie.dev/put"
+ (http :put)
+ (body-plain fone)))
+(def rpst (pst))
+(assert (= 200 (rpst :status)))
+(def jpst (json/decode (rpst :body) true))
+(assert (= fone (jpst :data)))
diff --git a/test/03-api/03-fields/forms.janet b/test/03-api/03-fields/forms.janet
new file mode 100644
index 0000000..f88a752
--- /dev/null
+++ b/test/03-api/03-fields/forms.janet
@@ -0,0 +1,53 @@
+(use ../../../jurl)
+(import spork/json)
+
+(def fone "form 1")
+(def ftwo "form 2")
+
+# mime/multipart
+(def one (->> "https://pie.dev/post"
+ (http :post)
+ (body [{:name "one"
+ :data fone}
+ {:name "two"
+ :data ftwo}])))
+(def two (->> one
+ (body [{:name "one"
+ :data fone}])))
+
+(def rone (one))
+(assert (= 200 (rone :status)))
+
+(def rtwo (two))
+(assert (= 200 (rtwo :status)))
+
+(def jone ((json/decode (rone :body) true) :form))
+(def jtwo ((json/decode (rtwo :body) true) :form))
+
+(assert (= fone (jone :one)))
+(assert (= ftwo (jone :two)))
+(assert (= fone (jtwo :one)))
+(assert (= :nothing (get jtwo :two :nothing)))
+
+# x-www-urlencoded
+(def one (->> "https://pie.dev/post"
+ (http :post)
+ (body {:one fone
+ :two ftwo})))
+(def two (->> one
+ # body similarly gets overwritten
+ (body {:one fone})))
+
+(def rone (one))
+(assert (= 200 (rone :status)))
+
+(def rtwo (two))
+(assert (= 200 (rtwo :status)))
+
+(def jone ((json/decode (rone :body) true) :form))
+(def jtwo ((json/decode (rtwo :body) true) :form))
+
+(assert (= fone (jone :one)))
+(assert (= ftwo (jone :two)))
+(assert (= fone (jtwo :one)))
+(assert (= :nothing (get jtwo :two :nothing)))
diff --git a/test/03-api/03-fields/headers.janet b/test/03-api/03-fields/headers.janet
new file mode 100644
index 0000000..8b10aa2
--- /dev/null
+++ b/test/03-api/03-fields/headers.janet
@@ -0,0 +1,28 @@
+(use ../../../jurl)
+(import spork/json)
+
+(def hone "header 1")
+(def htwo "header 2")
+
+(def one (->> "https://pie.dev/get"
+ (http :get)
+ (headers {:one hone})))
+(def two (->> one
+ # headers are additive
+ (headers {:two htwo})))
+
+(def rone (one))
+(assert (= 200 (rone :status)))
+
+(def rtwo (two))
+(assert (= 200 (rtwo :status)))
+
+(def jone ((json/decode (rone :body) true) :headers))
+(def jtwo ((json/decode (rtwo :body) true) :headers))
+
+# note: pie.dev Capitalizes-Headers-Like-This on its own
+# we actually always lowercase them on send, but receive as-is
+(assert (= hone (jone :One)))
+(assert (= :nothing (get jone :Two :nothing)))
+(assert (= hone (jtwo :One)))
+(assert (= htwo (jtwo :Two)))