diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-13 14:52:24 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-13 15:55:54 +0000 |
| commit | cf319efc6dcdc6c54564cb84e13218edbf3643fa (patch) | |
| tree | ccccf807fac6c2ab242b2d6bb322c679ae5b94f7 /tests/prs_list.rs | |
| parent | 3112576195aef212622d27ad9164336796c1953e (diff) | |
feat!: nip34 make pr event optional
use first patch as thread root if pr event isn't present.
begin renaming pr event to cover letter.
fix patch ordering upon creation. patches were in youngest first
order which caused:
- `PATCH n/t`to be in reverse order
- the youngest patch was the marked root
- oldest patch replied to the youngest
fix finding most recent patch event. when a patch in a set is the
most recent it will share a created_at with other patches.
previously the first patch recieved from relay in the set would be
used. now it finds the first patch with that created_at which isn't
also a parent of another patch with the same created_at.
Diffstat (limited to 'tests/prs_list.rs')
| -rw-r--r-- | tests/prs_list.rs | 241 |
1 files changed, 216 insertions, 25 deletions
diff --git a/tests/prs_list.rs b/tests/prs_list.rs index 75704f6..7c0d8ec 100644 --- a/tests/prs_list.rs +++ b/tests/prs_list.rs | |||
| @@ -6,6 +6,7 @@ use test_utils::{git::GitTestRepo, relay::Relay, *}; | |||
| 6 | static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; | 6 | static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; |
| 7 | static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; | 7 | static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; |
| 8 | static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; | 8 | static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; |
| 9 | static FEATURE_BRANCH_NAME_4: &str = "feature-example-d"; | ||
| 9 | 10 | ||
| 10 | static PR_TITLE_1: &str = "pr a"; | 11 | static PR_TITLE_1: &str = "pr a"; |
| 11 | static PR_TITLE_2: &str = "pr b"; | 12 | static PR_TITLE_2: &str = "pr b"; |
| @@ -18,22 +19,19 @@ fn cli_tester_create_prs() -> Result<GitTestRepo> { | |||
| 18 | &git_repo, | 19 | &git_repo, |
| 19 | FEATURE_BRANCH_NAME_1, | 20 | FEATURE_BRANCH_NAME_1, |
| 20 | "a", | 21 | "a", |
| 21 | PR_TITLE_1, | 22 | Some((PR_TITLE_1, "pr a description")), |
| 22 | "pr a description", | ||
| 23 | )?; | 23 | )?; |
| 24 | cli_tester_create_pr( | 24 | cli_tester_create_pr( |
| 25 | &git_repo, | 25 | &git_repo, |
| 26 | FEATURE_BRANCH_NAME_2, | 26 | FEATURE_BRANCH_NAME_2, |
| 27 | "b", | 27 | "b", |
| 28 | PR_TITLE_2, | 28 | Some((PR_TITLE_2, "pr b description")), |
| 29 | "pr b description", | ||
| 30 | )?; | 29 | )?; |
| 31 | cli_tester_create_pr( | 30 | cli_tester_create_pr( |
| 32 | &git_repo, | 31 | &git_repo, |
| 33 | FEATURE_BRANCH_NAME_3, | 32 | FEATURE_BRANCH_NAME_3, |
| 34 | "c", | 33 | "c", |
| 35 | PR_TITLE_3, | 34 | Some((PR_TITLE_3, "pr c description")), |
| 36 | "pr c description", | ||
| 37 | )?; | 35 | )?; |
| 38 | Ok(git_repo) | 36 | Ok(git_repo) |
| 39 | } | 37 | } |
| @@ -66,28 +64,44 @@ fn cli_tester_create_pr( | |||
| 66 | test_repo: &GitTestRepo, | 64 | test_repo: &GitTestRepo, |
| 67 | branch_name: &str, | 65 | branch_name: &str, |
| 68 | prefix: &str, | 66 | prefix: &str, |
| 69 | title: &str, | 67 | cover_letter_title_and_description: Option<(&str, &str)>, |
| 70 | description: &str, | ||
| 71 | ) -> Result<()> { | 68 | ) -> Result<()> { |
| 72 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; | 69 | create_and_populate_branch(test_repo, branch_name, prefix, false)?; |
| 73 | 70 | ||
| 74 | let mut p = CliTester::new_from_dir( | 71 | if let Some((title, description)) = cover_letter_title_and_description { |
| 75 | &test_repo.dir, | 72 | let mut p = CliTester::new_from_dir( |
| 76 | [ | 73 | &test_repo.dir, |
| 77 | "--nsec", | 74 | [ |
| 78 | TEST_KEY_1_NSEC, | 75 | "--nsec", |
| 79 | "--password", | 76 | TEST_KEY_1_NSEC, |
| 80 | TEST_PASSWORD, | 77 | "--password", |
| 81 | "--disable-cli-spinners", | 78 | TEST_PASSWORD, |
| 82 | "prs", | 79 | "--disable-cli-spinners", |
| 83 | "create", | 80 | "prs", |
| 84 | "--title", | 81 | "create", |
| 85 | format!("\"{title}\"").as_str(), | 82 | "--title", |
| 86 | "--description", | 83 | format!("\"{title}\"").as_str(), |
| 87 | format!("\"{description}\"").as_str(), | 84 | "--description", |
| 88 | ], | 85 | format!("\"{description}\"").as_str(), |
| 89 | ); | 86 | ], |
| 90 | p.expect_end_eventually()?; | 87 | ); |
| 88 | p.expect_end_eventually()?; | ||
| 89 | } else { | ||
| 90 | let mut p = CliTester::new_from_dir( | ||
| 91 | &test_repo.dir, | ||
| 92 | [ | ||
| 93 | "--nsec", | ||
| 94 | TEST_KEY_1_NSEC, | ||
| 95 | "--password", | ||
| 96 | TEST_PASSWORD, | ||
| 97 | "--disable-cli-spinners", | ||
| 98 | "prs", | ||
| 99 | "create", | ||
| 100 | "--no-cover-letter", | ||
| 101 | ], | ||
| 102 | ); | ||
| 103 | p.expect_end_eventually()?; | ||
| 104 | } | ||
| 91 | Ok(()) | 105 | Ok(()) |
| 92 | } | 106 | } |
| 93 | 107 | ||
| @@ -432,6 +446,183 @@ mod when_main_branch_is_uptodate { | |||
| 432 | Ok(()) | 446 | Ok(()) |
| 433 | } | 447 | } |
| 434 | } | 448 | } |
| 449 | mod when_forth_pr_has_no_cover_letter { | ||
| 450 | use super::*; | ||
| 451 | |||
| 452 | async fn prep_and_run() -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 453 | // fallback (51,52) user write (53, 55) repo (55, 56) | ||
| 454 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 455 | Relay::new(8051, None, None), | ||
| 456 | Relay::new(8052, None, None), | ||
| 457 | Relay::new(8053, None, None), | ||
| 458 | Relay::new(8055, None, None), | ||
| 459 | Relay::new(8056, None, None), | ||
| 460 | ); | ||
| 461 | |||
| 462 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 463 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 464 | r51.events.push(generate_repo_ref_event()); | ||
| 465 | |||
| 466 | r55.events.push(generate_repo_ref_event()); | ||
| 467 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 468 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 469 | |||
| 470 | let cli_tester_handle = | ||
| 471 | std::thread::spawn(move || -> Result<(GitTestRepo, GitTestRepo)> { | ||
| 472 | let originating_repo = cli_tester_create_prs()?; | ||
| 473 | cli_tester_create_pr( | ||
| 474 | &originating_repo, | ||
| 475 | FEATURE_BRANCH_NAME_4, | ||
| 476 | "d", | ||
| 477 | None, | ||
| 478 | )?; | ||
| 479 | let test_repo = GitTestRepo::default(); | ||
| 480 | test_repo.populate()?; | ||
| 481 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["prs", "list"]); | ||
| 482 | |||
| 483 | p.expect("finding PRs...\r\n")?; | ||
| 484 | let mut c = p.expect_choice( | ||
| 485 | "All PRs", | ||
| 486 | vec![ | ||
| 487 | format!("\"{PR_TITLE_1}\""), | ||
| 488 | format!("\"{PR_TITLE_2}\""), | ||
| 489 | format!("\"{PR_TITLE_3}\""), | ||
| 490 | format!("add d3.md"), // commit msg title | ||
| 491 | ], | ||
| 492 | )?; | ||
| 493 | c.succeeds_with(3, true)?; | ||
| 494 | let mut confirm = | ||
| 495 | p.expect_confirm_eventually("check out branch?", Some(true))?; | ||
| 496 | confirm.succeeds_with(None)?; | ||
| 497 | p.expect_end_eventually_and_print()?; | ||
| 498 | |||
| 499 | for p in [51, 52, 53, 55, 56] { | ||
| 500 | relay::shutdown_relay(8000 + p)?; | ||
| 501 | } | ||
| 502 | Ok((originating_repo, test_repo)) | ||
| 503 | }); | ||
| 504 | |||
| 505 | // launch relay | ||
| 506 | let _ = join!( | ||
| 507 | r51.listen_until_close(), | ||
| 508 | r52.listen_until_close(), | ||
| 509 | r53.listen_until_close(), | ||
| 510 | r55.listen_until_close(), | ||
| 511 | r56.listen_until_close(), | ||
| 512 | ); | ||
| 513 | let res = cli_tester_handle.join().unwrap()?; | ||
| 514 | |||
| 515 | Ok(res) | ||
| 516 | } | ||
| 517 | |||
| 518 | mod cli_prompts { | ||
| 519 | use super::*; | ||
| 520 | async fn run_async_prompts_to_choose_from_pr_titles() -> Result<()> { | ||
| 521 | let (mut r51, mut r52, mut r53, mut r55, mut r56) = ( | ||
| 522 | Relay::new(8051, None, None), | ||
| 523 | Relay::new(8052, None, None), | ||
| 524 | Relay::new(8053, None, None), | ||
| 525 | Relay::new(8055, None, None), | ||
| 526 | Relay::new(8056, None, None), | ||
| 527 | ); | ||
| 528 | |||
| 529 | r51.events.push(generate_test_key_1_relay_list_event()); | ||
| 530 | r51.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 531 | r51.events.push(generate_repo_ref_event()); | ||
| 532 | |||
| 533 | r55.events.push(generate_repo_ref_event()); | ||
| 534 | r55.events.push(generate_test_key_1_metadata_event("fred")); | ||
| 535 | r55.events.push(generate_test_key_1_relay_list_event()); | ||
| 536 | |||
| 537 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | ||
| 538 | let originating_repo = cli_tester_create_prs()?; | ||
| 539 | cli_tester_create_pr( | ||
| 540 | &originating_repo, | ||
| 541 | FEATURE_BRANCH_NAME_4, | ||
| 542 | "d", | ||
| 543 | None, | ||
| 544 | )?; | ||
| 545 | let test_repo = GitTestRepo::default(); | ||
| 546 | test_repo.populate()?; | ||
| 547 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["prs", "list"]); | ||
| 548 | |||
| 549 | p.expect("finding PRs...\r\n")?; | ||
| 550 | let mut c = p.expect_choice( | ||
| 551 | "All PRs", | ||
| 552 | vec![ | ||
| 553 | format!("\"{PR_TITLE_1}\""), | ||
| 554 | format!("\"{PR_TITLE_2}\""), | ||
| 555 | format!("\"{PR_TITLE_3}\""), | ||
| 556 | format!("add d3.md"), // commit msg title | ||
| 557 | ], | ||
| 558 | )?; | ||
| 559 | c.succeeds_with(3, true)?; | ||
| 560 | p.expect("finding commits...\r\n")?; | ||
| 561 | let mut confirm = p.expect_confirm("check out branch?", Some(true))?; | ||
| 562 | confirm.succeeds_with(None)?; | ||
| 563 | p.expect("checked out PR branch. pulled 2 new commits\r\n")?; | ||
| 564 | p.expect_end()?; | ||
| 565 | |||
| 566 | for p in [51, 52, 53, 55, 56] { | ||
| 567 | relay::shutdown_relay(8000 + p)?; | ||
| 568 | } | ||
| 569 | Ok(()) | ||
| 570 | }); | ||
| 571 | |||
| 572 | // launch relay | ||
| 573 | let _ = join!( | ||
| 574 | r51.listen_until_close(), | ||
| 575 | r52.listen_until_close(), | ||
| 576 | r53.listen_until_close(), | ||
| 577 | r55.listen_until_close(), | ||
| 578 | r56.listen_until_close(), | ||
| 579 | ); | ||
| 580 | cli_tester_handle.join().unwrap()?; | ||
| 581 | println!("{:?}", r55.events); | ||
| 582 | Ok(()) | ||
| 583 | } | ||
| 584 | |||
| 585 | #[tokio::test] | ||
| 586 | #[serial] | ||
| 587 | async fn prompts_to_choose_from_pr_titles() -> Result<()> { | ||
| 588 | let _ = run_async_prompts_to_choose_from_pr_titles().await; | ||
| 589 | Ok(()) | ||
| 590 | } | ||
| 591 | } | ||
| 592 | |||
| 593 | #[tokio::test] | ||
| 594 | #[serial] | ||
| 595 | async fn pr_branch_created_with_correct_name() -> Result<()> { | ||
| 596 | let (_, test_repo) = prep_and_run().await?; | ||
| 597 | assert_eq!( | ||
| 598 | vec![FEATURE_BRANCH_NAME_4, "main"], | ||
| 599 | test_repo.get_local_branch_names()? | ||
| 600 | ); | ||
| 601 | Ok(()) | ||
| 602 | } | ||
| 603 | |||
| 604 | #[tokio::test] | ||
| 605 | #[serial] | ||
| 606 | async fn pr_branch_checked_out() -> Result<()> { | ||
| 607 | let (_, test_repo) = prep_and_run().await?; | ||
| 608 | assert_eq!( | ||
| 609 | FEATURE_BRANCH_NAME_4, | ||
| 610 | test_repo.get_checked_out_branch_name()?, | ||
| 611 | ); | ||
| 612 | Ok(()) | ||
| 613 | } | ||
| 614 | |||
| 615 | #[tokio::test] | ||
| 616 | #[serial] | ||
| 617 | async fn pr_branch_tip_is_most_recent_patch() -> Result<()> { | ||
| 618 | let (originating_repo, test_repo) = prep_and_run().await?; | ||
| 619 | assert_eq!( | ||
| 620 | originating_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?, | ||
| 621 | test_repo.get_tip_of_local_branch(FEATURE_BRANCH_NAME_4)?, | ||
| 622 | ); | ||
| 623 | Ok(()) | ||
| 624 | } | ||
| 625 | } | ||
| 435 | } | 626 | } |
| 436 | } | 627 | } |
| 437 | 628 | ||