-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove axios dependency (#1424)
- Loading branch information
1 parent
26a1b21
commit 1b43267
Showing
16 changed files
with
299 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class ResponseError extends Error { | ||
response: Response; | ||
|
||
constructor(params: { response: Response; message: string }) { | ||
super(params.message); | ||
this.response = params.response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { http, HttpResponse } from 'msw'; | ||
import { generateEndPointUrl, getRequest } from './api'; | ||
import { getGlobalConfigMock } from '../mocks/globalConfigMock'; | ||
import { setUnifiedConfig } from './util'; | ||
import { server } from '../mocks/server'; | ||
|
||
describe('generateEndPointUrl', () => { | ||
it('should return the correct endpoint URL', () => { | ||
const mockConfig = getGlobalConfigMock(); | ||
setUnifiedConfig({ | ||
...mockConfig, | ||
meta: { | ||
...mockConfig.meta, | ||
restRoot: 'testing_name', | ||
}, | ||
}); | ||
const name = 'testing_endpoint'; | ||
|
||
const result = generateEndPointUrl(name); | ||
|
||
expect(result).toMatchInlineSnapshot(`"testing_name_testing_endpoint"`); | ||
}); | ||
}); | ||
|
||
describe('getRequest', () => { | ||
beforeEach(() => { | ||
const mockConfig = getGlobalConfigMock(); | ||
setUnifiedConfig({ | ||
...mockConfig, | ||
meta: { | ||
...mockConfig.meta, | ||
restRoot: 'testing_name', | ||
}, | ||
}); | ||
server.use(http.get('*', () => HttpResponse.json({}, { status: 500 }))); | ||
}); | ||
it('should call callbackOnError if handleError is true', async () => { | ||
const callbackOnError = jest.fn(); | ||
|
||
await expect(() => | ||
getRequest({ | ||
endpointUrl: 'testing_endpoint', | ||
handleError: true, | ||
callbackOnError, | ||
}) | ||
).rejects.toThrow(); | ||
|
||
expect(callbackOnError).toHaveBeenCalled(); | ||
}); | ||
it('should not call callbackOnError if handleError is false', async () => { | ||
const callbackOnError = jest.fn(); | ||
|
||
await expect(() => | ||
getRequest({ | ||
endpointUrl: 'testing_endpoint', | ||
handleError: false, | ||
callbackOnError, | ||
}) | ||
).rejects.toThrow(); | ||
|
||
expect(callbackOnError).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.