@@ -4057,6 +4057,49 @@ TEST(extract_ts_url_builder_issue1009) {
40574057 PASS ();
40584058}
40594059
4060+ /* A route registration names its middleware before its handler, and every
4061+ * framework here puts the handler last. The handler scan took the FIRST
4062+ * argument that looked like a function reference, so a named middleware won
4063+ * and the HANDLES edge pointed at the middleware instead of the handler. */
4064+ TEST (extract_ts_route_handler_after_named_middleware ) {
4065+ CBMFileResult * r = extract ("function requireAuth(req: any, res: any, next: any) { next(); }\n"
4066+ "function rateLimit(req: any, res: any, next: any) { next(); }\n"
4067+ "function listUsers(req: any, res: any) { res.json([]); }\n"
4068+ "routerGet(\"/users\", requireAuth, rateLimit, listUsers);\n" ,
4069+ CBM_LANG_TYPESCRIPT , "t" , "routes.ts" );
4070+ ASSERT_NOT_NULL (r );
4071+ const CBMCall * c = find_call_by_callee (r , "routerGet" );
4072+ ASSERT_NOT_NULL (c );
4073+ ASSERT_NOT_NULL (c -> first_string_arg );
4074+ ASSERT_STR_EQ (c -> first_string_arg , "/users" );
4075+ ASSERT_NOT_NULL (c -> second_arg_name );
4076+ ASSERT_STR_EQ (c -> second_arg_name , "listUsers" );
4077+ cbm_free_result (r );
4078+ PASS ();
4079+ }
4080+
4081+ /* The same route with its middleware written inline. An arrow function is not
4082+ * one of the kinds the handler scan accepts, so three of them pushed the real
4083+ * handler past the scan bound and no handler came back at all. */
4084+ TEST (extract_ts_route_handler_after_inline_middleware ) {
4085+ CBMFileResult * r = extract ("function listOrders(req: any, res: any) { res.json([]); }\n"
4086+ "routerGet(\"/orders\",\n"
4087+ " (req: any, res: any, next: any) => { next(); },\n"
4088+ " (req: any, res: any, next: any) => { next(); },\n"
4089+ " (req: any, res: any, next: any) => { next(); },\n"
4090+ " listOrders);\n" ,
4091+ CBM_LANG_TYPESCRIPT , "t" , "orders.ts" );
4092+ ASSERT_NOT_NULL (r );
4093+ const CBMCall * c = find_call_by_callee (r , "routerGet" );
4094+ ASSERT_NOT_NULL (c );
4095+ ASSERT_NOT_NULL (c -> first_string_arg );
4096+ ASSERT_STR_EQ (c -> first_string_arg , "/orders" );
4097+ ASSERT_NOT_NULL (c -> second_arg_name );
4098+ ASSERT_STR_EQ (c -> second_arg_name , "listOrders" );
4099+ cbm_free_result (r );
4100+ PASS ();
4101+ }
4102+
40604103/* Issue #1009 (composed builders): a builder whose template inlines an earlier
40614104 * builder's call plus a query string: `return \`${basePath(id)}?${params}\``.
40624105 * The known-substitution is inlined and the query string is truncated, so the
@@ -6892,6 +6935,8 @@ SUITE(extraction) {
68926935 RUN_TEST (extract_go_binary_concat_url_issue1249 );
68936936 RUN_TEST (extract_go_binary_concat_url_no_literal_suffix_issue1249 );
68946937 RUN_TEST (extract_ts_url_builder_issue1009 );
6938+ RUN_TEST (extract_ts_route_handler_after_named_middleware );
6939+ RUN_TEST (extract_ts_route_handler_after_inline_middleware );
68956940 RUN_TEST (extract_ts_url_builder_composed_issue1009 );
68966941 RUN_TEST (extract_c_url_builder_gated_issue1009 );
68976942 RUN_TEST (extract_ts_url_builder_mixed_returns_issue1009 );
0 commit comments