Skip to content

Commit

Permalink
refactor(serviceConfig): sw-2353 start poll retryCount earlier (#1343)
Browse files Browse the repository at this point in the history
* retryCount starts earlier, allow additional status callback firing
* allow poll location urls to also include service call configs
  • Loading branch information
cdcabrera committed Jul 16, 2024
1 parent 6fc1082 commit f7eb1a9
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 43 deletions.
146 changes: 133 additions & 13 deletions src/services/common/__tests__/__snapshots__/serviceConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ exports[`ServiceConfig should handle polling service call errors: location error
[
[Error: location string error],
],
[
[Error: location string error],
],
]
`;

Expand All @@ -338,19 +341,36 @@ 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": -1,
"error": {
"data": undefined,
"pollConfig": undefined,
},
"success": undefined,
},
{
"count": 0,
"error": {
"data": "error",
"pollConfig": {
"__retryCount": 1,
"location": "/pollError",
"__retryCount": 0,
"location": {
"config": undefined,
"url": "/pollError",
},
"pollInterval": 1,
"status": [Function],
"validate": [Function],
Expand All @@ -367,19 +387,33 @@ exports[`ServiceConfig should handle polling service call errors: status of a st
[
[Error: status error],
],
[
[Error: status error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status of a status error polling 1`] = `
{
"status": [
{
"count": -1,
"error": {
"data": undefined,
"pollConfig": undefined,
},
"success": undefined,
},
{
"count": 0,
"error": {
"data": "error",
"pollConfig": {
"__retryCount": 1,
"location": "/pollError",
"__retryCount": 0,
"location": {
"config": undefined,
"url": "/pollError",
},
"pollInterval": 1,
"status": [Function],
"validate": [Function],
Expand All @@ -405,26 +439,47 @@ exports[`ServiceConfig should handle polling service calls: basic polling valida
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"count": -1,
"success": {
"data": "success",
"pollConfig": [Function],
},
},
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 0,
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"validate": [Function],
},
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"validate": [Function],
},
Expand All @@ -447,7 +502,7 @@ exports[`ServiceConfig should handle polling service calls: custom location 1`]
},
"validator": [
{
"count": 0,
"count": -1,
"success": {
"data": "success",
"pollConfig": {
Expand All @@ -457,6 +512,19 @@ exports[`ServiceConfig should handle polling service calls: custom location 1`]
"url": "/test/",
},
},
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 0,
"location": [Function],
"pollInterval": 1,
"validate": [Function],
},
"url": "/pollSuccess/",
},
},
{
"count": 1,
"success": {
Expand All @@ -480,17 +548,35 @@ exports[`ServiceConfig should handle polling service calls: specific polling val
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": -1,
"success": {
"data": "success",
"pollConfig": {
"validate": [Function],
},
},
},
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 0,
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"validate": [Function],
},
},
Expand All @@ -501,7 +587,10 @@ exports[`ServiceConfig should handle polling service calls: specific polling val
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"validate": [Function],
},
Expand All @@ -521,14 +610,25 @@ exports[`ServiceConfig should handle polling service calls: status polling 1`] =
},
},
"status": [
{
"count": -1,
"err": undefined,
"success": {
"data": undefined,
"pollConfig": undefined,
},
},
{
"count": 0,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"__retryCount": 0,
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"status": [Function],
"validate": [Function],
Expand All @@ -538,11 +638,31 @@ exports[`ServiceConfig should handle polling service calls: status polling 1`] =
{
"count": 1,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
},
{
"count": 2,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 2,
"location": "/test/",
"location": {
"config": undefined,
"url": "/test/",
},
"pollInterval": 1,
"status": [Function],
"validate": [Function],
Expand Down
24 changes: 12 additions & 12 deletions src/services/common/__tests__/serviceConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe('ServiceConfig', () => {
{ pollInterval: 1 }
);

expect(basicPollValidator).toHaveBeenCalledTimes(2);
expect(basicPollValidator).toHaveBeenCalledTimes(3);
expect({
validator: basicPollValidator.mock.calls.map(([response, count]) => ({
success: {
Expand Down Expand Up @@ -298,7 +298,7 @@ describe('ServiceConfig', () => {
{ pollInterval: 1 }
);

expect(specificPollValidator).toHaveBeenCalledTimes(2);
expect(specificPollValidator).toHaveBeenCalledTimes(3);
expect({
validator: specificPollValidator.mock.calls.map(([response, count]) => ({
success: {
Expand Down Expand Up @@ -333,12 +333,12 @@ describe('ServiceConfig', () => {
setTimeout(() => resolve(), 25);
});

expect(statusPoll).toHaveBeenCalledTimes(2);
expect(statusPoll).toHaveBeenCalledTimes(4);
expect({
status: statusPoll.mock.calls.map(([success, err, count]) => ({
success: {
data: success.data,
pollConfig: success.config.poll
data: success?.data,
pollConfig: success?.config.poll
},
err,
count
Expand All @@ -362,7 +362,7 @@ describe('ServiceConfig', () => {
{ pollInterval: 1 }
);

expect(mockLocation).toHaveBeenCalledTimes(2);
expect(mockLocation).toHaveBeenCalledTimes(3);
expect({
validator: mockLocation.mock.calls.map(([success, count]) => ({
success: {
Expand Down Expand Up @@ -438,12 +438,12 @@ describe('ServiceConfig', () => {
setTimeout(() => resolve(), 50);
});

expect(statusErrorPoll).toHaveBeenCalledTimes(1);
expect(statusErrorPoll).toHaveBeenCalledTimes(2);
expect({
status: statusErrorPoll.mock.calls.map(([success, err, count]) => ({
error: {
data: err.response.data,
pollConfig: err.config.poll
data: err?.response.data,
pollConfig: err?.config.poll
},
success,
count
Expand Down Expand Up @@ -494,12 +494,12 @@ describe('ServiceConfig', () => {
setTimeout(() => resolve(), 25);
});

expect(statusStatusErrorPoll).toHaveBeenCalledTimes(1);
expect(statusStatusErrorPoll).toHaveBeenCalledTimes(2);
expect({
status: statusStatusErrorPoll.mock.calls.map(([success, err, count]) => ({
error: {
data: err.response.data,
pollConfig: err.config.poll
data: err?.response.data,
pollConfig: err?.config.poll
},
success,
count
Expand Down
Loading

0 comments on commit f7eb1a9

Please sign in to comment.