commit 8560c6f5c603abbabe5ebe469fdf157760ca611b
parent ac1d1528e797d7e371f180365301042c8d77fbd1
Author: Decay <decay@todayiwilllaunchmyinfantsonintoorbit.com>
Date: Mon, 21 Nov 2022 21:52:57 -0800
Fix test suite
Tests now pass correctly, begun fleshing out tests, still lots more work
to do.
Diffstat:
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/src/rpc.lisp b/src/rpc.lisp
@@ -56,7 +56,7 @@ Each batch item is a CONS structured as ([request] . [input data]). For requests
("false" . nil)
("false" . :false)))
(batch-input (encode-json-alist-to-string input-items)))
- (cohost-rpc client batch :get :batch "1" :input batch-input))))
+ (cohost-rpc client batch :get :batch 1 :input batch-input))))
(defmacro define-trpc-request (name (&rest lambda-list))
"Macro for defining tRPC request objects.
diff --git a/tests/main.lisp b/tests/main.lisp
@@ -38,7 +38,7 @@
;; Batch input
((and (string= uri "https://cohost.org/api/v1/trpc/projects.listEditedProjects,login.loggedIn,bookmarks.tags.list,users.displayPrefs,posts.isLiked")
(string= (assoc-val "input" parameters) "{\"4\":12345}")
- (eql (assoc-val "batch" parameters) 1)
+ (string= (assoc-val "batch" parameters) "1")
(eql method :get))
"{\"foo\":1}")))
@@ -73,9 +73,11 @@
(ok (let ((result (test.atomic-param 42)))
(and (string= (car result) "test.atomicParam")
(eq (cdr result) 42))))
- (ok (let ((result (test.structured-params "foo" "bar")))
+ (ok (let* ((result (test.structured-params "foo" "bar"))
+ (params (cdr result)))
(and (string= (car result) "test.structuredParams")
- (string= (cdr result) "{\"firstParam\":\"foo\",\"secondParam\":\"bar\"}"))))))
+ (string= (assoc-val "firstParam" params) "foo")
+ (string= (assoc-val "secondParam" params) "bar"))))))
(deftest cohost-api-tests
(with-test-client (client)
@@ -86,31 +88,51 @@
(and (eql (assoc-val :status response) 422)
(string= (assoc-val :message response) "Login Failed")))))))
-(deftest cohost-high-level-tests
+(deftest cohost-creation-tests
(with-test-client (client)
(testing "Can create new post object with no parameters"
- (ok (let ((chost (cohost.client:new-post client)))
- (and (null (cohost.client:adult-content chost))
+ (ok (let* ((project "TestProject")
+ (chost (cohost.client:new-post client project)))
+ (and (string= (cohost.client:project chost) project)
+ (null (cohost.client:draft chost))
+ (null (cohost.client:adult-content chost))
(null (cohost.client:content-blocks chost))
(null (cohost.client:content-warnings chost))
(null (cohost.client:headline chost))
(null (cohost.client:tags chost))))))
(testing "Can create new post object with a full set of parameters"
- (ok (let* ((adult t)
- (content-block "test")
+ (ok (let* ((content-block "test")
(cw "test-cw")
(headline "test")
(tag "test-tag")
- (chost (cohost.client:new-post client :adult-content adult
+ (project "TestProject")
+ (chost (cohost.client:new-post client project
+ :draft t
+ :adult-content t
:blocks (list content-block)
:content-warnings (list cw)
:headline headline
:tags (list tag))))
- (and (cohost.client:adult-content chost)
+ (and (string= (cohost.client:project chost) project)
+ (cohost.client:draft chost)
+ (cohost.client:adult-content chost)
(eql (length (cohost.client:content-blocks chost)) 1)
(string= (car (cohost.client:content-blocks chost)) content-block)
(eql (length (cohost.client:content-warnings chost)) 1)
(string= (car (cohost.client:content-warnings chost)) cw)
(string= (cohost.client:headline chost) headline)
(eql (length (cohost.client:tags chost)) 1)
- (string= (car (cohost.client:tags chost)) tag)))))))
+ (string= (car (cohost.client:tags chost)) tag)))))
+ (testing "Can create markdown block object"
+ (ok (let* ((content "test content")
+ (markdown (cohost.client:new-markdown-block client content)))
+ (string= (cohost.client:content markdown) content))))
+ (testing "Can create attachment block object with and without alt-text"
+ (ok (let* ((attachment-id 12345)
+ (alt-text "foo")
+ (attachment-with-alt (cohost.client:new-attachment client attachment-id :alt-text alt-text))
+ (attachment-without-alt (cohost.client:new-attachment client attachment-id)))
+ (and (eql (cohost.client:attachment-id attachment-with-alt) attachment-id)
+ (eql (cohost.client:attachment-id attachment-without-alt) attachment-id)
+ (string= (cohost.client:alt-text attachment-with-alt) alt-text)
+ (not (cohost.client:alt-text attachment-without-alt))))))))