Skip to content

Commit

Permalink
Add automated testing (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerauko authored May 30, 2023
2 parents b80a634 + 8bfb518 commit 19320de
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
key: maven-${{ hashFiles('shadow-cljs.edn') }}
- run: yarn
- run: yarn lint
- run: yarn test
- name: wrike-ist
env:
WRIKE_TOKEN: ${{ secrets.WRIKE_TOKEN }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ node_modules/
jspm_packages/
resources/cljs-runtime

# Test build
resources/test.js

# TypeScript v1 declaration files
typings/

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"scripts": {
"build": "shadow-cljs compile main",
"lint": "shadow-cljs run clj-kondo.main --lint src",
"test": "shadow-cljs compile test",
"repl": "shadow-cljs node-repl",
"release": "rm -f resources/*.js && shadow-cljs release main && ncc build resources/main.js -o resources",
"clean": "rm -rf target && rm -f resources/main.js",
"clean": "rm -rf target && rm -f resources/*.js",
"hard-reset": "yarn clean && rm -rf node_modules && rm -f yarn.lock"
},
"repository": {
Expand Down
7 changes: 5 additions & 2 deletions shadow-cljs.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; shadow-cljs configuration
{:source-paths ["src"]
{:source-paths ["src" "test"]

:dependencies [[funcool/httpurr "2.0.0"]
[clj-kondo "2022.09.08"]]
Expand All @@ -14,4 +14,7 @@
:compiler-options {:optimizations :simple}
:output-to "resources/main.js"
:output-dir "resources"
:main wrike-ist.core/main}}}
:main wrike-ist.core/main}
:test {:target :node-test
:output-to "resources/test.js"
:autorun true}}}
46 changes: 46 additions & 0 deletions test/wrike_ist/core_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(ns wrike-ist.core-test
(:require [cljs.test :refer-macros [deftest is testing run-tests]]
[wrike-ist.core :refer [extract-details]]))

(deftest extract-details-test
(testing "No .body in payload"
(let [payload (clj->js {})]
(is (= nil (extract-details payload)))))
(testing "No link in payload"
(let [payload (clj->js {:body ""})]
(is (= nil (extract-details payload)))))
(testing "Extract link from payload"
(let [url "https://www.wrike.com/open.htm?id=1"
payload (clj->js {:body (str "a\n" url "\nb")})]
(is (= url (:permalink (extract-details payload))))))
(testing "Extract pull request URL from payload"
(let [url "https://github.com/valerauko/wrike-ist/pull/9001"
payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:html_url url})]
(is (= url (:pr-url (extract-details payload))))))
(testing "Extract pull request title from payload"
(let [title "hoge"
payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:title title})]
(is (= title (:title (extract-details payload))))))
(testing "Translating pull request state"
(let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:merged true
:state "closed"})]
(is (= :merged (:state (extract-details payload)))))
(let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:merged true})]
(is (= :merged (:state (extract-details payload)))))
(let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:merged false
:state "closed"})]
(is (= :closed (:state (extract-details payload)))))
(let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:state "closed"})]
(is (= :closed (:state (extract-details payload)))))
(let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"
:merged false
:state "open"})]
(is (= :open (:state (extract-details payload)))))
(let [payload (clj->js {:body "https://www.wrike.com/open.htm?id=1"})]
(is (= :open (:state (extract-details payload)))))))
15 changes: 15 additions & 0 deletions test/wrike_ist/wrike_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns wrike-ist.wrike-test
(:require [cljs.test :refer-macros [deftest is testing run-tests]]
[wrike-ist.wrike :refer [link-html]]))

(deftest link-html-test
(testing "No title"
(let [url "https://github.com/valerauko/wrike-ist/pull/9001"
data {:pr-url url}]
(is (= url (re-find (re-pattern url) (link-html data))))))
(testing "With title"
(let [url "https://github.com/valerauko/wrike-ist/pull/9001"
title "hoge"
data {:pr-url url :title title}]
(is (= url (re-find (re-pattern url) (link-html data))))
(is (= title (re-find (re-pattern title) (link-html data)))))))

0 comments on commit 19320de

Please sign in to comment.