bbyars/mountebank

View on GitHub
src/views/docs/api/predicates/and.ejs

Summary

Maintainability
Test Coverage
<p>The <code>and</code> predicate matches if all of its sub-predicates match.</p>

<testScenario name='tcp and example'>
    <step type='http'>
<pre><code>POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json
Content-Type: application/json

{
  "port": 4554,
  "protocol": "tcp",
  "mode": "text",
  "stubs": [<strong class='highlight1'>
    {
      "responses": [{ "is": { "data": "matches" } }],
      "predicates": [
        {
          "and": [
            { "startsWith": { "data": "start" } },
            { "endsWith": { "data": "end\n" } },
            { "contains": { "data": "middle" } }
          ]
        }
      ]
    }</strong>
  ]
}</code></pre>
    </step>

<p>The first request matches all sub-predicates, triggering the stub response:</p>

    <step type='exec'>
<pre><code>echo '<strong class='highlight1'>start middle end</strong>' | nc localhost 4554</code></pre>

        <assertResponse>
<pre><code><strong class='highlight1'>matches</strong></code></pre>
        </assertResponse>
    </step>

    <p>The stub matches two of the three sub-predicates, which is not enough to match
the <code>and</code> predicate.</p>

<p>The stub does not match none of the sub-predicates match...</p>

    <step type='exec'>
<pre><code>echo '<strong class='highlight1'>start end</strong>' | nc localhost 4554</code></pre>

<p>No response is sent.</p>

        <assertResponse>
<pre><code>
</code></pre>
        </assertResponse>
    </step>

    <step type='http'>
<code class='hidden'>DELETE /imposters/4554 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json</code>
    </step>
</testScenario>