use crate::e2e::config::E2eConfig;
use crate::e2e::fixture::{Assertion, Fixture};
fn mock_total_fixture() -> Fixture {
Fixture {
id: "wasm_mock_capture_fixture".to_string(),
category: Some("mock_capture".to_string()),
description: "asserts against the mock server request log for a result_is_simple call".to_string(),
assertions: vec![Assertion {
assertion_type: "equals".to_string(),
field: Some("mock.requests.total".to_string()),
value: Some(serde_json::json!(1)),
..Default::default()
}],
..Default::default()
}
}
fn render(e2e_config: &E2eConfig, fixture: &Fixture) -> String {
crate::e2e::codegen::typescript::render_test_file(
"wasm",
"mock_capture",
&[fixture],
"",
"sample-wasm-bindings",
"speech",
&[],
None,
None,
e2e_config,
&[],
&[],
&[],
"Wasm",
&crate::core::config::ResolvedCrateConfig::default(),
&[],
)
}
#[test]
fn mock_assertion_wins_over_the_result_is_simple_length_dispatch() {
let mut e2e_config = E2eConfig::default();
e2e_config.call.result_is_simple = true;
let fixture = mock_total_fixture();
let out = render(&e2e_config, &fixture);
assert!(
out.contains(
" expect(await alefMockRequestCount(`${process.env.MOCK_SERVER_URL}`, \"/__alef/requests/total?prefix=\")).toBe(1);"
),
"expected the mock-capture call even for a result_is_simple call, got:\n{out}"
);
assert!(
!out.contains("result.length"),
"the mock.* assertion must never fall into the result_is_simple length dispatch, got:\n{out}"
);
assert!(
out.contains("async function alefMockRequestCount(baseUrl: string, pathAndQuery: string): Promise<number> {"),
"expected the helper definition alongside the call, got:\n{out}"
);
}
#[test]
fn a_result_is_simple_fixture_with_no_mock_assertion_defines_no_helper() {
let mut e2e_config = E2eConfig::default();
e2e_config.call.result_is_simple = true;
let fixture = Fixture {
id: "wasm_no_mock_fixture".to_string(),
category: Some("mock_capture".to_string()),
assertions: vec![Assertion {
assertion_type: "not_empty".to_string(),
field: Some("bytes".to_string()),
..Default::default()
}],
..Default::default()
};
let out = render(&e2e_config, &fixture);
assert!(
!out.contains("alefMockRequestCount"),
"a file with no mock.* assertion must not reference or define the helper, got:\n{out}"
);
}