- describe('Axios Configurations', function () {
- let requestUrl, expectedUrl;
- beforeEach(function () {
- requestUrl = 'https://example.com/client_id';
- expectedUrl = 'https://example.com/client_id';
- });
- it('_axiosConfig', function () {
- const method = 'GET';
- const contentType = 'text/plain';
- const body = undefined;
- const params = {
- 'extra_parameter': 'foobar',
- };
- const urlObj = new URL(requestUrl);
- const expectedUrlObj = new URL(`${requestUrl}?extra_parameter=foobar`);
- const expected = {
- method,
- url: 'https://example.com/client_id',
- headers: {
- 'Content-Type': 'text/plain',
- },
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._axiosConfig(method, urlObj, body, params, {
- 'Content-Type': contentType,
- });
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('_axiosConfig covers defaults', function () {
- const method = 'OPTIONS';
- const urlObj = new URL(requestUrl);
- const expectedUrlObj = new URL(requestUrl);
- const expected = {
- method,
- url: expectedUrl,
- headers: {},
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._axiosConfig(method, urlObj);
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('covers data', function () {
- const method = 'POST';
- const body = Buffer.from('some data');
- const params = {};
- const urlObj = new URL(requestUrl);
- const expected = {
- method,
- url: 'https://example.com/client_id',
- data: body,
- headers: {},
- params: urlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._axiosConfig(method, urlObj, body, params, {});
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
-
- });
- it('covers null response transform', function () {
- const urlObj = new URL(requestUrl);
- const result = Communication._axiosConfig('GET', urlObj, undefined, {}, {});
- result.transformResponse[0]();
- });
- }); // Axios Configurations
-