From 2133d0d0d5df5fae9336e8b6a7107a0645643bca Mon Sep 17 00:00:00 2001 From: Chloe Kudryavtsev Date: Tue, 28 Mar 2023 17:10:07 -0400 Subject: 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 --- test/03-api/03-fields/forms.janet | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/03-api/03-fields/forms.janet (limited to 'test/03-api/03-fields/forms.janet') 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))) -- cgit v1.2.3