Skip to content

Commit

Permalink
fixed linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
just-sultanov committed Oct 21, 2019
1 parent 6f389b5 commit bd2733f
Showing 1 changed file with 59 additions and 61 deletions.
120 changes: 59 additions & 61 deletions test/clj_fsm/fsm_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -165,64 +165,62 @@

(deftest ^:unit init-finish-test
(testing "initializing `fsm`:"
(def d {:document/name " sImplE nAme "
:document/author "John Doe"})

(def f {::sut/name :document/fsm
::sut/desc "Simple document FSM"
::sut/states {:document/unverified {::fsm.state/desc "Unverified", ::fsm.state/initial? true}
:document/verified {::fsm.state/desc "Verified"}
:document/published {::fsm.state/desc "Published"}
:document/archived {::fsm.state/desc "Archived", ::fsm.state/finish? true}
:document/rejected {::fsm.state/desc "Rejected"}}
::sut/events {:document/verify {::fsm.event/transition-from [:document/unverified]
::fsm.event/transition-to [:document/verified]}
:document/reject {::fsm.event/transition-from [:document/unverified]
::fsm.event/transition-to [:document/rejected]}
:document/reverify {::fsm.event/transition-from [:document/verified]
::fsm.event/transition-to [:document/unverified]}
:document/publish {::fsm.event/transition-from [:document/verified]
::fsm.event/transition-to [:document/published]}
:document/unpublish {::fsm.event/transition-from [:document/published]
::fsm.event/transition-to [:document/verified]}
:document/archive {::fsm.event/transition-from [:document/published :document/verified :document/unverified]
::fsm.event/transition-to [:document/archived]}}})

(def data (sut/assign d f))

(testing "should be returned a valid initial state name"
(is (= :document/unverified (sut/get-fsm-initial-state data))))

(testing "should be returned a valid finish state name"
(is (= :document/archived (sut/get-fsm-finish-state data))))

(testing "should be returned a valid current state name"
(let [data' (sut/init data)]
(is (nil? (sut/get-fsm-previous-state data')))
(is (= :document/unverified (sut/get-fsm-current-state data')))))

(testing "should be returned a valid previous state name"
(let [data' (-> data
sut/init
(sut/apply-state :document/verified))]
(is (= :document/unverified (sut/get-fsm-previous-state data')))
(is (= :document/verified (sut/get-fsm-current-state data')))))

(testing "should be returned valid states after initialize and finalize"
(let [data' (-> data
sut/init
sut/finish)]
(is (= :document/unverified (sut/get-fsm-previous-state data')))
(is (= :document/archived (sut/get-fsm-current-state data')))))

(testing "should be thrown an error on initializing data without `fsm`"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not exists assigned `fsm` in the given data" (-> data sut/unassign sut/init))))

(testing "should be thrown an error on finalizing data without `fsm`"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not exists assigned `fsm` in the given data" (-> data sut/unassign sut/finish))))

(testing "should be thrown an error on finalizing uninitialized `fsm`"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not initialized `fsm` in the given data" (sut/finish data))))

(testing "should be thrown an error on applying not existing state"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not exists `fsm` state with the given name" (sut/apply-state data ::unknown))))))
(let [d {:document/name " sImplE nAme "
:document/author "John Doe"}
f {::sut/name :document/fsm
::sut/desc "Simple document FSM"
::sut/states {:document/unverified {::fsm.state/desc "Unverified", ::fsm.state/initial? true}
:document/verified {::fsm.state/desc "Verified"}
:document/published {::fsm.state/desc "Published"}
:document/archived {::fsm.state/desc "Archived", ::fsm.state/finish? true}
:document/rejected {::fsm.state/desc "Rejected"}}
::sut/events {:document/verify {::fsm.event/transition-from [:document/unverified]
::fsm.event/transition-to [:document/verified]}
:document/reject {::fsm.event/transition-from [:document/unverified]
::fsm.event/transition-to [:document/rejected]}
:document/reverify {::fsm.event/transition-from [:document/verified]
::fsm.event/transition-to [:document/unverified]}
:document/publish {::fsm.event/transition-from [:document/verified]
::fsm.event/transition-to [:document/published]}
:document/unpublish {::fsm.event/transition-from [:document/published]
::fsm.event/transition-to [:document/verified]}
:document/archive {::fsm.event/transition-from [:document/published :document/verified :document/unverified]
::fsm.event/transition-to [:document/archived]}}}
data (sut/assign d f)]

(testing "should be returned a valid initial state name"
(is (= :document/unverified (sut/get-fsm-initial-state data))))

(testing "should be returned a valid finish state name"
(is (= :document/archived (sut/get-fsm-finish-state data))))

(testing "should be returned a valid current state name"
(let [data' (sut/init data)]
(is (nil? (sut/get-fsm-previous-state data')))
(is (= :document/unverified (sut/get-fsm-current-state data')))))

(testing "should be returned a valid previous state name"
(let [data' (-> data
sut/init
(sut/apply-state :document/verified))]
(is (= :document/unverified (sut/get-fsm-previous-state data')))
(is (= :document/verified (sut/get-fsm-current-state data')))))

(testing "should be returned valid states after initialize and finalize"
(let [data' (-> data
sut/init
sut/finish)]
(is (= :document/unverified (sut/get-fsm-previous-state data')))
(is (= :document/archived (sut/get-fsm-current-state data')))))

(testing "should be thrown an error on initializing data without `fsm`"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not exists assigned `fsm` in the given data" (-> data sut/unassign sut/init))))

(testing "should be thrown an error on finalizing data without `fsm`"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not exists assigned `fsm` in the given data" (-> data sut/unassign sut/finish))))

(testing "should be thrown an error on finalizing uninitialized `fsm`"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not initialized `fsm` in the given data" (sut/finish data))))

(testing "should be thrown an error on applying not existing state"
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error) #"Not exists `fsm` state with the given name" (sut/apply-state data ::unknown)))))))

0 comments on commit bd2733f

Please sign in to comment.