mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
SEARCH-569
- Updated indexVersion
This commit is contained in:
@@ -52,6 +52,7 @@ const searchConfig = {
|
||||
MINIMUM_DATE: '0000000000000',
|
||||
MAXIMUM_DATE: '9999999999999',
|
||||
SORT_BY_SCORE: 0,
|
||||
INDEX_VERSION: 'v1',
|
||||
BATCH_RANDOM_INDEX_PATH_LENGTH: 20,
|
||||
LIBRARY_CONSTANTS: libraryPaths,
|
||||
FOLDERS_CONSTANTS: folderPaths,
|
||||
|
||||
@@ -69,7 +69,7 @@ function readFile(userId, resolve, reject) {
|
||||
if (err) {
|
||||
return reject(new Error('Error reading the '))
|
||||
}
|
||||
let usersConfig = [];
|
||||
let usersConfig = {};
|
||||
try {
|
||||
usersConfig = JSON.parse(data);
|
||||
} catch (e) {
|
||||
@@ -115,12 +115,17 @@ function createUser(userId, oldConfig) {
|
||||
* @param data
|
||||
*/
|
||||
function createUserConfigFile(userId, data) {
|
||||
let userData = data;
|
||||
|
||||
if (userData && !userData.indexVersion) {
|
||||
userData.indexVersion = searchConfig.INDEX_VERSION;
|
||||
}
|
||||
|
||||
let createStream = fs.createWriteStream(searchConfig.FOLDERS_CONSTANTS.USER_CONFIG_FILE);
|
||||
if (data) {
|
||||
let jsonData;
|
||||
if (userData) {
|
||||
try {
|
||||
jsonData = JSON.stringify(data);
|
||||
createStream.write(`{"${userId}": ${jsonData}}`);
|
||||
userData = JSON.stringify(userData);
|
||||
createStream.write(`{"${userId}": ${userData}}`);
|
||||
} catch (e) {
|
||||
createStream.write(`{"${userId}": {}}`);
|
||||
}
|
||||
@@ -139,9 +144,15 @@ function createUserConfigFile(userId, data) {
|
||||
* @returns {*}
|
||||
*/
|
||||
function updateConfig(userId, data, resolve, reject) {
|
||||
let userData = data;
|
||||
|
||||
if (userData && !userData.indexVersion) {
|
||||
userData.indexVersion = searchConfig.INDEX_VERSION;
|
||||
}
|
||||
|
||||
let configPath = searchConfig.FOLDERS_CONSTANTS.USER_CONFIG_FILE;
|
||||
if (!fs.existsSync(configPath)) {
|
||||
createUserConfigFile(userId, data);
|
||||
createUserConfigFile(userId, userData);
|
||||
return reject(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ describe('Tests for Search', function() {
|
||||
realTimeIndexPath = path.join(userConfigDir, 'data', 'temp_realtime_index');
|
||||
tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes');
|
||||
dataFolderPath = path.join(userConfigDir, 'data');
|
||||
console.log(dataFolderPath);
|
||||
if (fs.existsSync(dataFolderPath)) {
|
||||
fs.unlinkSync(dataFolderPath)
|
||||
}
|
||||
@@ -70,7 +69,7 @@ describe('Tests for Search', function() {
|
||||
setTimeout(function () {
|
||||
|
||||
deleteIndexFolders(dataFolderPath);
|
||||
let root = path.join(searchConfig.FOLDERS_CONSTANTS.EXEC_PATH, '..', `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}.enc`);
|
||||
let root = path.join(userConfigDir, `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}.enc`);
|
||||
if (fs.existsSync(root)) {
|
||||
fs.unlinkSync(root);
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ describe('Tests for Search Utils', function() {
|
||||
language: 'en'
|
||||
};
|
||||
SearchUtilsAPI.updateUserConfig(1234567891011, data).then(function (res) {
|
||||
data.indexVersion = 'v1';
|
||||
expect(res).toEqual(data);
|
||||
done();
|
||||
})
|
||||
@@ -137,6 +138,7 @@ describe('Tests for Search Utils', function() {
|
||||
};
|
||||
SearchUtilsAPI.updateUserConfig(1234567891011, data).then(function (res) {
|
||||
expect(res.rotationId).toEqual(1);
|
||||
expect(res.indexVersion).toEqual('v1');
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user