1
0
Fork 0
A CLI program which grabs data from the Return to Ritherdon project's REST API server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 

76 lines
3.1 KiB

;;;; tests/main.lisp
(in-package #:ritherdon-rest-tests)
(def-suite all-tests
:description "The master suite of all ritherdon-rest tests.")
(in-suite all-tests)
;; These two examples show the 'full' call to the fiveAm test
;; functions. This is just for reference. The 'namespace' is already
;; 'imported' in 'package.lisp'.
;; (fiveam:test sum-1
;; (fiveam:is (= 3 (+ 1 2))))
;; (fiveam:run!)
;; How you would normally create the tests -- with fiveAM already
;; set-up in 'package.lisp' and not needing to be explicit about it
;; here. This is similar to 'using static' in C#.
(defun test-quasi()
(run! 'all-tests))
(test factory-1-light-reading-data
:description "Validates the (reading) data produced by `FACTORY1'."
(let ((data (ritherdon-rest:parse-request "/status/latest/1")))
;; Data should look something like:
;; ((:ID . 79) (:STATUS . "off") (:TIME . "2021-07-01T16:00:001")).
(is (= 3 (length data)))
(is (equal t (consp data)))
(is (equal ':id (first (nth 0 data))))
(is (equal ':status (first (nth 1 data))))
(is (equal ':time (first (nth 2 data))))
(is (equal t (typep (cdr (car data)) 'integer))) ; :id number
(is (> (cdr (car data)) 0))
(is (equal t (typep (cdr (car (cdr data))) 'string))) ; :status value
(is (equal t (or (string-equal (cdr (car (cdr data))) "off")
(string-equal (cdr (car (cdr data))) "on"))))))
(test factory-2-light-reading-data
:description "Validates the (reading) data produced by `FACTORY2'."
(let ((data (ritherdon-rest:parse-request "/status/latest/2")))
;; Data should look something like:
;; ((:ID . 79) (:STATUS . "off") (:TIME . "2021-07-01T16:00:001")).
(is (= 3 (length data)))
(is (equal t (consp data)))
(is (equal ':id (first (nth 0 data))))
(is (equal ':status (first (nth 1 data))))
(is (equal ':time (first (nth 2 data))))
(is (equal t (typep (cdr (car data)) 'integer))) ; :id number
(is (> (cdr (car data)) 0))
(is (equal t (typep (cdr (car (cdr data))) 'string))) ; :status value
(is (equal t (or (string-equal (cdr (car (cdr data))) "off")
(string-equal (cdr (car (cdr data))) "on"))))))
(test factory-3-light-reading-data
:description "Validates the (reading) data produced by `FACTORY3'."
(let ((data (ritherdon-rest:parse-request "/status/latest/3")))
;; Ritherdon has a third welding booth but it was not included in
;; the art project so no light sensor was installed. Therefore,
;; this should always return the 'default/initial/seed' data
;; readings.
;; Data should still take the same shape as factory1 and factory 2:
;; ((:ID . 1) (:STATUS . "off") (:TIME . "2021-04-26T20:42:19.400868")).
(is (= 3 (length data)))
(is (equal t (consp data)))
(is (equal ':id (first (nth 0 data))))
(is (equal ':status (first (nth 1 data))))
(is (equal ':time (first (nth 2 data))))
(is (equal t (typep (cdr (car data)) 'integer))) ; :id number
(is (> (cdr (car data)) 0))
(is (equal t (typep (cdr (car (cdr data))) 'string))) ; :status value
(is (equal t (or (string-equal (cdr (car (cdr data))) "off")
(string-equal (cdr (car (cdr data))) "on"))))))