[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master e3e2608 6/8: Add test for a simple JSON post

From: Stefan Monnier
Subject: [elpa] master e3e2608 6/8: Add test for a simple JSON post
Date: Mon, 30 Mar 2020 09:06:29 -0400 (EDT)

branch: master
commit e3e260844ae7259f9e5f490d00772f18e5b1697c
Author: jcaw <address@hidden>
Commit: jcaw <address@hidden>

    Add test for a simple JSON post
    Want to ensure we can post JSON, and access it in the handler.
 web-server-test.el | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/web-server-test.el b/web-server-test.el
index 01e08f8..7ea02fa 100644
--- a/web-server-test.el
+++ b/web-server-test.el
@@ -184,6 +184,39 @@ 
       (ws-stop server))))
+(ert-deftest ws/parse-json-data ()
+  "Ensure we can send arbitrary data through to the handler
+The handler can then parse it itself."
+  (let ((server (ws-start nil ws-test-port))
+        (request (make-instance 'ws-request)))
+    (unwind-protect
+        (progn
+          (setf (pending request)
+                "POST /complex.org HTTP/1.1
+Host: localhost:4444
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 
+Accept: */*
+Accept-Language: en-US,en;q=0.5
+Accept-Encoding: gzip, deflate
+DNT: 1
+Content-Type: application/json
+Referer: http://localhost:4444/complex.org
+Content-Length: 33
+Cookie: __utma=111872281.1462392269.1345929539.1345929539.1345929539.1
+Connection: keep-alive
+Pragma: no-cache
+Cache-Control: no-cache
+{\"some example\": \"json data\"}")
+          (ws-parse-request request)
+          (let ((headers (cdr (headers request))))
+            (should (string= (cdr (assoc :CONTENT-TYPE headers))
+                             "application/json"))
+            (should (string= (oref request body)
+                             "{\"some example\": \"json data\"}")))
+      (ws-stop server)))))
 (ert-deftest ws/simple-post ()
   "Test a simple POST server."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]