penpot/backend/test/backend_tests/rpc_file_task_test.clj
Juan de la Cruz ea61730f61
✨ Add review mode, review comments and tasks to design reviews (#12939)
* ✨ Add review mode, review comments and tasks to design reviews

A design review now opens a read-only review mode. The left panel shows
the pages and layers with the View only badge, the toolbar offers the
review tools (move, comment, comment an area, create a task, show the
changes) and the right panel holds the inspect of the selection, the
comments of the review and its tasks. A bar at the bottom names the
review, shows the progress of its tasks and opens its details.

Comments can point at a spot, a layer or an area, and a comment written
in a review says so with its own mark, wherever the file is open. The
layers panel counts the open comments of each layer.

Tasks are new: work on a file, assigned to someone and tied to a layer
or to a spot of the canvas. A comment can become a task and stays
attached to it. A task moves through open, done, verified, reopened and
won't do; anybody may move it, and each move is an event that records
who made it. Deleting a layer with open tasks moves them to its board
and offers to undo the deletion or to mark them done; a task can then
be linked to another layer or get its layer back. Assignees are told by
email. Merging a branch moves its tasks and their threads into main:
the open ones keep going, the closed ones stay as its history, and the
merge dialog lists them and can tell their assignees.

The details of a review show its overview, its tasks and its activity:
what the saves of the branch did to each layer since the review opened,
by person and day, with the values before and after. The changes can be
shown on the canvas one after another.

The backend adds the review fields of a comment thread, the task and
task event tables, the activity of a review (recorded by each save of a
branch under review) and the commands of the tasks.

* ♻️ Bring the design review styles and components up to the DS

Move what the review UI repeated into the design system: layer-chip*,
progress-bar*, comment-card*, link-button* and textarea*, each with its
story and docs. The screens keep the look they had: the same review states
compare equal, pixel by pixel, before and after.

The stylesheets follow the rules of the UI guide: local variables for the
colors that change by state, the right tokens, no unused imports and fewer
element and nested selectors. What has no DS token or typography says so in
a TODO. The aliases left in comments.scss resolve to their tokens.

The components get complete schemas and a single owner for the copyright.
Translations take literal keys and templates instead of dynamic keys and
glued strings, and comments.cljs no longer depends on the review tasks: the
workspace passes it what a thread shows about its task.

Fix three bugs of the review:

- The inspect took the width of a narrower panel and its height from the
  window, so it looked squeezed and cut its last rows. It now fills the
  panel that holds it.
- Enter on the menu of a task opened the task. The row now reacts only to
  keys on itself, and the menu keeps Enter from the workspace shortcuts.
- The resolved and lost marks ignored the pointer: hover now wins over the
  state of a mark.

* ✨ Turn each review message into a task and restore the filter dropdown

Each message of a thread can now become a task, so one thread can hold
several. The new file_task.comment_id column records the message, the
migration fills it with the first message of the thread for existing tasks,
and the backend rejects a message from another thread or one that already
has a task.

Comments and tasks of a review behave like normal ones. The canvas marks
show a short preview on hover and there is one mark per task. A blue label
marks what belongs to a review, in the thread and in the sidebar, and a
selected card takes a blue border there and the primary color elsewhere.
The new review-label* component holds the label.

The sidebar and the review panel go back to a filter dropdown in place of
the chips. Comments offer the views all, yours and mentions, with an option
to hide the resolved ones. Tasks offer all, yours, open and to verify, with
an option to hide the closed ones. Resolved comments now show by default.

"New task" outside a review now arms the task tool: it shows the task cursor
and the next click opens the task form, not a comment. Then the comment tool
returns, and Esc leaves the tool.

The details modal shows changed properties in the format of the compare
dialogs, and showing a task on the canvas syncs the WASM viewport. The sidebar
cards put the layer chip on the line of the replies, and task states lose the
dot and take a color each.

Fix these bugs:

- The hover card of the activity tab crashed on a change with no token.
- The assignee and reviewer dropdowns came out cut. The select now portals
  into the closest dialog, because the modal makes the rest of the page inert.
- The review label cut the header of the thread. It now sits below it.

* ✨ Group overlapping review marks and let tasks change assignee

Comments and tasks of a review that fall on the same spot now show as one
mark with a counter in a white bubble. A click fans them out, as the comment
bubbles do, and the user picks one. They group on the same layer and, by
proximity, at a low zoom. The card of the mark lists up to five items.

Hovering a mark outlines its layer, or its board when the layer is gone. The
WASM viewport draws no outlines under the comments tool, so it now draws the
highlighted ones there. Opening a comment from a mark closes the open task.

A task can change assignee from the selector in its state and from "Assign
to" in its menu, which holds the team in the same popover. The change shows
right away and goes to the history of the task. A closed task keeps its
assignee.

Deleting a task or a comment now asks first, with the usual confirmation. A
task deleted from the details of a review brings the dialog back on its tab.

The state of a task takes two rows, in its panel and in a thread: state and
layer, then assignee and the review it comes from, which a review omits. The
text of tasks and comments sits in a box. The history no longer says that the
task was created.

* ✨ Keep the branch bar and the palettes at one level on a branch

The open branch bar covered the horizontal scroll of the canvas. It now sits
as far from the bottom as the review bar. Folded, it stays flush.

On a branch the palettes no longer lift over the branch bar: both sit at the
same level and work as a toggle. Opening one folds the other, also through
the palette shortcuts, and both can stay folded. The new `:bottom-bar` state
says which one is open. It exists only while the branch bar does, so a file
that is not a branch keeps the palettes on their layout flags and at their
usual place, and what happens on a branch does not reach them.

The branch bar comes open on a branch and centers on the canvas, not on the
window, so that it clears the folded palettes at usual widths. The room it
published for the palettes goes away with the lifting.

* ✨ Give every task a thread and tidy the design review screens

Every task now lives in a message of a comment thread, so anyone can go on
commenting on it. A task made from scratch gets a thread whose first message
is its title, on its layer and in its review, created in the same
transaction. A comment turned into a task keeps its thread, as before. The
panel of a task with no thread is gone: a task always opens as its thread.
Migration 0814 gives a thread to the tasks that had none. Deleting a thread
deletes its tasks, after a confirmation that says so.

The anchor of a task was a plain map, not a point, so a thread on a layer
refused replies. It is now a point.

The details of a review filter the tasks by state with the chips of the
activity, in the colour of each state, and show how many are closed on the
right. The "New task" button leaves the dialog.

Descriptions look the same everywhere: the box of the branch info dialog,
an "Edit" button and a dashed box when empty. Read, they grow up to 400px
and scroll inside; edited, the textarea starts at 400px. The text of a
review in the sidebar does the same once unfolded.

In the review bar, the author gets a "Publish latest changes" button when
the branch moved past the review, with a hint that approvals must be
renewed. The others keep a badge, now "Unpublished changes", with a hint.
The bar refreshes once the publish lands.

Smaller changes: the resolve checkbox lines up with the task button and has
a tooltip, messages sit in a filled box, task events take an outline, and
the change navigator sits right above the review bar.

* 💄 Sort the test runner requires that cljfmt rejects

The Frontend Tests lint step fails on runner.cljs: the requires for
workspace-tasks-test, review-details-test and review-markers-test sat
out of alphabetical order. This is the output of cljfmt fix.

AI-assisted-by: claude-opus-5-5
Signed-off-by: Álvaro Tejero Cantero <alvorithm@teje.ro>

* 🐛 Test the design review mode in the pull request spec

The review bar replaced the branch banner, so four tests still drove
the branch bar: a visible Compare button, the rectangle tool and the
Review button. They now drive the design review instead.

* Opening a file with a pr-id enters the review: the bar names the
  review, the header trades the file name for the review title, and
  comparing, merging and cancelling sit in the bar's options menu.
* The compare dialog opens from that menu.
* The review is read-only rather than an editable file: the review
  toolbar offers its five tools, the drawing tools are gone, the
  sidebar says View only, and the right panel is the review's own
  Inspect, Comments and Tasks tabs.
* The verdict comes from the bar's Submit review button and the
  dialog it opens, scoped by role so the bar action and the dialog
  action do not collide.

The tests also reach the review bar by its region label instead of
walking up three parents from the Reviewing the design review text,
which broke as soon as the bar's markup changed.

AI-assisted-by: claude-opus-5-5
Signed-off-by: Álvaro Tejero Cantero <alvorithm@teje.ro>

* 🐛 Count only the test thread's acquisitions in the climit test

acquires-the-command-own-limits-before-the-root-limits failed on CI
with an extra "root/global" ahead of the expected order. The test
records metrics through with-redefs, which is global, so a call of
another thread of the test JVM, such as an RPC an earlier test left
running, can take a root limiter inside the window and land in the
same atom.

Record the thread with each metrics call and keep, in
acquired-in-order, only the acquisitions of the calling thread. Both
tests that read it acquire their limiters on the test thread. The
same class of flake was fixed on develop for the waiting-count test
(12d73d0f63); this one is still open there.

AI-assisted-by: claude-opus-5-5
Signed-off-by: Álvaro Tejero Cantero <alvorithm@teje.ro>

* 📚 Describe the task moves the server allows in the table comment

The comment on file_task said a task is reopened only from done and
that editors move tasks. files_task.clj::transitions also reopens a
verified or won't-do task, and set-task-status lets anybody who can
read the file move one. Say the same in the schema.

AI-assisted-by: claude-opus-5-5
Signed-off-by: Álvaro Tejero Cantero <alvorithm@teje.ro>

---------

Signed-off-by: Álvaro Tejero Cantero <alvorithm@teje.ro>
Co-authored-by: Álvaro Tejero Cantero <alvorithm@teje.ro>
2026-11-17 22:30:22 +01:00

427 lines
22 KiB
Clojure

;; 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/.
;;
;; Copyright (c) KALEIDOS INC Sucursal en España SL
(ns backend-tests.rpc-file-task-test
(:require
[app.common.features :as cfeat]
[app.common.geom.point :as gpt]
[app.common.types.shape :as cts]
[app.common.uuid :as uuid]
[app.config :as cf]
[app.db :as db]
[app.email :as eml]
[app.rpc :as-alias rpc]
[backend-tests.helpers :as th]
[clojure.test :as t]))
(t/use-fixtures :once th/state-init)
(t/use-fixtures :each th/database-reset)
(defn- task-flags
"The test flags plus `:branching`. Read at run time, inside the
`th/state-init` fixture, so the flags it turns off (the admin
console among them) stay off: a value captured when the namespace
loads would carry the production defaults instead."
[]
(conj cf/flags :branching))
(defn- page-id-of
[profile file-id]
(-> (th/command! {::th/type :get-file
::rpc/profile-id (:id profile)
:id file-id})
:result :data :pages first))
(defn- update-file*
[profile file-id changes]
(let [f (th/db-get :file {:id file-id})]
(th/command! {::th/type :update-file
::rpc/profile-id (:id profile)
:id file-id
:session-id (uuid/random)
:revn (:revn f)
:vern (:vern f)
:features cfeat/supported-features
:changes changes})))
(defn- add-rect*
[profile file-id page-id rect-id name]
(update-file* profile file-id
[{:type :add-obj
:page-id page-id
:id rect-id
:parent-id uuid/zero
:frame-id uuid/zero
:obj (cts/setup-shape
{:id rect-id :name name :type :rect
:parent-id uuid/zero :frame-id uuid/zero})}]))
(defn- setup-review
"A file with a rect on main, a branch of it and an open design review of
the branch. Returns the ids the tests need."
[]
(let [author (th/create-profile* 1 {:is-active true})
reviewer (th/create-profile* 2 {:is-active true})
file (th/create-file* 1 {:profile-id (:id author)
:project-id (:default-project-id author)})
page-id (page-id-of author (:id file))
rect-id (uuid/random)]
(th/create-team-role* {:team-id (:default-team-id author)
:profile-id (:id reviewer)
:role :editor})
(add-rect* author (:id file) page-id rect-id "Pay button")
(let [branch (:result (th/command! {::th/type :create-file-branch
::rpc/profile-id (:id author)
:file-id (:id file)
:name "feature-login"}))
review (:result (th/command! {::th/type :create-pull-request
::rpc/profile-id (:id author)
:branch-id (:id branch)
:title "Checkout redesign"
:reviewers [(:id reviewer)]}))]
{:author author
:reviewer reviewer
:file file
:page-id page-id
:rect-id rect-id
:branch branch
:branch-file-id (:branch-file-id branch)
:review review})))
(defn- create-task*
[profile params]
(th/command! (merge {::th/type :create-task
::rpc/profile-id (:id profile)
:frame-id uuid/zero
:position (gpt/point 0)
:title "Use the secondary token on the pay button"}
params)))
(defn- set-status*
[profile task-id status]
(th/command! {::th/type :set-task-status
::rpc/profile-id (:id profile)
:id task-id
:status status}))
(t/deftest task-lifecycle-records-who-made-each-move
(with-redefs [cf/flags (task-flags)
eml/send-template (fn [_ _] nil)]
(let [{:keys [author reviewer page-id rect-id branch-file-id review]} (setup-review)
out (create-task* reviewer {:file-id branch-file-id
:page-id page-id
:shape-id rect-id
:assignee-id (:id author)
:pull-request-id (:id review)})
task (:result out)]
(t/is (nil? (:error out)))
(t/is (= "open" (:status task)))
(t/is (= "Checkout redesign" (:review-title task)))
(t/testing "the assignee marks it done and the reviewer verifies it"
(t/is (nil? (:error (set-status* author (:id task) "done"))))
(t/is (nil? (:error (set-status* reviewer (:id task) "verified")))))
(t/testing "every move is an event with who made it"
(let [events (:result (th/command! {::th/type :get-task-events
::rpc/profile-id (:id author)
:id (:id task)}))]
(t/is (= ["created" "assigned" "status" "status"] (mapv :type events)))
(t/is (= [(:id reviewer) (:id reviewer) (:id author) (:id reviewer)]
(mapv :profile-id events)))
(t/is (= {:from "done" :to "verified"} (:payload (last events))))))
(t/testing "the review counts its tasks"
(let [row (:result (th/command! {::th/type :get-pull-request
::rpc/profile-id (:id author)
:id (:id review)}))]
(t/is (= {"verified" 1} (-> row :counts :tasks))))))))
(t/deftest task-refuses-a-move-its-state-does-not-allow
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id branch-file-id]} (setup-review)
task (:result (create-task* author {:file-id branch-file-id :page-id page-id}))
out (set-status* author (:id task) "verified")]
(t/is (= :invalid-task-transition (-> out :error ex-data :code))))))
(t/deftest task-assignee-must-be-a-team-member
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id branch-file-id]} (setup-review)
stranger (th/create-profile* 3 {:is-active true})
out (create-task* author {:file-id branch-file-id
:page-id page-id
:assignee-id (:id stranger)})]
(t/is (= :assignee-not-team-member (-> out :error ex-data :code))))))
(t/deftest deleted-layer-moves-its-task-to-the-board
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id rect-id branch-file-id]} (setup-review)
board-id (uuid/random)
task (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:shape-id rect-id}))
out (th/command! {::th/type :mark-tasks-layer-deleted
::rpc/profile-id (:id author)
:file-id branch-file-id
:layers [{:shape-id rect-id
:shape-name "Pay button"
:frame-id board-id
:frame-name "Checkout / Mobile"
:objects [{:id rect-id :name "Pay button" :type :rect}]}]})]
(t/is (nil? (:error out)))
(t/is (= 1 (count (:result out))))
(let [row (th/db-get :file-task {:id (:id task)})]
(t/is (= "Pay button" (:lost-shape-name row)))
(t/is (= board-id (:frame-id row))))
(t/testing "restoring the layer clears the loss"
(th/command! {::th/type :mark-task-layer-restored
::rpc/profile-id (:id author)
:id (:id task)
:frame-id uuid/zero})
(t/is (nil? (:lost-shape-name (th/db-get :file-task {:id (:id task)}))))))))
(t/deftest review-thread-points-at-a-layer
(with-redefs [cf/flags (task-flags)]
(let [{:keys [reviewer page-id rect-id branch-file-id review]} (setup-review)
out (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id reviewer)
:file-id branch-file-id
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 10 20)
:content "The pay button loses contrast"
:pull-request-id (:id review)
:anchor {:type :layer :shape-id rect-id}})]
(t/is (nil? (:error out)))
(let [[thread] (:result (th/command! {::th/type :get-comment-threads
::rpc/profile-id (:id reviewer)
:file-id branch-file-id}))]
(t/is (= (:id review) (:pull-request-id thread)))
(t/is (= "Checkout redesign" (:pull-request-title thread)))
(t/is (= :layer (:anchor-type thread)))
(t/is (= rect-id (:shape-id thread)))))))
(t/deftest review-thread-refuses-a-review-of-another-file
(with-redefs [cf/flags (task-flags)]
(let [{:keys [reviewer page-id file review]} (setup-review)
out (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id reviewer)
:file-id (:id file)
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "on main"
:pull-request-id (:id review)})]
(t/is (= :pull-request-not-open (-> out :error ex-data :code))))))
(t/deftest branch-save-under-review-records-its-activity
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id rect-id branch-file-id review]} (setup-review)]
(update-file* author branch-file-id
[{:type :mod-obj :page-id page-id :id rect-id
:operations [{:type :set :attr :name :val "Pay"}]}])
(let [[row :as rows] (:result (th/command! {::th/type :get-pull-request-activity
::rpc/profile-id (:id author)
:id (:id review)}))]
(t/is (= 1 (count rows)))
(t/is (= (:id author) (:profile-id row)))
(t/is (= [{:id rect-id :kind :modified :attrs {:name ["Pay button" "Pay"]}}]
(mapv #(select-keys % [:id :kind :attrs]) (:entries row))))))))
(t/deftest merge-moves-the-tasks-and-their-threads-into-main
(with-redefs [cf/flags (task-flags)
eml/send-template (fn [_ _] nil)]
(let [{:keys [author page-id rect-id file branch branch-file-id review]} (setup-review)
;; main has a thread of its own already: the moved one must not
;; take its number
_ (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id author)
:file-id (:id file)
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "on main"})
thread (:result (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id author)
:file-id branch-file-id
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "fix the radius"
:pull-request-id (:id review)}))
open (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:shape-id rect-id
:thread-id (:id thread)
:pull-request-id (:id review)}))
closed (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:title "Drop the promo"}))]
(set-status* author (:id closed) "wont-do")
(update-file* author branch-file-id
[{:type :mod-obj :page-id page-id :id rect-id
:operations [{:type :set :attr :name :val "Pay"}]}])
(let [out (th/command! {::th/type :merge-file-branch
::rpc/profile-id (:id author)
:branch-id (:id branch)
:notify-assignees true})]
(t/is (nil? (:error out))))
(let [tasks (:result (th/command! {::th/type :get-file-tasks
::rpc/profile-id (:id author)
:file-id (:id file)}))
[merge-row] (th/db-query :file-branch-merge {:file-id (:id file)})]
(t/is (= #{(:id open) (:id closed)} (into #{} (map :id) tasks)))
(t/is (every? #(= (:id merge-row) (:merge-id %)) tasks))
(t/is (every? #(= "feature-login" (:branch-name %)) tasks))
(t/is (= "Checkout redesign"
(:review-title (th/db-get :file-task {:id (:id open)})))))
(t/testing "the threads move with their tasks and take the next numbers of main"
(let [moved (th/db-get :comment-thread {:id (:id thread)})
closed (th/db-get :comment-thread {:id (:thread-id closed)})]
(t/is (= (:id file) (:file-id moved)))
(t/is (= (:id file) (:file-id closed)))
(t/is (= [2 3] [(:seqn moved) (:seqn closed)]))
(t/is (= 3 (:comment-thread-seqn (th/db-get :file {:id (:id file)}
{::db/remove-deleted false})))))))))
(t/deftest each-message-of-a-thread-may-be-a-task
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id branch-file-id]} (setup-review)
thread (:result (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id author)
:file-id branch-file-id
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "fix the radius"}))
reply (:result (th/command! {::th/type :create-comment
::rpc/profile-id (:id author)
:thread-id (:id thread)
:content "and the shadow"}))
messages (:result (th/command! {::th/type :get-comments
::rpc/profile-id (:id author)
:thread-id (:id thread)}))
first-id (:id (first (sort-by :created-at messages)))
from (fn [comment-id]
(create-task* author {:file-id branch-file-id
:page-id page-id
:thread-id (:id thread)
:comment-id comment-id}))]
(t/testing "a thread holds a task per message"
(t/is (nil? (:error (from first-id))))
(t/is (nil? (:error (from (:id reply)))))
(let [tasks (:result (th/command! {::th/type :get-file-tasks
::rpc/profile-id (:id author)
:file-id branch-file-id}))]
(t/is (= #{first-id (:id reply)} (into #{} (map :comment-id) tasks)))))
(t/testing "a message holds one task"
(t/is (= :comment-already-has-task (-> (from first-id) :error ex-data :code))))
(t/testing "a message of another thread is refused"
(let [other (:result (th/command! {::th/type :create-comment-thread
::rpc/profile-id (:id author)
:file-id branch-file-id
:page-id page-id
:frame-id uuid/zero
:position (gpt/point 0)
:content "another one"}))
out (create-task* author {:file-id branch-file-id
:page-id page-id
:thread-id (:id other)
:comment-id (:id reply)})]
(t/is (= :comment-not-in-thread (-> out :error ex-data :code))))))))
(t/deftest task-on-the-canvas-keeps-its-position
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id branch-file-id]} (setup-review)
out (create-task* author {:file-id branch-file-id
:page-id page-id
:position (gpt/point 120 340)})
task (:result out)]
(t/is (nil? (:error out)))
(t/is (nil? (:shape-id task)))
(let [[row] (:result (th/command! {::th/type :get-file-tasks
::rpc/profile-id (:id author)
:file-id branch-file-id}))]
(t/is (= {:x 120.0 :y 340.0} (into {} (:position row)))))
(t/testing "a move of its state answers with the task"
(t/is (nil? (:error (set-status* author (:id task) "done"))))))))
(t/deftest task-created-on-the-canvas-gets-a-thread
(with-redefs [cf/flags (task-flags)
eml/send-template (fn [_ _] nil)]
(let [{:keys [author reviewer page-id rect-id branch-file-id review]} (setup-review)
out (create-task* reviewer {:file-id branch-file-id
:page-id page-id
:shape-id rect-id
:position (gpt/point 30 40)
:title " Use the secondary token "
:pull-request-id (:id review)})
task (:result out)]
(t/is (nil? (:error out)))
(t/is (some? (:thread-id task)))
(t/is (some? (:comment-id task)))
(t/testing "the thread points at the layer of the task, in its review"
(let [thread (th/db-get :comment-thread {:id (:thread-id task)})]
(t/is (= branch-file-id (:file-id thread)))
(t/is (= (:id reviewer) (:owner-id thread)))
(t/is (= (:id review) (:pull-request-id thread)))
(t/is (= "layer" (:anchor-type thread)))
(t/is (= rect-id (:shape-id thread)))))
(t/testing "its first message is the title and holds the task"
(let [[message] (:result (th/command! {::th/type :get-comments
::rpc/profile-id (:id author)
:thread-id (:thread-id task)}))]
(t/is (= (:comment-id task) (:id message)))
(t/is (= "Use the secondary token" (:content message)))))
(t/testing "anybody can go on commenting in it"
(let [out (th/command! {::th/type :create-comment
::rpc/profile-id (:id author)
:thread-id (:thread-id task)
:content "On it"})]
(t/is (nil? (:error out)))
(t/is (= 2 (count (th/db-query :comment {:thread-id (:thread-id task)})))))))))
(t/deftest task-on-the-empty-canvas-gets-a-thread-on-its-spot
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id branch-file-id]} (setup-review)
task (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:position (gpt/point 120 340)}))
thread (th/db-get :comment-thread {:id (:thread-id task)})]
(t/is (= "canvas" (:anchor-type thread)))
(t/is (nil? (:shape-id thread)))
(t/is (nil? (:pull-request-id thread)))
(t/is (= {:x 120.0 :y 340.0} (into {} (db/decode-pgpoint (:position thread))))))))
(t/deftest deleting-a-thread-deletes-its-tasks
(with-redefs [cf/flags (task-flags)]
(let [{:keys [author page-id branch-file-id]} (setup-review)
task (:result (create-task* author {:file-id branch-file-id :page-id page-id}))
other (:result (create-task* author {:file-id branch-file-id
:page-id page-id
:title "Another one"}))
out (th/command! {::th/type :delete-comment-thread
::rpc/profile-id (:id author)
:id (:thread-id task)})]
(t/is (nil? (:error out)))
(t/is (nil? (th/db-get :comment-thread {:id (:thread-id task)})))
(t/is (some? (:deleted-at (th/db-get :file-task {:id (:id task)}
{::db/remove-deleted false}))))
(t/is (= [(:id other)]
(mapv :id (:result (th/command! {::th/type :get-file-tasks
::rpc/profile-id (:id author)
:file-id branch-file-id}))))))))