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/.
|
|
|
|
;;
|
|
|
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
|
|
;; defined by the Mozilla Public License, v. 2.0.
|
|
|
|
;;
|
2020-09-07 03:56:42 -05:00
|
|
|
;; Copyright (c) 2020 UXBOX Labs SL
|
2020-05-27 03:03:00 -05:00
|
|
|
|
2020-08-18 12:26:37 -05:00
|
|
|
(ns app.tests.test-services-viewer
|
2020-04-07 07:20:29 -05:00
|
|
|
(:require
|
|
|
|
[clojure.test :as t]
|
|
|
|
[datoteka.core :as fs]
|
2020-08-18 12:26:37 -05:00
|
|
|
[app.common.uuid :as uuid]
|
|
|
|
[app.db :as db]
|
2021-01-30 05:31:51 -05:00
|
|
|
[app.tests.helpers :as th]))
|
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-01-31 11:02:10 -05:00
|
|
|
(let [prof (th/create-profile* 1 {:is-active true})
|
|
|
|
prof2 (th/create-profile* 2 {:is-active true})
|
2020-05-27 02:33:09 -05:00
|
|
|
team-id (:default-team-id prof)
|
|
|
|
proj-id (:default-project-id prof)
|
2020-04-07 07:20:29 -05:00
|
|
|
|
2021-01-31 11:02:10 -05:00
|
|
|
file (th/create-file* 1 {:profile-id (:id prof)
|
|
|
|
:project-id proj-id
|
|
|
|
:is-shared false})
|
2020-09-07 03:56:42 -05:00
|
|
|
token (atom nil)]
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
(t/testing "authenticated with page-id"
|
2020-12-24 08:32:19 -05:00
|
|
|
(let [data {::th/type :viewer-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)
|
|
|
|
:page-id (get-in file [:data :pages 0])}
|
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)]
|
2020-12-07 02:55:54 -05:00
|
|
|
(t/is (contains? result :token))
|
2020-04-07 07:20:29 -05:00
|
|
|
(t/is (contains? result :page))
|
|
|
|
(t/is (contains? result :file))
|
|
|
|
(t/is (contains? result :project)))))
|
|
|
|
|
|
|
|
(t/testing "generate share token"
|
2020-12-24 08:32:19 -05:00
|
|
|
(let [data {::th/type :create-file-share-token
|
2020-09-07 03:56:42 -05:00
|
|
|
:profile-id (:id prof)
|
|
|
|
:file-id (:id file)
|
|
|
|
:page-id (get-in file [:data :pages 0])}
|
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)]
|
2020-09-07 03:56:42 -05:00
|
|
|
(t/is (string? (:token result)))
|
|
|
|
(reset! token (:token result)))))
|
2020-04-07 07:20:29 -05:00
|
|
|
|
2020-09-07 03:56:42 -05:00
|
|
|
(t/testing "not authenticated with page-id"
|
2020-12-24 08:32:19 -05:00
|
|
|
(let [data {::th/type :viewer-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)
|
|
|
|
:page-id (get-in file [:data :pages 0])}
|
2020-12-24 08:32:19 -05:00
|
|
|
out (th/query! data)]
|
2020-04-07 07:20:29 -05:00
|
|
|
|
|
|
|
;; (th/print-result! out)
|
|
|
|
(let [error (:error out)
|
|
|
|
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
|
|
|
|
2020-12-24 08:32:19 -05:00
|
|
|
;; (t/testing "authenticated with token & profile"
|
|
|
|
;; (let [data {::sq/type :viewer-bundle
|
|
|
|
;; :profile-id (:id prof2)
|
|
|
|
;; :token @token
|
|
|
|
;; :file-id (:id file)
|
|
|
|
;; :page-id (get-in file [:data :pages 0])}
|
|
|
|
;; out (th/try-on! (sq/handle data))]
|
|
|
|
|
|
|
|
;; ;; (th/print-result! out)
|
|
|
|
|
|
|
|
;; (let [result (:result out)]
|
|
|
|
;; (t/is (contains? result :page))
|
|
|
|
;; (t/is (contains? result :file))
|
|
|
|
;; (t/is (contains? result :project)))))
|
|
|
|
|
|
|
|
;; (t/testing "authenticated with token"
|
|
|
|
;; (let [data {::sq/type :viewer-bundle
|
|
|
|
;; :token @token
|
|
|
|
;; :file-id (:id file)
|
|
|
|
;; :page-id (get-in file [:data :pages 0])}
|
|
|
|
;; out (th/try-on! (sq/handle data))]
|
|
|
|
|
|
|
|
;; ;; (th/print-result! out)
|
|
|
|
|
|
|
|
;; (let [result (:result out)]
|
|
|
|
;; (t/is (contains? result :page))
|
|
|
|
;; (t/is (contains? result :file))
|
|
|
|
;; (t/is (contains? result :project)))))
|
2020-04-07 07:20:29 -05:00
|
|
|
))
|