Skip to content

Commit

Permalink
Refactoring Storage Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Rıza Kat committed Oct 7, 2024
1 parent 52827ce commit e9fcf8b
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 633 deletions.
1 change: 0 additions & 1 deletion lib/countly-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var cc = {
storageTypeEnums: {
FILE: "file",
MEMORY: "memory",
CUSTOM: "custom",
},

/**
Expand Down
9 changes: 7 additions & 2 deletions lib/countly-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var initStorage = function(userPath, storageType, isBulk = false, persistQueue =
if (storageType === StorageTypes.MEMORY) {
storageMethod = memoryStorage;
}
else if (storageType === StorageTypes.CUSTOM) {
else if (customStorageMethod) {
if (hasValidMethods(customStorageMethod)) {
storageMethod = customStorageMethod;
if (userPath) {
Expand Down Expand Up @@ -322,7 +322,12 @@ var getStorageType = function() {
if (storageMethod === memoryStorage) {
return StorageTypes.MEMORY;
}
return StorageTypes.FILE;

if (storageMethod === fileStorage) {
return StorageTypes.FILE;
}

return null;
};

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ Countly.Bulk = Bulk;

// device_id
Countly.device_id = undefined;
Countly.device_id_type = undefined;
Countly.remote_config = undefined;
Countly.require_consent = false;
Countly.debug = undefined;
Expand Down
17 changes: 12 additions & 5 deletions test/helpers/helper_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,30 @@ function clearStorage(keepID = false, isBulk = false, customDir = '') {
// Resets Countly
Countly.halt(true);
// Determine the directory based on isBulk or customDir
const eventDirectory = customDir || (isBulk ? bulkEventDir : eventDir);
const reqDirectory = customDir || (isBulk ? bulkQueueDir : reqDir);
// Helper function to remove directory and files
const eventDirectory = isBulk ? bulkEventDir : eventDir;
const reqDirectory = isBulk ? bulkQueueDir : reqDir;
function removeDir(directory) {
if (fs.existsSync(directory)) {
fs.rmSync(directory, { recursive: true, force: true });
// Remove the .json extension from the directory name, since it will be added in path.resolve
var filePath = path.resolve(__dirname, `${directory}`);
if (fs.existsSync(filePath)) {
fs.rmSync(filePath, { recursive: true, force: true });
}
}
// Remove event directory if it exists
removeDir(eventDirectory);
// Remove request directory if it exists
removeDir(reqDirectory);
if (customDir) {
removeDir(customDir);
}
// Optionally keep the ID directory
if (!keepID) {
removeDir(idDir);
removeDir(idTypeDir);
}
return new Promise((resolve, reject) => {
resolve("string");
});
}
/**
* bunch of tests specifically gathered for testing events
Expand Down
Loading

0 comments on commit e9fcf8b

Please sign in to comment.