Skip to content

Commit 2ca5269

Browse files
authored
test: Httpbin calls replaced with jsonplaceholder to prevent test cases from timing out (#484)
1 parent f2c8277 commit 2ca5269

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/auth/AxiosJwtAuthService.test.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Object.keys(jwtTokens).forEach((jwtTokenName) => {
7878
const mockCsrfToken = 'thetokenvalue';
7979
const mockApiEndpointPath = `${process.env.BASE_URL}/api/v1/test`;
8080

81-
global.location = { ...global.location, assign: jest.fn() };
81+
global.location ??= { ...global.location, assign: jest.fn() };
8282

8383
const mockCookies = new Cookies();
8484

@@ -885,17 +885,16 @@ describe('fetchAuthenticatedUser', () => {
885885

886886
// These tests all make real network calls to http://httpbin.org.
887887
describe('Cache Functionality', () => {
888-
const getUrl = 'http://httpbin.org/get';
889-
const postUrl = 'http://httpbin.org/post';
890-
const requestId = 'get-httpbin';
888+
const getUrl = 'https://jsonplaceholder.typicode.com/posts/1';
889+
const postUrl = 'https://jsonplaceholder.typicode.com/posts';
890+
const requestId = 'get-jsonplaceholder-posts';
891891

892892
const getWithRequestId = async (config = {}) => cachedClient.get(getUrl, {
893893
id: requestId,
894894
...config,
895895
});
896896

897897
const postWithRequestId = async (config = {}) => cachedClient.post(postUrl, {
898-
id: requestId,
899898
...config,
900899
});
901900

@@ -1001,15 +1000,15 @@ describe('Cache Functionality', () => {
10011000
});
10021001

10031002
it('GET request: refreshes the jwt token', async () => {
1004-
const response = await cachedClient.get('https://httpbin.org/get');
1003+
const response = await cachedClient.get(getUrl);
10051004
expectSingleCallToJwtTokenRefresh();
10061005
expectNoCallToCsrfTokenFetch();
10071006
expectRequestToHaveJwtAuth(response.config);
10081007
});
10091008

10101009
['post', 'put', 'patch', 'delete'].forEach((method) => {
10111010
it(`${method.toUpperCase()}: refreshes the csrf and jwt tokens`, async () => {
1012-
const response = await cachedClient[method](`https://httpbin.org/${method}`);
1011+
const response = await cachedClient[method](method === 'post' ? postUrl : getUrl);
10131012
expectSingleCallToJwtTokenRefresh();
10141013
expectSingleCallToCsrfTokenFetch();
10151014
expectRequestToHaveJwtAuth(response.config);
@@ -1035,7 +1034,7 @@ describe('Cache Functionality', () => {
10351034
['post', 'put', 'patch', 'delete'].forEach((method) => {
10361035
it(`${method.toUpperCase()}: refreshes the csrf token but does not attempt to refresh the jwt token`, async () => {
10371036
setJwtCookieTo(jwtTokens.valid.encoded);
1038-
const response = await cachedClient[method](`https://httpbin.org/${method}`, {
1037+
const response = await cachedClient[method](method === 'post' ? postUrl : getUrl, {
10391038
id: requestId,
10401039
});
10411040
expectNoCallToJwtTokenRefresh();
@@ -1057,7 +1056,7 @@ describe('Cache Functionality', () => {
10571056
it(`${method.toUpperCase()}: throws an error and calls logError`, async () => {
10581057
expect.hasAssertions();
10591058
try {
1060-
await cachedClient[method](`https://httpbin.org/${method}`, {
1059+
await cachedClient[method](getUrl, {
10611060
id: requestId,
10621061
});
10631062
} catch (err) {

0 commit comments

Comments
 (0)