require_relative "test_helper"

class ResolverTest < Minitest::Test
  def test_configured_project_uses_configured_board
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/some-repo",
      config_contents: "board: llf-schema\n",
      boards: %w[llf-schema other-board]
    )

    assert_equal "use llf-schema", resolver.resolve_string
  end

  def test_unconfigured_dev_repo_uses_board_named_after_repo
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/llf-schema",
      config_contents: nil,
      boards: %w[llf-schema]
    )

    assert_equal "use llf-schema", resolver.resolve_string
  end

  def test_unconfigured_client_repo_uses_board_named_after_repo
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/clients/acme-co",
      config_contents: nil,
      boards: %w[acme-co]
    )

    assert_equal "use acme-co", resolver.resolve_string
  end

  def test_matching_archived_board_activates
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/old-project",
      config_contents: nil,
      boards: %w[archived--old-project]
    )

    assert_equal "activate archived--old-project", resolver.resolve_string
  end

  def test_configured_archived_board_activates
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/some-repo",
      config_contents: "board: old-project\n",
      boards: %w[archived--old-project]
    )

    assert_equal "activate archived--old-project", resolver.resolve_string
  end

  def test_no_match_stops_and_discusses
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/brand-new-repo",
      config_contents: nil,
      boards: %w[unrelated-board]
    )

    assert_equal "stop-and-discuss", resolver.resolve_string
  end

  def test_path_outside_dev_and_clients_is_ambiguous
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/scratch/some-repo",
      config_contents: nil,
      boards: %w[some-repo]
    )

    assert_equal "stop-and-discuss", resolver.resolve_string
  end

  def test_configured_board_with_no_match_stops_and_discusses
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/some-repo",
      config_contents: "board: nonexistent\n",
      boards: %w[llf-schema]
    )

    assert_equal "stop-and-discuss", resolver.resolve_string
  end

  def test_empty_config_contents_is_treated_as_unconfigured
    resolver = Backlog::Resolver.new(
      repo_path: "/home/jared/dev/llf-schema",
      config_contents: "",
      boards: %w[llf-schema]
    )

    assert_equal "use llf-schema", resolver.resolve_string
  end
end
