Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss] Add unit tests for retries config #1751

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Our versioning strategy is as follows:
* `[templates/nextjs-sxa]` Fix feature `show Grid column` in Experience Editor. ([#1704](https://github.com/Sitecore/jss/pull/1704))
* `[sitecore-jss-nextjs] [templates/nextjs-xmcloud]` SDK initialization rejections are now correctly handled. Errors should no longer occur after getSDK() promises resolve when they shouldn't (for example, getting Events SDK in development environment) ([#1712](https://github.com/Sitecore/jss/pull/1712) [#1715](https://github.com/Sitecore/jss/pull/1715) [#1716](https://github.com/Sitecore/jss/pull/1716))
* `[sitecore-jss-nextjs]` Fix redirects middleware for working with absolute url where is using site language context ([#1727](https://github.com/Sitecore/jss/pull/1727)) ([#1737](https://github.com/Sitecore/jss/pull/1737))
* `[sitecore-jss]` Enable the Layout and dictionary service to use custom `retryStrategy`. ([#1749](https://github.com/Sitecore/jss/pull/1749))
* `[sitecore-jss]` Enable the Layout and dictionary service to use custom `retryStrategy`. ([#1749](https://github.com/Sitecore/jss/pull/1749)) ([#1751](https://github.com/Sitecore/jss/pull/1751))

### 🛠 Breaking Changes

Expand Down
31 changes: 30 additions & 1 deletion packages/sitecore-jss/src/graphql-request-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { expect, use, spy } from 'chai';
import sinon from 'sinon';
import spies from 'chai-spies';
import nock from 'nock';
import { GraphQLRequestClient, DefaultRetryStrategy } from './graphql-request-client';
import {
GraphQLRequestClient,
DefaultRetryStrategy,
GraphQLRequestClientConfig,
} from './graphql-request-client';
import { ClientError } from 'graphql-request';
import debugApi from 'debug';
import debug from './debug';
Expand Down Expand Up @@ -169,6 +173,31 @@ describe('GraphQLRequestClient', () => {
});

describe('Working with retryer', () => {
it('should use the clientConfig values configured by the client', () => {
addy-pathania marked this conversation as resolved.
Show resolved Hide resolved
const clientConfig: GraphQLRequestClientConfig = {
retries: 4,
retryStrategy: {
getDelay: () => 1000,
shouldRetry: () => true,
},
};

const graphQLClient = new GraphQLRequestClient(endpoint, clientConfig);

expect(graphQLClient['retries']).to.equal(clientConfig.retries);
expect(graphQLClient['retryStrategy']).to.deep.equal(clientConfig.retryStrategy);
});

it('should fallback to use default values when clientConfig is undefined', () => {
const clientConfig = { retries: undefined, retryStrategy: undefined };
const graphQLClient = new GraphQLRequestClient(endpoint, clientConfig);

expect(graphQLClient['retries']).to.equal(0);
expect(graphQLClient['retryStrategy']).to.deep.equal(
new DefaultRetryStrategy({ statusCodes: [429, 502, 503, 504, 520, 521, 522, 523, 524] })
);
});

it('should use retry and throw error when retries specified', async function() {
this.timeout(8000);
nock('http://jssnextweb')
Expand Down