cc-os/plugins/os-backlog/tests/cards_test.rb

96 lines
3.3 KiB
Ruby
Raw Normal View History

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" }
assert_equal backlog.id, card["listId"]
assert_equal "Fix the flaky import", card["name"]
assert_equal "project", card["type"]
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")
assert_operator second["position"], :>, first["position"]
end
def test_add_with_description
card = @cards.add(board_name: "llf-schema", title: "t", description: "details here")
assert_equal "details here", card["description"]
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
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" }
@client.attach_label(card["id"], p1.id)
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
def test_attach_label_by_name
card = @cards.add(board_name: "llf-schema", title: "raw card")
@cards.attach_label(board_name: "llf-schema", card_id: card["id"], label: "afk-ready")
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
@cards.attach_label(board_name: "llf-schema", card_id: card["id"], label: "nonexistent")
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")
comment = @cards.comment(card_id: card["id"], text: "audit: in Doing 9 days")
assert_equal card["id"], comment["cardId"]
assert_equal "audit: in Doing 9 days", comment["text"]
assert_equal 1, @client.comments.store.size
end
end