diff options
| author | 2023-03-28 17:10:07 -0400 | |
|---|---|---|
| committer | 2023-03-28 17:10:07 -0400 | |
| commit | 2133d0d0d5df5fae9336e8b6a7107a0645643bca (patch) | |
| tree | d5db4977991c446af0cf995a031b0ac979614d6b /test/03-api/03-fields/forms.janet | |
| parent | meta: 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
Diffstat (limited to '')
| -rw-r--r-- | test/03-api/03-fields/forms.janet | 53 |
1 files changed, 53 insertions, 0 deletions
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))) |
