Browse Source
These tests check the shape of the data produced by the light meters in the welding in booths in Ritherdon. I've place a note with the factory3 tests explaining the reason why there is a factory3 in the system but there is not actual light meter in the third welding booth in Ritherdon.unstable
Craig Oates
3 years ago
1 changed files with 76 additions and 0 deletions
@ -0,0 +1,76 @@ |
|||||||
|
;;;; 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")))))) |
Reference in new issue