alef-e2e 0.15.25

Fixture-driven e2e test generator for alef
Documentation
{#- TypeScript HTTP test case template

   Context variables:
   - test_name: sanitized test name
   - description: fixture description with escaped quotes
   - method: HTTP method (uppercase)
   - init_str: fetch init parameters as string
   - fixture_id: escaped fixture ID
   - expected_status: HTTP status code
   - has_text_body: bool
   - text_body: escaped text body (or empty)
   - has_json_body: bool
   - json_val: JSON value as JS literal
   - has_partial_body: bool
   - partial_body_checks: array of {key, js_val} dicts
   - header_assertions: array of {name, assertion_type, value} dicts
   - has_validation_errors: bool
   - validation_errors: array of {loc_js, escaped_msg} dicts
#}
  it('{{ test_name }}: {{ description }}', async () => {
    const mockUrl = `${process.env.MOCK_SERVER_URL}/fixtures/{{ fixture_id }}`;
    const response = await fetch(mockUrl, { {{ init_str }} });
    expect(response.status).toBe({{ expected_status }});
{%- if has_text_body %}
    const text = await response.text();
    expect(text).toBe('{{ text_body }}');
{%- elif has_json_body %}
    const data = await response.json();
    expect(data).toEqual({{ json_val }});
{%- elif has_partial_body %}
    const data = await response.json();
{%- for check in partial_body_checks %}
    expect((data as Record<string, unknown>)['{{ check.key }}']).toEqual({{ check.js_val }});
{%- endfor %}
{%- endif %}
{%- for assertion in header_assertions %}
{%- if assertion.assertion_type == "present" %}
    expect(response.headers.get('{{ assertion.name }}')).not.toBeNull();
{%- elif assertion.assertion_type == "absent" %}
    expect(response.headers.get('{{ assertion.name }}')).toBeNull();
{%- elif assertion.assertion_type == "uuid" %}
    expect(response.headers.get('{{ assertion.name }}')).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
{%- else %}
    expect(response.headers.get('{{ assertion.name }}')).toBe('{{ assertion.value }}');
{%- endif %}
{%- endfor %}
{%- if has_validation_errors %}
    const body = await response.json() as { errors?: unknown[] };
    const errors = body.errors ?? [];
{%- for ve in validation_errors %}
    expect((errors as Array<Record<string, unknown>>).some((e) => JSON.stringify(e["loc"]) === JSON.stringify([{{ ve.loc_js }}]) && String(e["msg"]).includes("{{ ve.escaped_msg }}"))).toBe(true);
{%- endfor %}
{%- endif %}
  });