Skip to content

Commit

Permalink
Merge branch 'master' into Cookiezaurs-patch-9
Browse files Browse the repository at this point in the history
  • Loading branch information
Cookiezaurs authored Aug 2, 2024
2 parents 0f3433f + 6a0a183 commit a5087b9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
12 changes: 6 additions & 6 deletions api/utils/countly-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ var convertOptionsToGot = function(options) {
module.exports = function(countlyConfig) {
// Return the request function
// eslint-disable-next-line require-jsdoc
function requestFunction(uri, options, callback) {
function requestFunction(uri, options, callback, config = countlyConfig) {
if (typeof uri === 'undefined') {
throw new Error('undefined is not a valid uri or options object.');
}

// Initialize params with the provided config
const params = initParams(uri, options, callback, countlyConfig);
const params = initParams(uri, options, callback, config);

// Request logic follows, unchanged from your provided code
if (params.options && (params.options.url || params.options.uri)) {
Expand All @@ -184,7 +184,7 @@ module.exports = function(countlyConfig) {
}

// eslint-disable-next-line require-jsdoc
function post(uri, options, callback, config) {
function post(uri, options, callback, config = countlyConfig) {
var params = initParams(uri, options, callback, config);
if (params.options && (params.options.url || params.options.uri)) {
if (params.options.form && params.options.form.fileStream && params.options.form.fileField) {
Expand Down Expand Up @@ -219,8 +219,8 @@ module.exports = function(countlyConfig) {
}


function get(uri, options, callback, config) {
module.exports(uri, options, callback, config);
function get(uri, options, callback, config = countlyConfig) {
requestFunction(uri, options, callback, config);
}

requestFunction.post = post;
Expand Down Expand Up @@ -259,4 +259,4 @@ async function uploadFormFile(url, fileData, callback) {



module.exports.convertOptionsToGot = convertOptionsToGot;
module.exports.convertOptionsToGot = convertOptionsToGot;
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
}
var payload = {};
var persistent = msg.persistent;
payload.text = msg.message;
payload.text = countlyCommon.encodeHtml(msg.message);
payload.autoHide = !msg.sticky;
payload.id = msg.id;
payload.width = msg.width;
Expand Down
26 changes: 26 additions & 0 deletions test/unit-tests/api.utils.countly-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var pluginManager = require('../../plugins/pluginManager');
var request = require('countly-request')(pluginManager.getConfig("security"));
var should = require('should');
const testUtils = require("../testUtils");

describe('Countly Request', () => {

Expand Down Expand Up @@ -61,6 +62,15 @@ describe('Countly Request', () => {

});

it('Makes get request', (done) => {
request.get(`${testUtils.url}/o/ping`, (err, res) => {
should.not.exist(err);
should.exist(res);

done();
});
});

it('Make post request', () => {
request.post('https://countly', function(err, res/*, body*/) {
should.not.exist(err);
Expand All @@ -69,4 +79,20 @@ describe('Countly Request', () => {
});
});

it('Makes post request', (done) => {
request.post({
url: `${testUtils.url}/i/configs`,
json: {
api_key: testUtils.get('API_KEY_ADMIN'),
app_key: testUtils.get('APP_KEY'),
configs: JSON.stringify({ frontend: { test: true } }),
},
}, (err, res) => {
should.not.exist(err);
should.exist(res);

done();
});
});

});

0 comments on commit a5087b9

Please sign in to comment.