Skip to content

Commit

Permalink
feat(serviceConfig): sw-2024 allow response polling (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Feb 19, 2024
1 parent 50d11ad commit dce14d6
Show file tree
Hide file tree
Showing 6 changed files with 631 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ REACT_APP_UI_WINDOW_ID=curiosity

REACT_APP_AJAX_TIMEOUT=60000
REACT_APP_AJAX_CACHE=15000
REACT_APP_AJAX_POLL_INTERVAL=15000
REACT_APP_SELECTOR_CACHE=120000

REACT_APP_CONFIG_SERVICE_LOCALES_COOKIE=rh_locale
Expand Down
11 changes: 11 additions & 0 deletions src/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Axios config for cancelling, caching, and emulated service calls.

* [ServiceConfig](#Helpers.module_ServiceConfig)
* [~globalXhrTimeout](#Helpers.module_ServiceConfig..globalXhrTimeout) : <code>number</code>
* [~globalPollInterval](#Helpers.module_ServiceConfig..globalPollInterval) : <code>number</code>
* [~globalCancelTokens](#Helpers.module_ServiceConfig..globalCancelTokens) : <code>object</code>
* [~globalResponseCache](#Helpers.module_ServiceConfig..globalResponseCache) : <code>object</code>
* [~axiosServiceCall(config, options)](#Helpers.module_ServiceConfig..axiosServiceCall) ⇒ <code>Promise.&lt;\*&gt;</code>
Expand All @@ -169,6 +170,12 @@ Axios config for cancelling, caching, and emulated service calls.
### ServiceConfig~globalXhrTimeout : <code>number</code>
Set Axios XHR default timeout.

**Kind**: inner constant of [<code>ServiceConfig</code>](#Helpers.module_ServiceConfig)
<a name="Helpers.module_ServiceConfig..globalPollInterval"></a>

### ServiceConfig~globalPollInterval : <code>number</code>
Set Axios polling default.

**Kind**: inner constant of [<code>ServiceConfig</code>](#Helpers.module_ServiceConfig)
<a name="Helpers.module_ServiceConfig..globalCancelTokens"></a>

Expand Down Expand Up @@ -211,6 +218,8 @@ page or wait the "maxAge".
</tr><tr>
<td>config.params</td><td><code>object</code></td>
</tr><tr>
<td>config.poll</td><td><code>Object</code> | <code>function</code></td>
</tr><tr>
<td>config.schema</td><td><code>Array</code></td>
</tr><tr>
<td>config.transform</td><td><code>Array</code></td>
Expand All @@ -224,6 +233,8 @@ page or wait the "maxAge".
<td>options.responseCache</td><td><code>object</code></td>
</tr><tr>
<td>options.xhrTimeout</td><td><code>number</code></td>
</tr><tr>
<td>options.pollInterval</td><td><code>number</code></td>
</tr> </tbody>
</table>

Expand Down
235 changes: 235 additions & 0 deletions src/services/common/__tests__/__snapshots__/serviceConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,240 @@ exports[`ServiceConfig should handle cancelling service calls: cancelled request
]
`;

exports[`ServiceConfig should handle polling service call errors: location error 1`] = `
[
[
[Error: location string error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status error 1`] = `
[
[
[Error: status error],
],
[
[Error: status error],
],
[
[Error: status error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status error polling 1`] = `
{
"status": [
{
"count": 0,
"error": {
"data": "error",
"pollConfig": {
"__retryCount": 1,
"location": "/pollError",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
"success": undefined,
},
],
}
`;

exports[`ServiceConfig should handle polling service call errors: status of a status error 1`] = `
[
[
[Error: status error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status of a status error polling 1`] = `
{
"status": [
{
"count": 0,
"error": {
"data": "error",
"pollConfig": {
"__retryCount": 1,
"location": "/pollError",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
"success": undefined,
},
],
}
`;

exports[`ServiceConfig should handle polling service call errors: validation error 1`] = `
[
[
[Error: basic validation error],
],
]
`;

exports[`ServiceConfig should handle polling service calls: basic polling validator 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"success": {
"data": "success",
"pollConfig": [Function],
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
},
],
}
`;

exports[`ServiceConfig should handle polling service calls: custom location 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"__retryCount": 2,
"location": [Function],
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"location": [Function],
"validate": [Function],
},
"url": "/test/",
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": [Function],
"pollInterval": 1,
"validate": [Function],
},
"url": "/pollSuccess/",
},
},
],
}
`;

exports[`ServiceConfig should handle polling service calls: specific polling validator 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"validate": [Function],
},
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
},
],
}
`;

exports[`ServiceConfig should handle polling service calls: status polling 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"status": [Function],
"validate": [Function],
},
},
"status": [
{
"count": 0,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
},
{
"count": 1,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 2,
"location": "/test/",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
},
],
}
`;

exports[`ServiceConfig should handle producing a service call configuration: response configs 1`] = `
[
"{
Expand Down Expand Up @@ -377,6 +611,7 @@ exports[`ServiceConfig should have specific properties and methods: specific pro
[
"axiosServiceCall",
"globalXhrTimeout",
"globalPollInterval",
"globalCancelTokens",
"globalResponseCache",
]
Expand Down
Loading

0 comments on commit dce14d6

Please sign in to comment.