use super::*;

#[test]
fn scopes_comments_and_builds_label_payloads() {
    let comment = models::Comment {
        issue_url: Some("https://example.test/api/v1/repos/a/b/issues/7".into()),
        ..Default::default()
    };
    assert!(comment_belongs_to_issue(&comment, 7));
    assert!(!comment_belongs_to_issue(&comment, 8));
    assert!(!comment_can_edit(&comment, Some(1)));
    let owned = models::Comment {
        id: Some(3),
        user: Some(Box::new(models::User {
            id: Some(1),
            ..Default::default()
        })),
        ..Default::default()
    };
    assert!(comment_can_edit(&owned, Some(1)));
    assert_eq!(label_option(&[2, 4]).labels.unwrap().len(), 2);
}

#[test]
fn maps_issue_drafts_without_losing_clear_operations() {
    let draft = IssueDraft {
        title: "Title".into(),
        body: "Body".into(),
        label_ids: vec![2, 4],
        milestone_id: None,
        due_date: None,
        closed: true,
    };
    let create = create_issue_option(draft.clone());
    assert_eq!(create.title, "Title");
    assert_eq!(create.body.as_deref(), Some("Body"));
    assert_eq!(create.closed, Some(true));
    assert_eq!(create.labels, Some(vec![2, 4]));
    let edit = edit_issue_draft(draft);
    assert_eq!(edit.option.milestone, Some(0));
    assert_eq!(edit.option.state.as_deref(), Some("closed"));
    assert_eq!(edit.option.unset_due_date, Some(true));
    assert_eq!(edit.replace_labels, Some(vec![2, 4]));
}
