test(add): cover insert_method revert/not-found paths and only_controller errors

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-11 13:38:09 -05:00
1 parent 4fe5b53e7f
commit 0aee29478b
2 files changed
+39

No files matched your search

+26
View File
@@ -17,3 +17,29 @@ fn add_sse_appends_handler() {
assert!(out.contains("@Sse("));
assert!(out.contains("import { Route, Get, Sse }") || out.contains("Sse }"));
}
#[test]
fn add_errors_when_no_controller() {
let d = tempdir().unwrap();
std::fs::create_dir_all(d.path().join("src/controllers")).unwrap();
Command::cargo_bin("matcha").unwrap()
.current_dir(d.path())
.args(["add", "sse"]).assert().failure();
}
#[test]
fn add_errors_when_multiple_controllers_and_writes_nothing() {
let d = tempdir().unwrap();
let cdir = d.path().join("src/controllers");
std::fs::create_dir_all(&cdir).unwrap();
let original = "export class X {}\n";
for n in ["a", "b"] {
std::fs::write(cdir.join(format!("{n}.controller.ts")), original).unwrap();
}
Command::cargo_bin("matcha").unwrap()
.current_dir(d.path())
.args(["add", "sse"]).assert().failure();
// no file was modified
assert_eq!(std::fs::read_to_string(cdir.join("a.controller.ts")).unwrap(), original);
assert_eq!(std::fs::read_to_string(cdir.join("b.controller.ts")).unwrap(), original);
}