SEARCH-569

- Updated indexVersion
This commit is contained in:
Keerthi Niranjan
2018-01-12 17:31:59 +05:30
parent 27cab1ab93
commit 253aee2ac6
4 changed files with 21 additions and 8 deletions

View File

@@ -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,

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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();
})
});