2026-07-10 17:41:44 +00:00
|
|
|
require_relative "test_helper"
|
|
|
|
|
|
|
|
|
|
class CardsTest < Minitest::Test
|
|
|
|
|
include BacklogTestHelpers
|
|
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
@client = FakePlankaClient.new
|
|
|
|
|
@ensurer = Backlog::BoardEnsurer.new(client: @client, human_user_id: "human-1")
|
|
|
|
|
@ensurer.ensure("llf-schema", project_name: "Dev")
|
|
|
|
|
@cards = Backlog::Cards.new(client: @client)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_add_creates_card_at_backlog_list
|
|
|
|
|
card = @cards.add(board_name: "llf-schema", title: "Fix the flaky import")
|
|
|
|
|
|
|
|
|
|
backlog = @client.lists_store.find { |l| l.name == "Backlog" }
|
2026-07-10 20:51:23 +00:00
|
|
|
assert_equal backlog.id, card.list_id
|
|
|
|
|
assert_equal "Fix the flaky import", card.name
|
|
|
|
|
assert_equal "project", card.type
|
2026-07-10 17:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_add_positions_new_card_after_existing_backlog_cards
|
|
|
|
|
first = @cards.add(board_name: "llf-schema", title: "one")
|
|
|
|
|
second = @cards.add(board_name: "llf-schema", title: "two")
|
|
|
|
|
|
2026-07-10 20:51:23 +00:00
|
|
|
assert_operator second.position, :>, first.position
|
2026-07-10 17:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_add_with_description
|
|
|
|
|
card = @cards.add(board_name: "llf-schema", title: "t", description: "details here")
|
|
|
|
|
|
2026-07-10 20:51:23 +00:00
|
|
|
assert_equal "details here", card.description
|
2026-07-10 17:41:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_add_raises_for_missing_board
|
|
|
|
|
error = assert_raises(RuntimeError) { @cards.add(board_name: "nope", title: "t") }
|
|
|
|
|
assert_match(/no board named/, error.message)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_snapshot_shape_and_list_order
|
|
|
|
|
@cards.add(board_name: "llf-schema", title: "captured task")
|
|
|
|
|
|
|
|
|
|
snapshot = @cards.snapshot(board_name: "llf-schema")
|
|
|
|
|
|
|
|
|
|
assert_equal "llf-schema", snapshot["board"]
|
|
|
|
|
assert_equal Backlog::BoardSpec::LISTS, snapshot["lists"].map { |l| l["name"] }
|
|
|
|
|
backlog = snapshot["lists"].find { |l| l["name"] == "Backlog" }
|
|
|
|
|
assert_equal ["captured task"], backlog["cards"].map { |c| c["name"] }
|
|
|
|
|
assert_equal Backlog::BoardSpec::LABEL_NAMES.sort, snapshot["labels"].sort
|
|
|
|
|
end
|
|
|
|
|
|
2026-07-10 21:13:57 +00:00
|
|
|
def test_snapshot_card_emits_complete_key_set
|
|
|
|
|
@cards.add(board_name: "llf-schema", title: "captured task")
|
|
|
|
|
|
|
|
|
|
snapshot = @cards.snapshot(board_name: "llf-schema")
|
|
|
|
|
backlog = snapshot["lists"].find { |l| l["name"] == "Backlog" }
|
|
|
|
|
card = backlog["cards"].first
|
|
|
|
|
|
|
|
|
|
expected_keys = %w[
|
|
|
|
|
id createdAt updatedAt type position name description dueDate
|
|
|
|
|
isDueCompleted stopwatch commentsTotal isClosed listChangedAt
|
|
|
|
|
boardId listId creatorUserId prevListId coverAttachmentId
|
|
|
|
|
isSubscribed labels
|
|
|
|
|
]
|
|
|
|
|
assert_equal expected_keys.sort, card.keys.sort
|
|
|
|
|
assert card.key?("listChangedAt"), "snapshot card must carry listChangedAt for board-audit"
|
|
|
|
|
end
|
|
|
|
|
|
2026-07-10 17:41:44 +00:00
|
|
|
def test_snapshot_includes_card_label_names
|
|
|
|
|
card = @cards.add(board_name: "llf-schema", title: "labeled task")
|
|
|
|
|
p1 = @client.labels_store.find { |l| l.name == "P1" }
|
2026-07-10 20:51:23 +00:00
|
|
|
@client.attach_label(card.id, p1.id)
|
2026-07-10 17:41:44 +00:00
|
|
|
|
|
|
|
|
snapshot = @cards.snapshot(board_name: "llf-schema")
|
|
|
|
|
|
|
|
|
|
backlog = snapshot["lists"].find { |l| l["name"] == "Backlog" }
|
|
|
|
|
assert_equal ["P1"], backlog["cards"].first["labels"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_snapshot_raises_for_missing_board
|
|
|
|
|
assert_raises(RuntimeError) { @cards.snapshot(board_name: "nope") }
|
|
|
|
|
end
|
2026-07-10 17:44:13 +00:00
|
|
|
|
|
|
|
|
def test_attach_label_by_name
|
|
|
|
|
card = @cards.add(board_name: "llf-schema", title: "raw card")
|
|
|
|
|
|
2026-07-10 20:51:23 +00:00
|
|
|
@cards.attach_label(board_name: "llf-schema", card_id: card.id, label: "afk-ready")
|
2026-07-10 17:44:13 +00:00
|
|
|
|
|
|
|
|
snapshot = @cards.snapshot(board_name: "llf-schema")
|
|
|
|
|
backlog = snapshot["lists"].find { |l| l["name"] == "Backlog" }
|
|
|
|
|
assert_equal ["afk-ready"], backlog["cards"].first["labels"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_attach_label_raises_for_unknown_label
|
|
|
|
|
card = @cards.add(board_name: "llf-schema", title: "raw card")
|
|
|
|
|
|
|
|
|
|
error = assert_raises(RuntimeError) do
|
2026-07-10 20:51:23 +00:00
|
|
|
@cards.attach_label(board_name: "llf-schema", card_id: card.id, label: "nonexistent")
|
2026-07-10 17:44:13 +00:00
|
|
|
end
|
|
|
|
|
assert_match(/no label/, error.message)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_comment_adds_text_to_card
|
|
|
|
|
card = @cards.add(board_name: "llf-schema", title: "stale card")
|
|
|
|
|
|
2026-07-10 20:51:23 +00:00
|
|
|
comment = @cards.comment(card_id: card.id, text: "audit: in Doing 9 days")
|
2026-07-10 17:44:13 +00:00
|
|
|
|
2026-07-10 20:51:23 +00:00
|
|
|
assert_equal card.id, comment.card_id
|
|
|
|
|
assert_equal "audit: in Doing 9 days", comment.text
|
2026-07-10 17:44:13 +00:00
|
|
|
assert_equal 1, @client.comments.store.size
|
|
|
|
|
end
|
2026-07-10 17:41:44 +00:00
|
|
|
end
|