feat(add,create): matcha add cookie and matcha create transformer
CI / installer (macos-14) (pull_request) Successful in 3s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Failing after 31s
CI / starter (deno) (pull_request) Failing after 32s
CI / starter (edge) (pull_request) Failing after 37s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 9s
CI / starter (node) (pull_request) Failing after 32s
CI / installer (macos-14) (pull_request) Successful in 3s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Failing after 31s
CI / starter (deno) (pull_request) Failing after 32s
CI / starter (edge) (pull_request) Failing after 37s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 9s
CI / starter (node) (pull_request) Failing after 32s
add cookie reads a cookie with @cookie and sets one through a @Transformer and setCookie, since core sends Set-Cookie only as a header. create transformer writes a typed TransformerFn and prints how to attach it; there is nothing to wire into a module. starter-smoke now covers both. add cookie uses @cookie and setCookie, which are new in core RC.1, so this lands together with the CORE_VERSION bump. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
6 files changed
+133
-2
No files matched your search
@@ -199,3 +199,37 @@ fn add_rejects_a_controller_path_that_does_not_exist() {
|
||||
.failure()
|
||||
.stderr(predicates::str::contains("no such controller"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_cookie_reads_with_the_decorator_and_writes_through_a_transformer() {
|
||||
let d = tempdir().unwrap();
|
||||
std::fs::create_dir_all(d.path().join("src/controllers")).unwrap();
|
||||
std::fs::write(
|
||||
d.path().join("src/controllers/home.controller.ts"),
|
||||
"import { Route, Get } from '@green-tea/core';\n\n\
|
||||
@Route('/')\nexport class HomeController {\n @Get('/')\n home() {}\n}\n",
|
||||
)
|
||||
.unwrap();
|
||||
for _ in 0..2 {
|
||||
Command::cargo_bin("matcha")
|
||||
.unwrap()
|
||||
.current_dir(d.path())
|
||||
.args(["add", "cookie"])
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
let out = std::fs::read_to_string(d.path().join("src/controllers/home.controller.ts")).unwrap();
|
||||
assert!(out.contains("@cookie('theme')"), "{out}");
|
||||
assert!(out.contains("'set-cookie': setCookie("), "{out}");
|
||||
for symbol in ["Post", "Transformer", "body", "cookie", "setCookie"] {
|
||||
assert!(
|
||||
out.contains(&format!("{symbol},")) || out.contains(&format!("{symbol} }}")),
|
||||
"{symbol} not imported:\n{out}"
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
out.matches("@Post('/prefs')").count(),
|
||||
1,
|
||||
"not idempotent:\n{out}"
|
||||
);
|
||||
}
|
||||
@@ -170,3 +170,29 @@ fn create_does_not_overwrite_an_existing_file() {
|
||||
.stderr(predicates::str::contains("already exists"));
|
||||
assert_eq!(std::fs::read_to_string(&file).unwrap(), "// edited\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_transformer_writes_a_typed_function_and_says_where_it_goes() {
|
||||
let d = tempdir().unwrap();
|
||||
seed_module(d.path());
|
||||
create(d.path(), "transformer", "csv-export")
|
||||
.success()
|
||||
.stdout(predicates::str::contains(
|
||||
"@Transformer(csvExportTransformer)",
|
||||
));
|
||||
let file = std::fs::read_to_string(d.path().join("src/transformers/csvexport.transformer.ts"))
|
||||
.unwrap();
|
||||
assert!(
|
||||
file.contains("import type { TransformerFn } from '@green-tea/core'"),
|
||||
"{file}"
|
||||
);
|
||||
assert!(
|
||||
file.contains("export const csvExportTransformer: TransformerFn"),
|
||||
"{file}"
|
||||
);
|
||||
let module = std::fs::read_to_string(d.path().join("src/app.module.ts")).unwrap();
|
||||
assert!(
|
||||
!module.contains("Transformer"),
|
||||
"a transformer is not a module member:\n{module}"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user