Skip to content

Commit

Permalink
add unit tests for config values
Browse files Browse the repository at this point in the history
  • Loading branch information
addy-pathania committed Feb 29, 2024
1 parent 4a772de commit 3b65acf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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', () => {
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 = {};
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
2 changes: 1 addition & 1 deletion packages/sitecore-jss/src/layout/graphql-layout-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class GraphQLLayoutService extends LayoutServiceBase {
apiKey: this.serviceConfig.apiKey,
debugger: debug.layout,
retries: this.serviceConfig.retries,
retryStrategy: this.serviceConfig.retryStrategy,
// retryStrategy: this.serviceConfig.retryStrategy,
});
}

Expand Down

0 comments on commit 3b65acf

Please sign in to comment.