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

67 lines
2.3 KiB
Ruby

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
end