Skip to content

Commit

Permalink
fix(HttpProxySubscription): OnOriginalMessageReceived event hook crea…
Browse files Browse the repository at this point in the history
…ted to handle outgoing messages
  • Loading branch information
virgs committed Jun 8, 2019
1 parent 8e49300 commit c952f3b
Show file tree
Hide file tree
Showing 18 changed files with 1,717 additions and 2,503 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -377,6 +377,7 @@ By default, there are three hook events available:

**onInit**
Available in requisitions, publishers and subscriptions. It gets executed as soon as the test is initialized.
As available parameter, an `elapsedTime` variable is given, counting every milliseconds since the instantiation of this component.

**onFinish**
Available in requisitions, publishers and subscriptions. It gets executed when the test is about to finish.
Expand All @@ -392,7 +393,6 @@ For instance, in the built-in http publisher implementation, there's a `statusCo

**custom**
Depending on the protocol implementation/library/author's mood, the publisher/subscription may have additional hooks.
As a good practice, is suggested, when implementing your own protocol library, to start the hook name with on preposition.
Such as onError, onFileNotFound and onRedirect...
[Http-proxy subscription test file](https://github.com/enqueuer-land/enqueuer/blob/master/examples/http-proxy.yml) is an excellent example, check it out.

Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Expand Up @@ -652,7 +652,8 @@ <h4 id="hooks" style="padding-left: 8px">3.1 hooks</h4>
<p>By default, there are three hook events available:</p>

<p><strong>onInit</strong> <br>
Available in requisitions, publishers and subscriptions. It gets executed as soon as the test is initialized.</p>
Available in requisitions, publishers and subscriptions. It gets executed as soon as the test is initialized.
As available parameter, an <code class="yaml">elapsedTime</code> variable is given, counting every milliseconds since the instantiation of this component.</p>

<p><strong>onFinish</strong> <br>
Available in requisitions, publishers and subscriptions. It gets executed when the test is about to finish.
Expand All @@ -668,7 +669,6 @@ <h4 id="hooks" style="padding-left: 8px">3.1 hooks</h4>

<p><strong>custom</strong>
Depending on the protocol implementation/library/author's mood, the publisher/subscription may have additional hooks.
As a good practice, is suggested, when implementing your own protocol library, to start the hook name with on preposition.
Such as onError, onFileNotFound and onRedirect...
<a href="https://github.com/enqueuer-land/enqueuer/blob/master/examples/http-proxy.yml">Http-proxy subscription test file</a> is an excellent example, check it out.</p>

Expand Down
80 changes: 31 additions & 49 deletions examples/http-proxy.yml
@@ -1,67 +1,49 @@
publishers:
- name: publisher proxy
type: http
url: http://localhost:23085/proxy/idValue?query=proxied
url: http://localhost:23085/proxy/enqueuer/123456?query=proxied
method: PATCH
payload:
proxy: test
headers:
content-type: application/json
authentication:
basic:
user: user
password: password
payload: original
onMessageReceived:
assertions:
- name: Status Code
expect: statusCode
toBeEqualTo: 333
- name: Body
expect: body
toBeEqualTo: `responsePayload`
- expect: statusCode
toBeEqualTo: 400
- expect: body
toBeEqualTo: `original -> proxy -> real -> proxied again`
subscriptions:
- name: proxy server
- name: proxy
type: http-proxy
endpoint: /proxy/:id
endpoint: /proxy
port: 23085
method: PATCH
redirect: http://localhost:23086
authentication:
basic:
user: user
password: password
redirect:
url: http://localhost:23086/real
method: POST
onOriginalMessageReceived:
script: this.redirect.payload = body + ` -> proxy`;
assertions:
- expect: body
toBeEqualTo: `original`
onMessageReceived:
script: this.response.payload = body + ` -> proxied again`; this.response.status = 2 * statusCode;
assertions:
- name: Payload
expect: JSON.parse(message.body).proxy
toBeEqualTo: `test`
- name: Params
expect: params.id
toBeEqualTo: `idValue`
- name: Query
expect: query.query
toBeEqualTo: `proxied`
- name: real server
- expect: body
toBeEqualTo: `original -> proxy -> real`
- expect: statusCode
toBeEqualTo: 200
- name: real
type: http
endpoint: /proxy/:firstId
endpoint: /real/enqueuer/:id
port: 23086
method: PATCH
timeout: 2000
authentication:
basic:
user: user
password: password
method: POST
response:
status: 333
payload: responsePayload
status: 200
onMessageReceived:
script: this.response.payload = body + ' -> real';
assertions:
- name: Payload
expect: JSON.parse(message.body).proxy
toBeEqualTo: `test`
- name: Params
expect: params.firstId
toBeEqualTo: `idValue`
- name: Query
expect: query.query
- expect: body
toBeEqualTo: `original -> proxy`
- expect: params.id
toBeEqualTo: 123456
- expect: query.query
toBeEqualTo: `proxied`

0 comments on commit c952f3b

Please sign in to comment.