Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort entitlements #2065

Merged
merged 3 commits into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/sql/queries.sql
Expand Up @@ -241,7 +241,7 @@ WHERE 1=1
/*~ (when (:is-active? params) */
AND entitlement.endt IS NULL
/*~ ) ~*/
;
ORDER BY entitlement.userId, res.resId, catAppId, entitlement.start, entitlement.endt;

-- :name save-attachment! :insert
INSERT INTO attachment
Expand Down
15 changes: 5 additions & 10 deletions test/clj/rems/api/test_entitlements.clj
Expand Up @@ -48,14 +48,12 @@
:end nil
:mail "malice@example.com"}
(dissoc x :start :application-id)))
(is (valid-date? (:start x))))
sort-entitlements (partial sort-by (juxt :mail :end))]
(is (valid-date? (:start x))))]
(testing "all"
(let [data (-> (request :get "/api/entitlements")
(authenticate api-key "developer")
handler
read-ok-body
sort-entitlements)]
read-ok-body)]
(is (= 2 (count data)))
(check-alice-entitlement (first data))
(check-malice-entitlement (second data))))
Expand All @@ -65,8 +63,7 @@
(let [data (-> (request :get "/api/entitlements")
(authenticate api-key userid)
handler
read-ok-body
sort-entitlements)]
read-ok-body)]
(is (= 2 (count data)))
(check-alice-entitlement (first data))
(check-malice-entitlement (second data)))))
Expand All @@ -75,8 +72,7 @@
(let [data (-> (request :get "/api/entitlements?resource=urn:nbn:fi:lb-201403262")
(authenticate api-key "developer")
handler
read-ok-body
sort-entitlements)]
read-ok-body)]
(is (= 2 (count data)))
(check-alice-entitlement (first data))
(check-malice-entitlement (second data))))
Expand All @@ -101,8 +97,7 @@
(let [data (-> (request :get "/api/entitlements?expired=true")
(authenticate api-key "owner")
handler
read-ok-body
sort-entitlements)]
read-ok-body)]
(is (= 3 (count data)))
(check-alice-entitlement (first data))
(check-alice-expired-entitlement (second data))
Expand Down
151 changes: 80 additions & 71 deletions test/clj/rems/test_browser.clj
Expand Up @@ -211,77 +211,86 @@
(add-to-cart "Default workflow")
(apply-for-resource "Default workflow")

(fill-form-field "Application title field" "Test name")
(fill-form-field "Text field" "Test")
(fill-form-field "Text area" "Test2")
(set-date "Date field" "2050-01-02")
(fill-form-field "Email field" "user@example.com")
;; leave attachment field empty
(is (not (field-visible? "Conditional field"))
"Conditional field is not visible before selecting option")
(select-option "Option list" "First option")
(wait-predicate #(field-visible? "Conditional field"))
(fill-form-field "Conditional field" "Conditional")
;; pick two options for the multi-select field:
(check-box "Option2")
(check-box "Option3")
;; leave "Text field with max length" empty
;; leave "Text are with max length" empty

(accept-licenses)
(send-application)
(is (= "Applied" (get-element-text *driver* :application-state))))

(testing "check a field answer"
(is (= "Test name" (get-element-text *driver* :form-1-field-fld2))))

(let [application-id (get-application-id)]
(testing "see application on applications page"
(go-to-applications)
(let [summary (get-application-summary application-id)]
(is (= "Default workflow" (:resource summary)))
(is (= "Applied" (:state summary)))
;; don't bother trying to predict the external id:
(is (.contains (:description summary) "Test name"))))
(testing "fetch application from API"
(let [application (:body
(http/get (str +test-url+ "/api/applications/" application-id)
{:as :json
:headers {"x-rems-api-key" "42"
"x-rems-user-id" "handler"}}))]
(testing "applicant information"
(is (= "alice" (get-in application [:application/applicant :userid])))
(is (= (set (map :license/id (:application/licenses application)))
(set (get-in application [:application/accepted-licenses :alice])))))
(testing "form fields"
(is (= "Test name" (:application/description application)))
(is (= [["label" ""]
["description" "Test name"]
["text" "Test"]
["texta" "Test2"]
["header" ""]
["date" "2050-01-02"]
["email" "user@example.com"]
["attachment" ""]
["option" "Option1"]
["text" "Conditional"]
["multiselect" "Option2 Option3"]
["label" ""]
["text" ""]
["texta" ""]]
(for [field (select [:application/forms ALL :form/fields ALL] application)]
;; TODO could test other fields here too, e.g. title
[(:field/type field)
(:field/value field)]))))

(testing "after navigating to the application view again"
(scroll-and-click *driver* [{:css "table.my-applications"}
{:tag :tr :data-row application-id}
{:css ".btn-primary"}])
(wait-visible *driver* {:tag :h1, :fn/has-text "Application"})
(wait-page-loaded)
(testing "check a field answer"
(is (= "Test name" (get-element-text *driver* :form-1-field-fld2))))))))))
(let [application-id (get-application-id)
application (:body
(http/get (str +test-url+ "/api/applications/" application-id)
{:as :json
:headers {"x-rems-api-key" "42"
"x-rems-user-id" "handler"}}))
form-id (get-in application [:application/forms 0 :form/id])
field-id (get-in application [:application/forms 0 :form/fields 1 :field/id])
field-selector (keyword (str "form-" form-id "-field-" field-id))] ; :form-1-field-fld2
(fill-form-field "Application title field" "Test name")
(fill-form-field "Text field" "Test")
(fill-form-field "Text area" "Test2")
(set-date "Date field" "2050-01-02")
(fill-form-field "Email field" "user@example.com")
;; leave attachment field empty
(is (not (field-visible? "Conditional field"))
"Conditional field is not visible before selecting option")
(select-option "Option list" "First option")
(wait-predicate #(field-visible? "Conditional field"))
(fill-form-field "Conditional field" "Conditional")
;; pick two options for the multi-select field:
(check-box "Option2")
(check-box "Option3")
;; leave "Text field with max length" empty
;; leave "Text are with max length" empty

(accept-licenses)
(send-application)
(is (= "Applied" (get-element-text *driver* :application-state)))

(testing "check a field answer"
(is (= "Test name" (get-element-text *driver* field-selector))))

(testing "see application on applications page"
(go-to-applications)
(let [summary (get-application-summary application-id)]
(is (= "Default workflow" (:resource summary)))
(is (= "Applied" (:state summary)))
;; don't bother trying to predict the external id:
(is (.contains (:description summary) "Test name"))))

(testing "fetch application from API"
(let [application (:body
(http/get (str +test-url+ "/api/applications/" application-id)
{:as :json
:headers {"x-rems-api-key" "42"
"x-rems-user-id" "handler"}}))]
(testing "applicant information"
(is (= "alice" (get-in application [:application/applicant :userid])))
(is (= (set (map :license/id (:application/licenses application)))
(set (get-in application [:application/accepted-licenses :alice])))))
(testing "form fields"
(is (= "Test name" (:application/description application)))
(is (= [["label" ""]
["description" "Test name"]
["text" "Test"]
["texta" "Test2"]
["header" ""]
["date" "2050-01-02"]
["email" "user@example.com"]
["attachment" ""]
["option" "Option1"]
["text" "Conditional"]
["multiselect" "Option2 Option3"]
["label" ""]
["text" ""]
["texta" ""]]
(for [field (select [:application/forms ALL :form/fields ALL] application)]
;; TODO could test other fields here too, e.g. title
[(:field/type field)
(:field/value field)]))))

(testing "after navigating to the application view again"
(scroll-and-click *driver* [{:css "table.my-applications"}
{:tag :tr :data-row application-id}
{:css ".btn-primary"}])
(wait-visible *driver* {:tag :h1, :fn/has-text "Application"})
(wait-page-loaded)
(testing "check a field answer"
(is (= "Test name" (get-element-text *driver* field-selector)))))))))))

(deftest test-guide-page
(with-postmortem *driver* {:dir reporting-dir}
Expand Down