2020-05-27 03:03:00 -05:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2022-09-20 16:23:22 -05:00
|
|
|
;; Copyright (c) KALEIDOS INC
|
2020-05-27 03:03:00 -05:00
|
|
|
|
2022-11-08 04:40:19 -05:00
|
|
|
(ns backend-tests.rpc-viewer-test
|
2020-04-07 07:20:29 -05:00
|
|
|
(:require
|
2022-11-08 04:40:19 -05:00
|
|
|
[backend-tests.helpers :as th]
|
2020-08-18 12:26:37 -05:00
|
|
|
[app.common.uuid :as uuid]
|
|
|
|
[app.db :as db]
|
2021-05-28 06:50:42 -05:00
|
|
|
[clojure.test :as t]
|
|
|
|
[datoteka.core :as fs]))
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
(t/use-fixtures :once th/state-init)
|
|
|
|
(t/use-fixtures :each th/database-reset)
|
|
|
|
|
|
|
|
(t/deftest retrieve-bundle
|
2021-08-16 08:46:02 -05:00
|
|
|
(let [prof (th/create-profile* 1 {:is-active true})
|
|
|
|
prof2 (th/create-profile* 2 {:is-active true})
|
|
|
|
team-id (:default-team-id prof)
|
|
|
|
proj-id (:default-project-id prof)
|
2020-04-07 07:20:29 -05:00
|
|
|
|
2021-08-16 08:46:02 -05:00
|
|
|
file (th/create-file* 1 {:profile-id (:id prof)
|
|
|
|
:project-id proj-id
|
|
|
|
:is-shared false})
|
|
|
|
share-id (atom nil)]
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
(t/testing "authenticated with page-id"
|
2021-08-16 08:46:02 -05:00
|
|
|
(let [data {::th/type :view-only-bundle
|
2020-04-07 07:20:29 -05:00
|
|
|
:profile-id (:id prof)
|
2020-09-07 03:56:42 -05:00
|
|
|
:file-id (:id file)
|
2022-07-12 06:52:48 -05:00
|
|
|
:page-id (get-in file [:data :pages 0])
|
|
|
|
:components-v2 true}
|
2020-04-07 07:20:29 -05:00
|
|
|
|
2020-12-24 08:32:19 -05:00
|
|
|
out (th/query! data)]
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
|
|
|
|
(let [result (:result out)]
|
2021-08-16 08:46:02 -05:00
|
|
|
(t/is (contains? result :share-links))
|
|
|
|
(t/is (contains? result :permissions))
|
|
|
|
(t/is (contains? result :libraries))
|
2020-04-07 07:20:29 -05:00
|
|
|
(t/is (contains? result :file))
|
|
|
|
(t/is (contains? result :project)))))
|
|
|
|
|
|
|
|
(t/testing "generate share token"
|
2021-08-16 08:46:02 -05:00
|
|
|
(let [data {::th/type :create-share-link
|
2020-09-07 03:56:42 -05:00
|
|
|
:profile-id (:id prof)
|
|
|
|
:file-id (:id file)
|
2021-08-16 08:46:02 -05:00
|
|
|
:pages #{(get-in file [:data :pages 0])}
|
2022-06-22 11:16:34 -05:00
|
|
|
:who-comment "team"
|
|
|
|
:who-inspect "all"}
|
2020-12-24 08:32:19 -05:00
|
|
|
out (th/mutation! data)]
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
(let [result (:result out)]
|
2021-08-16 08:46:02 -05:00
|
|
|
(t/is (uuid? (:id result)))
|
|
|
|
(reset! share-id (:id result)))))
|
2020-04-07 07:20:29 -05:00
|
|
|
|
2020-09-07 03:56:42 -05:00
|
|
|
(t/testing "not authenticated with page-id"
|
2021-08-16 08:46:02 -05:00
|
|
|
(let [data {::th/type :view-only-bundle
|
2020-04-07 07:20:29 -05:00
|
|
|
:profile-id (:id prof2)
|
2020-09-07 03:56:42 -05:00
|
|
|
:file-id (:id file)
|
2022-07-12 06:52:48 -05:00
|
|
|
:page-id (get-in file [:data :pages 0])
|
|
|
|
:components-v2 true}
|
2020-12-24 08:32:19 -05:00
|
|
|
out (th/query! data)]
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
2021-08-16 08:46:02 -05:00
|
|
|
(let [error (:error out)
|
2020-04-07 07:20:29 -05:00
|
|
|
error-data (ex-data error)]
|
|
|
|
(t/is (th/ex-info? error))
|
2021-01-31 11:02:10 -05:00
|
|
|
(t/is (= (:type error-data) :not-found))
|
|
|
|
(t/is (= (:code error-data) :object-not-found)))))
|
2020-04-07 07:20:29 -05:00
|
|
|
|
2021-08-16 08:46:02 -05:00
|
|
|
(t/testing "authenticated with token & profile"
|
|
|
|
(let [data {::th/type :view-only-bundle
|
|
|
|
:profile-id (:id prof2)
|
|
|
|
:share-id @share-id
|
|
|
|
:file-id (:id file)
|
2022-07-12 06:52:48 -05:00
|
|
|
:page-id (get-in file [:data :pages 0])
|
|
|
|
:components-v2 true}
|
2021-08-16 08:46:02 -05:00
|
|
|
out (th/query! data)]
|
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(t/is (nil? (:error out)))
|
|
|
|
|
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (contains? result :file))
|
|
|
|
(t/is (contains? result :project)))))
|
|
|
|
|
|
|
|
(t/testing "authenticated with token"
|
|
|
|
(let [data {::th/type :view-only-bundle
|
|
|
|
:share-id @share-id
|
|
|
|
:file-id (:id file)
|
2022-07-12 06:52:48 -05:00
|
|
|
:page-id (get-in file [:data :pages 0])
|
|
|
|
:components-v2 true}
|
2021-08-16 08:46:02 -05:00
|
|
|
out (th/query! data)]
|
|
|
|
|
|
|
|
;; (th/print-result! out)
|
2022-12-21 05:53:56 -05:00
|
|
|
(t/is (nil? (:error out)))
|
2021-08-16 08:46:02 -05:00
|
|
|
(let [result (:result out)]
|
|
|
|
(t/is (contains? result :file))
|
|
|
|
(t/is (contains? result :project)))))
|
|
|
|
|
2020-04-07 07:20:29 -05:00
|
|
|
))
|