Swift Search to Master (#405)

* SEARCH-627 & SEARCH-628

- Add implementation for memory indexing
- Batch indexing and Real-time indexing

* ELECTRON-426 (#345)

- Changes innerHTML to innerText
- Removes 'replaceStrongTag' and 'replaceHTMLTags' function and changing to innerHTML to innerText

* SEARCH-764

- Rework "deleteIndexFolders" in the Electron Preload Script
- Fixes the Security Vulnerability

* SEARCH-764

- Updates spectron test preload api version

* SEARCH-766

- Rework "readFile" in Electron Preload Script
- Removing this method as this is only for the demo app

* SEARCH-766

- Removes merge method

* SEARCH-767

- Rework "path" in Electron Preload Script
- Removes the constructor to use hardcoded path

* SEARCH-767

- Updates unit test

* SEARCH-775

- Adds search api version to match with the client app

* SEARCH-775

- Spectron test fix

* SEARCH-770 (#391)

- constructor is required which was removed as part of SEARCH-767
This commit is contained in:
Keerthi Niranjan
2018-06-27 14:12:16 +05:30
committed by Vishwas Shashidhar
parent 65c304766f
commit 4aaa9ac539
10 changed files with 210 additions and 209 deletions

View File

@@ -7,6 +7,7 @@ let userConfigDir = null;
let searchConfig;
let SearchApi;
let libSymphonySearch;
jest.mock('electron', function() {
return {
@@ -37,9 +38,6 @@ describe('Tests for Search', function() {
let userId;
let key;
let dataFolderPath;
let realTimeIndexPath;
let tempBatchPath;
let launchAgent;
let currentDate = new Date().getTime();
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
@@ -48,28 +46,32 @@ describe('Tests for Search', function() {
userId = 12345678910112;
key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd=';
executionPath = path.join(__dirname, 'library');
if (isWindowsOS) {
executionPath = path.join(__dirname, '..', 'library');
}
userConfigDir = path.join(__dirname, '..');
executionPath = path.join(__dirname, 'library');
if (isWindowsOS) {
executionPath = path.join(__dirname, '..', 'library');
}
userConfigDir = path.join(__dirname, '..');
libSymphonySearch = require('../js/search/searchLibrary.js');
searchConfig = require('../js/search/searchConfig.js');
let root = path.join(userConfigDir, `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}.enc`);
if (fs.existsSync(root)) {
fs.unlinkSync(root);
}
const { Search } = require('../js/search/search.js');
SearchApi = new Search(userId, key);
searchConfig = require('../js/search/searchConfig.js');
const { Search } = require('../js/search/search.js');
SearchApi = new Search(userId, key);
launchAgent = require('../js/search/utils/search-launchd.js');
realTimeIndexPath = path.join(userConfigDir, 'data', 'temp_realtime_index');
tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes');
dataFolderPath = path.join(userConfigDir, 'data');
if (fs.existsSync(dataFolderPath)) {
deleteIndexFolders(dataFolderPath);
}
done();
libSymphonySearch.symSEDestroy();
dataFolderPath = path.join(userConfigDir, 'data');
if (fs.existsSync(dataFolderPath)) {
deleteIndexFolders(dataFolderPath)
}
done();
});
afterAll(function (done) {
setTimeout(function () {
libSymphonySearch.symSEDestroy();
deleteIndexFolders(dataFolderPath);
let root = path.join(userConfigDir, `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}.enc`);
if (fs.existsSync(root)) {
@@ -83,12 +85,15 @@ describe('Tests for Search', function() {
}, 3000);
});
function deleteIndexFolders(location) {
function deleteIndexFolders(location, isEncryption) {
if (!isEncryption) {
libSymphonySearch.symSEDestroy();
}
if (fs.existsSync(location)) {
fs.readdirSync(location).forEach(function(file) {
let curPath = path.join(location, file);
if (fs.lstatSync(curPath).isDirectory()) {
deleteIndexFolders(curPath);
deleteIndexFolders(curPath, true);
} else {
fs.unlinkSync(curPath);
}
@@ -123,13 +128,9 @@ describe('Tests for Search', function() {
});
it('should exist index folder', function() {
expect(fs.existsSync(path.join(userConfigDir, 'data', 'search_index_12345678910112'))).toBe(true);
expect(fs.existsSync(realTimeIndexPath)).toBe(true);
expect(fs.existsSync(path.join(userConfigDir, 'data', 'search_index_12345678910112'))).toBe(false);
});
it('should not exist index folder', function() {
expect(fs.existsSync(tempBatchPath)).toBe(false);
});
});
describe('Batch indexing process tests', function () {
@@ -165,7 +166,6 @@ describe('Tests for Search', function() {
}];
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
SearchApi.indexBatch(JSON.stringify(messages)).then(function () {
expect(fs.existsSync(tempBatchPath)).toBe(true);
expect(indexBatch).toHaveBeenCalledWith(JSON.stringify(messages));
done();
});
@@ -232,28 +232,22 @@ describe('Tests for Search', function() {
it('should match messages length after batch indexing', function (done) {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('it works', [], [], '', undefined, undefined, 25, 0, 0).then(function (res) {
expect(res.messages.length).toEqual(0);
expect(res.messages.length).toEqual(3);
expect(searchQuery).toHaveBeenCalled();
done()
});
});
it('should merge batch index to user index', function (done) {
const mergeIndexBatches = jest.spyOn(SearchApi, 'mergeIndexBatches');
SearchApi.mergeIndexBatches().then(function () {
expect(fs.existsSync(tempBatchPath)).toBe(false);
expect(mergeIndexBatches).toHaveBeenCalled();
const memoryIndexToFSIndex = jest.spyOn(SearchApi, 'memoryIndexToFSIndex');
SearchApi.memoryIndexToFSIndex().then(function () {
expect(memoryIndexToFSIndex).toHaveBeenCalled();
done();
});
});
it('should match messages length after batch indexing', function (done) {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('it works', [], [], '', undefined, undefined, 25, 0, 0).then(function (res) {
expect(res.messages.length).toEqual(3);
expect(searchQuery).toHaveBeenCalled();
done();
});
it('should exist data folder after ram index to fs index', function () {
expect(fs.existsSync(dataFolderPath)).toBe(true);
});
});
@@ -280,7 +274,6 @@ describe('Tests for Search', function() {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('realtime working', ["71811853189212"], ["Au8O2xKHyX1LtE6zW019GX///rZYegAtdA=="], '', undefined, undefined, 25, 0, 0).then(function (res) {
expect(res.messages.length).toEqual(3);
expect(fs.existsSync(realTimeIndexPath)).toBe(true);
expect(searchQuery).toHaveBeenCalled();
done();
})
@@ -309,8 +302,6 @@ describe('Tests for Search', function() {
SearchApi.searchQuery('isRealTimeIndexing', [], [], '', undefined, undefined, 25, 0, 0).then(function (res) {
expect(res.messages.length).toEqual(0);
expect(fs.existsSync(realTimeIndexPath)).toBe(true);
done();
});
}, 6000)
@@ -378,7 +369,6 @@ describe('Tests for Search', function() {
it('should delete realtime index', function () {
const deleteRealTimeFolder = jest.spyOn(SearchApi, 'deleteRealTimeFolder');
SearchApi.deleteRealTimeFolder();
expect(fs.existsSync(realTimeIndexPath)).toBe(true);
expect(deleteRealTimeFolder).toHaveBeenCalled();
});
});
@@ -425,13 +415,14 @@ describe('Tests for Search', function() {
});
});
it('should not get the latest timestamp', function (done) {
it('should be equal to 0000000000000', function (done) {
const getLatestMessageTimestamp = jest.spyOn(SearchApi, 'getLatestMessageTimestamp');
deleteIndexFolders(dataFolderPath);
SearchApi.getLatestMessageTimestamp().catch(function (err) {
expect(err).toEqual(new Error('Index folder does not exist.'));
libSymphonySearch.symSEClearMainRAMIndex();
libSymphonySearch.symSEClearRealtimeRAMIndex();
SearchApi.getLatestMessageTimestamp().then(function (res) {
expect(getLatestMessageTimestamp).toHaveBeenCalled();
expect(getLatestMessageTimestamp).toHaveBeenCalledTimes(3);
expect(res).toEqual('0000000000000');
done();
});
});
@@ -479,26 +470,25 @@ describe('Tests for Search', function() {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('works', [], [], '', '', '', 2, 0, 0).then(function (res) {
expect(res.messages.length).toBe(2);
expect(searchQuery).toHaveBeenCalledTimes(7);
expect(searchQuery).toHaveBeenCalledTimes(6);
expect(searchQuery).toHaveBeenCalled();
done();
});
});
it('should search fails index folder not fund', function (done) {
deleteIndexFolders(dataFolderPath);
setTimeout(function () {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('it works', [], [], '', '', '', 25, 0, 0).catch(function (err) {
expect(err).toEqual(new Error('Index folder does not exist.'));
expect(searchQuery).toHaveBeenCalledTimes(8);
expect(searchQuery).toHaveBeenCalled();
SearchApi = undefined;
const { Search } = require('../js/search/search.js');
SearchApi = new Search(userId, key);
done();
})
}, 3000);
it('should search fails result cleared', function (done) {
libSymphonySearch.symSEClearMainRAMIndex();
libSymphonySearch.symSEClearRealtimeRAMIndex();
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('it works', [], [], '', '', '', 25, 0, 0).then(function (res) {
expect(res.messages.length).toBe(0);
expect(searchQuery).toHaveBeenCalledTimes(7);
expect(searchQuery).toHaveBeenCalled();
SearchApi = undefined;
const { Search } = require('../js/search/search.js');
SearchApi = new Search(userId, key);
done();
});
});
it('should search fails query is undefined', function (done) {
@@ -531,5 +521,52 @@ describe('Tests for Search', function() {
done();
});
});
it('should index for testing quote', function (done) {
let messages = [{
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
ingestionDate: currentDate.toString(),
senderId: "71811853189212",
chatType: "CHATROOM",
isPublic: "false",
sendingApp: "lc",
text: "quote search"
}, {
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
ingestionDate: currentDate.toString(),
senderId: "71811853189212",
chatType: "CHATROOM",
isPublic: "false",
sendingApp: "lc",
text: "search"
}];
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
SearchApi.indexBatch(JSON.stringify(messages)).then(function () {
expect(indexBatch).toHaveBeenCalledWith(JSON.stringify(messages));
done();
});
});
it('should search without quote', function (done) {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('search', [], [], undefined, '', '', 25, 0, 0).then(function (res) {
expect(res.messages.length).toEqual(2);
expect(searchQuery).toHaveBeenCalled();
expect(searchQuery).toHaveBeenCalledTimes(4);
done();
});
});
it('should quote search', function (done) {
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
SearchApi.searchQuery('\"quote search\"', [], [], undefined, '', '', 25, 0, 0).then(function (res) {
expect(res.messages.length).toEqual(1);
expect(searchQuery).toHaveBeenCalled();
expect(searchQuery).toHaveBeenCalledTimes(5);
done();
});
});
});
});

View File

@@ -65,14 +65,14 @@ describe('Tests for Search Utils', function() {
it('should return error', function (done) {
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
if (isMac) {
SearchUtilsAPI.path = undefined;
searchConfig.FOLDERS_CONSTANTS.USER_DATA_PATH = undefined;
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
expect(err).toEqual(new Error("Please provide path"));
expect(checkFreeSpace).toHaveBeenCalled();
done();
});
} else {
SearchUtilsAPI.path = undefined;
searchConfig.FOLDERS_CONSTANTS.USER_DATA_PATH = undefined;
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
expect(err).toBeTruthy();
expect(checkFreeSpace).toHaveBeenCalled();
@@ -85,7 +85,7 @@ describe('Tests for Search Utils', function() {
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
SearchUtilsAPI.path = './tp';
if (isWindowsOS) {
SearchUtilsAPI.path = 'A://test';
searchConfig.FOLDERS_CONSTANTS.USER_DATA_PATH = 'A://test';
searchConfig.LIBRARY_CONSTANTS.FREE_DISK_SPACE = path.join(__dirname, '..',
"node_modules/electron-utils/FreeDiskSpace/bin/Release/FreeDiskSpace.exe");
}

View File

@@ -4,6 +4,8 @@ const { buildNumber } = require('../../package');
const electronVersion = require('../../package').devDependencies.electron;
const bluebird = require('bluebird');
const SEARCH_API_VERSION = '2.0.0';
let app = new Application({});
describe('Tests for getVersionInfo API', () => {
@@ -56,14 +58,16 @@ describe('Tests for getVersionInfo API', () => {
'#api-version',
'#container-identifier',
'#container-ver',
'#build-number'
'#build-number',
'#search-api-ver'
]).mapSeries((string) => {
return app.client.getText(string)
}).then((values) => {
expect(values[ 0 ]).toBe('1.0.0');
expect(values[ 0 ]).toBe('2.0.0');
expect(values[ 1 ]).toBe('Electron');
expect(values[ 2 ]).toBe(electronVersion);
expect(values[ 3 ]).toBe(buildNumber);
expect(values[ 4 ]).toBe(SEARCH_API_VERSION);
done();
});
});