- })
- });
-
- describe('Axios Configurations', function () {
- let requestUrl, expectedUrl, topicUrl;
- beforeEach(function () {
- requestUrl = 'https://example.com/callback/?id=123';
- expectedUrl = 'https://example.com/callback/';
- topicUrl = 'http://example.com/blog/';
- });
- it('_axiosConfig', function () {
- const method = 'GET';
- const contentType = 'text/plain';
- const body = undefined;
- const params = {
- 'extra_parameter': 'foobar',
- };
- const expectedUrlObj = new URL('https://example.com/callback/?id=123&extra_parameter=foobar');
- const expected = {
- method,
- url: 'https://example.com/callback/',
- headers: {
- 'Content-Type': 'text/plain',
- },
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._axiosConfig(method, requestUrl, body, params, {
- 'Content-Type': contentType,
- });
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('_axiosConfig covers defaults', function () {
- const method = 'OPTIONS';
- const expectedUrlObj = new URL(requestUrl);
- const expected = {
- method,
- url: expectedUrl,
- headers: {},
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._axiosConfig(method, requestUrl);
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('covers null response transform', function () {
- const result = Communication._axiosConfig('GET', 'https://example.com/', undefined, {}, {});
- result.transformResponse[0]();
- });
- it('_intentVerifyAxiosConfig', function () {
- const mode = 'subscribe';
- const leaseSeconds = 864000;
- const challenge = 'abcxyz';
- const expectedUrlObj = new URL(`${requestUrl}&hub.mode=${mode}&hub.topic=${encodeURIComponent(topicUrl)}&hub.challenge=${challenge}&hub.lease_seconds=${leaseSeconds}`);
- const expected = {
- method: 'GET',
- url: expectedUrl,
- headers: {},
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._intentVerifyAxiosConfig(requestUrl, topicUrl, mode, leaseSeconds, challenge);
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('_intentDenyAxiosConfig', function () {
- const reason = 'something';
- const expectedUrlObj = new URL(`${requestUrl}&hub.mode=denied&hub.topic=${encodeURIComponent(topicUrl)}&hub.reason=${reason}`);
- const expected = {
- method: 'GET',
- url: expectedUrl,
- headers: {},
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._intentDenyAxiosConfig(requestUrl, topicUrl, reason);
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('_publisherValidationAxiosConfig', function () {
- const topic = {
- url: topicUrl,
- publisherValidationUrl: 'https://example.com/publisher/',
- };
- const verification = {
- callback: requestUrl,
- topic: topicUrl,
- };
- const expectedUrlObj = new URL(topic.publisherValidationUrl);
- const expected = {
- method: 'POST',
- url: topic.publisherValidationUrl,
- data: {
- callback: requestUrl,
- topic: topicUrl,
- },
- headers: {
- 'Content-Type': 'application/json',
- },
- params: expectedUrlObj.searchParams,
- responseType: 'text',
- };
- const result = Communication._publisherValidationAxiosConfig(topic, verification);
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);
- });
- it('_topicFetchAxiosConfig', function () {
- const topic = {
- url: topicUrl,
- contentType: 'text/plain',
- };
- const expectedUrlObj = new URL(topicUrl);
- const expected = {
- method: 'GET',
- url: topicUrl,
- params: expectedUrlObj.searchParams,
- headers: {
- Accept: 'text/plain, */*;q=0.9',
- },
- responseType: 'text',
- };
- const result = Communication._topicFetchAxiosConfig(topic);
- delete result.transformResponse;
- assert.deepStrictEqual(result, expected);