Skip to content

Commit f62efb6

Browse files
author
Umit Coskun Aydinoglu
committed
eslint fixes + test moved to test folder
1 parent 3a1dc8c commit f62efb6

File tree

3 files changed

+80
-73
lines changed

3 files changed

+80
-73
lines changed

api/utils/countly-request/index.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ var convertOptionsToGot = function(options) {
5252
"uri": "url"
5353
};
5454

55-
// Helper function to assign value to nested keys
55+
/***
56+
* Assigns a value to a nested object property
57+
* @param {object} obj - The object to assign the value to
58+
* @param {string} keyPath - The path to the property to assign the value to
59+
* @param {*} value - The value to assign
60+
*/
5661
function assignDeep(obj, keyPath, value) {
5762
var keys = keyPath.split('.');
5863
var lastKey = keys.pop();
@@ -73,10 +78,12 @@ var convertOptionsToGot = function(options) {
7378
var mappedKey = keyMap[key];
7479
if (mappedKey.includes('.')) {
7580
assignDeep(requestOptions, mappedKey, options[key]);
76-
} else {
81+
}
82+
else {
7783
requestOptions[mappedKey] = options[key];
7884
}
79-
} else {
85+
}
86+
else {
8087
requestOptions[key] = options[key];
8188
}
8289
}

api/utils/countly-request/test/countly-request.test.js

-70
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var request = require('../index.js');
2+
var should = require('should');
3+
4+
describe('Countly Request', () => {
5+
6+
it('Make sure options converted correctly', () => {
7+
const optionsWithoutBaseURL = {
8+
"qs": "searchParams",
9+
"strictSSL": true,
10+
"gzip": true,
11+
"jar": "cookieJar",
12+
//"baseUrl": "prefixUrl",
13+
"uri": "url"
14+
};
15+
16+
const expectedOptionsWithoutBaseURL = {
17+
"searchParams": "searchParams",
18+
"https": {
19+
"rejectUnauthorized": true
20+
},
21+
"decompress": true,
22+
"cookieJar": "cookieJar",
23+
//"prefixUrl": "prefixUrl",
24+
"url": "url"
25+
};
26+
27+
const optionsWithBaseURL = {
28+
"qs": "searchParams",
29+
"strictSSL": true,
30+
"gzip": true,
31+
"jar": "cookieJar",
32+
"baseUrl": "prefixUrl",
33+
"uri": "url"
34+
};
35+
36+
const expetedOptionsWithBaseURL = {
37+
"searchParams": "searchParams",
38+
"https": {
39+
"rejectUnauthorized": true
40+
},
41+
"decompress": true,
42+
"cookieJar": "cookieJar",
43+
"prefixUrl": "prefixUrl",
44+
"uri": "url"
45+
};
46+
47+
48+
request.convertOptionsToGot(optionsWithoutBaseURL).should.be.eql(expectedOptionsWithoutBaseURL);
49+
request.convertOptionsToGot(optionsWithBaseURL).should.be.eql(expetedOptionsWithBaseURL);
50+
});
51+
52+
53+
it('Make get request', () => {
54+
request.get('https://count.ly', {strictSSL: true}, function(err, res/*, body*/) {
55+
should.not.exist(err);
56+
should.exist(res);
57+
58+
});
59+
60+
});
61+
62+
it('Make post request', () => {
63+
request.post('https://countly', function(err, res/*, body*/) {
64+
should.not.exist(err);
65+
should.exist(res);
66+
67+
});
68+
});
69+
70+
});

0 commit comments

Comments
 (0)