Skip to content

Commit

Permalink
test: test event notification body against application raw api
Browse files Browse the repository at this point in the history
  • Loading branch information
opqdonut committed Apr 20, 2020
1 parent b7fca1a commit c5df8dd
Showing 1 changed file with 7 additions and 60 deletions.
67 changes: 7 additions & 60 deletions test/clj/rems/test_event_notification.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
[medley.core :refer [dissoc-in]]
[rems.config]
[rems.api.services.command :as command]
[rems.api.testing :refer [api-fixture api-call]]
[rems.db.test-data :as test-data]
[rems.db.testing :refer [test-db-fixture rollback-db-fixture]]
[rems.event-notification :as event-notification]
[rems.json :as json]
[rems.testing-util :refer [fixed-time-fixture with-user]]
[stub-http.core :as stub]))

(use-fixtures
:once
test-db-fixture
rollback-db-fixture)
api-fixture)

(deftest test-notify!
(with-open [server (stub/start! {"/ok" {:status 200}
Expand Down Expand Up @@ -58,10 +56,7 @@
:data (-> r
:body
(get "content")
json/parse-string
(dissoc-in [:event/application :application/events])
;; catalogue-item/start is set by the db and can't be easily fixed
(dissoc-in [:event/application :application/resources 0 :catalogue-item/start]))}))
json/parse-string)}))
form-id (test-data/create-form! {:form/title "notifications"
:form/fields [{:field/type :text
:field/id "field-1"
Expand All @@ -85,7 +80,9 @@
(is (empty? (stub/recorded-requests server))))
(event-notification/process-outbox!)
(testing "created event gets sent to both endpoints"
(let [notifications (get-notifications)]
(let [notifications (get-notifications)
app-from-raw-api (api-call :get (str "/api/applications/" app-id "/raw") nil
"42" "reporter")]
(is (= 2 (count notifications)))
(is (= #{"/created" "/all"}
(set (map :path notifications))))
Expand All @@ -100,57 +97,7 @@
:event/actor applicant
:event/type "application.event/created"
:application/licenses []
:event/application {:application/description ""
:application/invited-members []
:application/last-activity "2001-01-01T00:00:00.000Z"
:application/attachments []
:application/licenses []
:application/created "2001-01-01T00:00:00.000Z"
:application/state "application.state/draft"
:application/role-permissions
{:everyone-else ["application.command/accept-invitation"]
:member ["application.command/copy-as-new"
"application.command/accept-licenses"]
:reporter ["see-everything"]
:applicant ["application.command/copy-as-new"
"application.command/invite-member"
"application.command/submit"
"application.command/remove-member"
"application.command/accept-licenses"
"application.command/uninvite-member"
"application.command/save-draft"
"application.command/close"
"application.command/change-resources"]}
:application/modified "2001-01-01T00:00:00.000Z"
:application/user-roles {:alice ["applicant"] :handler ["handler"]}
:application/external-id "2001/1"
:application/workflow {:workflow/type "workflow/default"
:workflow/id workflow-id
:workflow.dynamic/handlers
[{:email nil :userid "handler" :name nil}]}
:application/blacklist []
:application/id app-id
:application/todo nil
:application/applicant {:email nil :userid "alice" :name nil}
:application/members []
:application/resources [{:catalogue-item/end nil
:catalogue-item/expired false
:catalogue-item/enabled true
:resource/id res-id
:catalogue-item/title {}
:catalogue-item/infourl {}
:resource/ext-id ext-id
:catalogue-item/archived false
:catalogue-item/id cat-id}]
:application/accepted-licenses {}
:application/forms [{:form/fields [{:field/value ""
:field/type "text"
:field/title {:en "text field"}
:field/id "field-1"
:field/optional false
:field/visible true}]
:form/title "notifications"
:form/id form-id}]}}
:event/application app-from-raw-api}
(:data (first notifications))))
(is (= (:data (first notifications))
(:data (second notifications))))))
Expand Down

0 comments on commit c5df8dd

Please sign in to comment.