100 lines
3.0 KiB
Rust
100 lines
3.0 KiB
Rust
|
|
use assert_fs::TempDir;
|
||
|
|
#[cfg(feature = "test-utils")]
|
||
|
|
use jj_cz::{CommitType, Description, MockPrompts, Scope};
|
||
|
|
use jj_cz::{CommitWorkflow, Error, JjLib};
|
||
|
|
#[cfg(feature = "test-utils")]
|
||
|
|
use std::process::Command;
|
||
|
|
|
||
|
|
/// Helper to initialize a temporary jj repository
|
||
|
|
#[cfg(feature = "test-utils")]
|
||
|
|
fn init_jj_repo(temp_dir: &TempDir) {
|
||
|
|
let status = Command::new("jj")
|
||
|
|
.args(["git", "init"])
|
||
|
|
.current_dir(temp_dir)
|
||
|
|
.status()
|
||
|
|
.expect("Failed to initialize jj repository");
|
||
|
|
assert!(status.success(), "jj git init failed");
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(feature = "test-utils")]
|
||
|
|
#[tokio::test]
|
||
|
|
async fn test_happy_path_integration() {
|
||
|
|
// T037: Happy path integration test
|
||
|
|
let temp_dir = TempDir::new().unwrap();
|
||
|
|
init_jj_repo(&temp_dir);
|
||
|
|
|
||
|
|
// Create mock prompts that simulate a successful workflow
|
||
|
|
let mock_prompts = MockPrompts::new()
|
||
|
|
.with_commit_type(CommitType::Feat)
|
||
|
|
.with_scope(Scope::empty())
|
||
|
|
.with_description(Description::parse("add new feature").unwrap())
|
||
|
|
.with_confirm(true);
|
||
|
|
|
||
|
|
// Create a mock executor that tracks calls
|
||
|
|
let executor = JjLib::with_working_dir(temp_dir.path());
|
||
|
|
let workflow = CommitWorkflow::with_prompts(executor, mock_prompts);
|
||
|
|
|
||
|
|
let result = workflow.run().await;
|
||
|
|
|
||
|
|
// The workflow should complete successfully
|
||
|
|
assert!(
|
||
|
|
result.is_ok(),
|
||
|
|
"Workflow should complete successfully: {:?}",
|
||
|
|
result
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
#[tokio::test]
|
||
|
|
async fn test_not_in_repo() {
|
||
|
|
// T038: Not-in-repo integration test
|
||
|
|
let temp_dir = TempDir::new().unwrap();
|
||
|
|
// Don't initialize jj repo
|
||
|
|
|
||
|
|
// Create executor with the temp directory (which is not a jj repo)
|
||
|
|
let executor = JjLib::with_working_dir(temp_dir.path());
|
||
|
|
let workflow = CommitWorkflow::new(executor);
|
||
|
|
|
||
|
|
let result = workflow.run().await;
|
||
|
|
|
||
|
|
// Should fail with NotARepository error
|
||
|
|
assert!(matches!(result, Err(Error::NotARepository)));
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(feature = "test-utils")]
|
||
|
|
#[tokio::test]
|
||
|
|
async fn test_cancellation() {
|
||
|
|
// T039: Cancellation integration test
|
||
|
|
// This is tricky to test directly without a TTY
|
||
|
|
// We'll test the error handling path instead
|
||
|
|
|
||
|
|
let temp_dir = TempDir::new().unwrap();
|
||
|
|
init_jj_repo(&temp_dir);
|
||
|
|
|
||
|
|
// Create a mock executor that simulates cancellation
|
||
|
|
struct CancelMock;
|
||
|
|
|
||
|
|
#[async_trait::async_trait(?Send)]
|
||
|
|
impl jj_cz::JjExecutor for CancelMock {
|
||
|
|
async fn is_repository(&self) -> Result<bool, Error> {
|
||
|
|
Ok(true)
|
||
|
|
}
|
||
|
|
|
||
|
|
async fn describe(&self, _message: &str) -> Result<(), Error> {
|
||
|
|
Err(Error::Cancelled)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let executor = CancelMock;
|
||
|
|
let mock_prompts = MockPrompts::new()
|
||
|
|
.with_commit_type(CommitType::Feat)
|
||
|
|
.with_scope(Scope::empty())
|
||
|
|
.with_description(Description::parse("test").unwrap())
|
||
|
|
.with_confirm(true);
|
||
|
|
let workflow = CommitWorkflow::with_prompts(executor, mock_prompts);
|
||
|
|
|
||
|
|
let result = workflow.run().await;
|
||
|
|
|
||
|
|
// Should fail with Cancelled error
|
||
|
|
assert!(matches!(result, Err(Error::Cancelled)));
|
||
|
|
}
|