use super::*;

#[test]
fn parses_typed_yaml_and_rejects_bad_indexes() {
    let issue: CreateIssueInput =
        parse_yaml("title: Fix it\nbody: Details\nlabel_names: [bug]\nmilestone_name: Version 1\n")
            .unwrap();

    assert_eq!(issue.issue.title, "Fix it");
    assert_eq!(issue.issue.body.as_deref(), Some("Details"));
    assert_eq!(issue.label_names, ["bug"]);
    assert_eq!(issue.milestone_name.as_deref(), Some("Version 1"));
    let edit: EditIssueInput = parse_yaml(
        "title: Updated\nadd_labels: [critical]\nremove_labels: [bug]\nadd_assignees: [alice]\n",
    )
    .unwrap();
    assert_eq!(edit.issue.title.as_deref(), Some("Updated"));
    assert_eq!(edit.add_labels, ["critical"]);
    assert_eq!(edit.remove_labels, ["bug"]);
    assert_eq!(edit.add_assignees, ["alice"]);
    assert!(number("0").is_err());
    assert!(number("7").is_ok());
}

#[test]
fn parses_issue_workflow_filters_and_bulk_state_targets() {
    let options = parse_issue_list(
        &[
            "hugo/Gotcha",
            "--state",
            "all",
            "--milestones",
            "first feature complete release",
            "-L",
            "bug,critical",
            "--page",
            "2",
            "--limit",
            "50",
        ]
        .map(str::to_owned),
    )
    .unwrap();
    assert_eq!(options.repository.as_deref(), Some("hugo/Gotcha"));
    assert_eq!(options.state, "all");
    assert_eq!(
        options.milestones.as_deref(),
        Some("first feature complete release")
    );
    assert_eq!(options.labels.as_deref(), Some("bug,critical"));
    assert_eq!((options.page, options.limit), (2, 50));

    let (indexes, repository) =
        issue_targets(&["4", "16", "hugo/Gotcha"].map(str::to_owned)).unwrap();
    assert_eq!(indexes, [4, 16]);
    assert_eq!(repository.as_deref(), Some("hugo/Gotcha"));
    assert!(parse_issue_list(&["--state".into(), "invalid".into()]).is_err());
    assert!(issue_targets(&[]).is_err());
}
