From e406e44f32ea737bd9d0070acb7cf99ce1e1c33a Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 23 Feb 2024 15:30:03 +0000 Subject: feat(list): newest proposals firsts show proposals in order newest first --- src/sub_commands/list.rs | 7 +++- tests/list.rs | 100 +++++++++++++++++++++++------------------------ 2 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index f7397f1..ad5a28d 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs @@ -732,7 +732,7 @@ pub async fn find_proposal_events( repo_ref: &RepoRef, root_commit: &str, ) -> Result> { - Ok(client + let mut proposals = client .get_events( repo_ref.relays.clone(), vec![ @@ -773,7 +773,10 @@ pub async fn find_proposal_events( })) }) .map(std::borrow::ToOwned::to_owned) - .collect::>()) + .collect::>(); + proposals.sort_by_key(|e| e.created_at); + proposals.reverse(); + Ok(proposals) } pub async fn find_commits_for_proposal_root_events( diff --git a/tests/list.rs b/tests/list.rs index b6bcd08..6d161ea 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -282,12 +282,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( @@ -355,12 +355,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -471,12 +471,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(2, true, None)?; + c.succeeds_with(0, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( @@ -545,12 +545,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(2, true, None)?; + c.succeeds_with(0, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -667,13 +667,13 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_3}\""), format!("add d3.md"), // commit msg title + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(3, true, None)?; + c.succeeds_with(0, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -747,13 +747,13 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), - format!("\"{PROPOSAL_TITLE_3}\""), format!("add d3.md"), // commit msg title + format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(3, true, None)?; + c.succeeds_with(0, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -879,12 +879,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -958,12 +958,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -1060,12 +1060,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -1138,12 +1138,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; let mut c = p.expect_choice( "", @@ -1257,12 +1257,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; p.expect_eventually("--force`\r\n")?; @@ -1346,12 +1346,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; p.expect("you have an amended/rebase version the proposal that is unpublished\r\n")?; p.expect("you have previously applied the latest version of the proposal (2 ahead 0 behind 'main') but your local proposal branch has amended or rebased it (2 ahead 0 behind 'main')\r\n")?; @@ -1460,12 +1460,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; p.expect( "local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal (3 ahead 0 behind 'main')\r\n", @@ -1543,12 +1543,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; p.expect( "local proposal branch exists with 1 unpublished commits on top of the most up-to-date version of the proposal (3 ahead 0 behind 'main')\r\n", @@ -1702,12 +1702,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; let mut c = p.expect_choice( @@ -1826,12 +1826,12 @@ mod when_main_branch_is_uptodate { let mut c = p.expect_choice( "all proposals", vec![ - format!("\"{PROPOSAL_TITLE_1}\""), - format!("\"{PROPOSAL_TITLE_2}\""), format!("\"{PROPOSAL_TITLE_3}\""), + format!("\"{PROPOSAL_TITLE_2}\""), + format!("\"{PROPOSAL_TITLE_1}\""), ], )?; - c.succeeds_with(0, true, None)?; + c.succeeds_with(2, true, None)?; p.expect("finding commits...\r\n")?; p.expect("updated proposal available (2 ahead 0 behind 'main'). existing version is 2 ahead 1 behind 'main'\r\n")?; let mut c = p.expect_choice( -- cgit v1.2.3