Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Rıza Kat committed Oct 15, 2024
1 parent e3fa2ba commit fdb8b62
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 531 deletions.
14 changes: 8 additions & 6 deletions test/helpers/helper_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const DIR_Bulk_request = (`${dir}/bulk_data/__cly_req_queue.json`);

// Custom
const DIR_Test = (`${dir_test}/customStorageDirectory`);
const DIR_Test_event = (`${dir_test}/customStorageDirectory/__cly_event.json`);
const DIR_Test_request = (`${dir_test}/customStorageDirectory/__cly_queue.json`);
const DIR_Test_bulk = (`${dir_test}/customStorageDirectory/__cly_bulk_queue.json`);
const DIR_Test_event = (`${dir_test}/customStorageDirectory/ __cly_bulk_event.json`);
const DIR_Test_request = (`${dir_test}/customStorageDirectory/__cly_req_queue.json`);
const DIR_Test_bulk_event = (`${dir_test}/customStorageDirectory/__cly_bulk_event.json`);
const DIR_Test_bulk_request = (`${dir_test}/customStorageDirectory/__cly_req_queue.json`);

// timeout variables
const sWait = 50;
Expand All @@ -48,10 +50,10 @@ function readEventQueue(givenPath = null, isBulk = false) {
return a;
}
// parsing request queue
function readRequestQueue(givenPath = null, isBulk = false) {
function readRequestQueue(customPath = false, isBulk = false) {
var destination = DIR_CLY_request;
if (givenPath !== null) {
destination = givenPath;
if (customPath) {
destination = DIR_Test_request;
}
var a = JSON.parse(fs.readFileSync(destination, "utf-8")).cly_queue;
if (isBulk) {
Expand All @@ -66,7 +68,7 @@ function doesFileStoragePathsExist(callback, isBulk = false, testPath = false) {
paths = [DIR_Bulk_request, DIR_Bulk_event, DIR_Bulk_bulk];
}
else if (testPath) {
paths = [DIR_Test_bulk, DIR_Test_event, DIR_Test_request];
paths = [DIR_Test_bulk, DIR_Test_bulk_event, DIR_Test_bulk_request];
}

let errors = 0;
Expand Down
38 changes: 38 additions & 0 deletions test/helpers/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ var userDetailObj = {
},
};

const invalidStorageMethods = {
_storage: {},
setInvalid: function() {
},
getInvalid: function() {
},
removeInvalid: function() {
},
};

const customStorage = {
_storage: {},
storeSet: function(key, value, callback) {
if (key) {
this._storage[key] = value;
if (typeof callback === "function") {
callback(null);
}
}
},
storeGet: function(key, def) {
return typeof this._storage[key] !== "undefined" ? this._storage[key] : def;
},
storeRemove: function(key) {
delete this._storage[key];
},
};

function getInvalidStorage() {
return invalidStorageMethods;
}

function getCustomStorage() {
return customStorage;
}

var getUserDetailsObj = function() {
return userDetailObj;
};
Expand All @@ -57,4 +93,6 @@ module.exports = {
getEventObj,
getUserDetailsObj,
getTimedEventObj,
getInvalidStorage,
getCustomStorage,
};
Loading

0 comments on commit fdb8b62

Please sign in to comment.