Files
matcha/tests/create.rs
T
chrnx 2f9b656692 fix(add): merge imports into existing brace + capability idempotency; fmt
- wire::add_import now merges a new symbol into an already-present
  `import { ... } from '<from>';` brace instead of appending a second,
  colliding import line for the same module (a duplicate ESM binding
  is a hard SyntaxError/TS2300, not a harmless dupe as previously
  assumed). Falls back to appending a new line when the module isn't
  imported yet, or if the brace-merge edit fails the parses_clean
  guard.
- cmd_add::run gains a capability-level idempotency guard, keyed on
  each capability's unique route-path literal, so `matcha add <cap>`
  run twice no longer appends a duplicate handler + route.
- cargo fmt --all across the crate; drop the stale #[allow(dead_code)]
  on wire::parses_clean now that it's demonstrably live.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-07-11 13:52:21 -05:00

33 lines
935 B
Rust

use assert_cmd::Command;
use tempfile::tempdir;
fn seed_module(dir: &std::path::Path) {
std::fs::create_dir_all(dir.join("src/controllers")).unwrap();
std::fs::write(
dir.join("src/app.module.ts"),
"import { Module } from '@green-tea/core';\n\n\
@Module({ controllers: [] })\nexport class AppModule {}\n",
)
.unwrap();
}
#[test]
fn create_controller_writes_and_wires() {
let d = tempdir().unwrap();
seed_module(d.path());
Command::cargo_bin("matcha")
.unwrap()
.current_dir(d.path())
.args(["create", "controller", "Users"])
.assert()
.success();
assert!(d
.path()
.join("src/controllers/users.controller.ts")
.exists());
let module = std::fs::read_to_string(d.path().join("src/app.module.ts")).unwrap();
assert!(module.contains("UsersController"));
assert!(module.contains("import { UsersController }"));
}