Skip to content

Commit

Permalink
CMR-9489: Added validation to prevent drafts from being associated. (#…
Browse files Browse the repository at this point in the history
…1970)

Co-authored-by: siwei xu <[email protected]>
  • Loading branch information
sxu123 and siwei xu authored Sep 19, 2023
1 parent 7492330 commit 36376e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
(let [concept-ids (concat [(:concept-id concept)] (map :concept-id associations))
concept-types (map #(concepts/concept-id->type %) concept-ids)
supported-concept-types (set (concat [:collection :variable :service :tool]
(concepts/get-generic-concept-types-array)))
concepts/get-generic-non-draft-concept-types-array))
non-supported-types (remove nil?
(map #(when-not (contains? supported-concept-types %) %)
concept-types))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,25 @@
(index/wait-until-indexed)

(testing "Generic associations can not be made between collection and service,tool and variables."
(let [ response (association-util/generic-associate-by-concept-ids-revision-ids
(let [response (association-util/generic-associate-by-concept-ids-revision-ids
token coll-concept-id nil [{:concept-id "V1234-PROV1"} {:concept-id "S1234-PROV1"} {:concept-id "TL1234-PROV1"}])]
(is (= 422 (:status response)))
(is (some? (re-find #"The following concept ids \[\(\"V1234-PROV1\" \"S1234-PROV1\" \"TL1234-PROV1\"\)\] can not be associated with concept id \[C\d*-PROV1\] because collection/\[service\|tool\|variable\] associations are not supported by the new generic association api."
(first (:errors response))))
"error message did not match")))

(testing "Generic associations can not be made between collection and drafts, and between generic doc and drafts."
(let [response1 (association-util/generic-associate-by-concept-ids-revision-ids
token coll-concept-id nil [{:concept-id "CD1234-PROV1"} {:concept-id "SD1234-PROV1"} {:concept-id "TD1234-PROV1"} {:concept-id "GD1234-PROV1"}])
response2 (association-util/generic-associate-by-concept-ids-revision-ids
token grid-concept-id nil [{:concept-id "CD1234-PROV1"} {:concept-id "SD1234-PROV1"} {:concept-id "TD1234-PROV1"} {:concept-id "GD1234-PROV1"}])]
(is (= 422 (:status response1)))
(is (= ["The following concept types [(:collection-draft :service-draft :tool-draft :grid-draft)] are not supported for generic associations."]
(:errors response1)))
(is (= 422 (:status response2)))
(is (= ["The following concept types [(:collection-draft :service-draft :tool-draft :grid-draft)] are not supported for generic associations."]
(:errors response2)))))

(testing "Associate grid with collection by concept-id and revision-ids"
(let [response1 (association-util/generic-associate-by-concept-ids-revision-ids
token grid-concept-id grid-revision-id [{:concept-id coll-concept-id :revision-id coll-revision-id}])
Expand Down

0 comments on commit 36376e1

Please sign in to comment.