mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
SEARCH-840 Migrates SwiftSearch to a different project (#434)
* SEARCH-840 Migrates SwiftSearch to a different project https://github.com/symphonyoss/SwiftSearch * SEARCH-840 Changes swift-search require * SEARCH-840 refactor * SEARCH-840 Changes swift-search version * SEARCH-840 Changes warn message
This commit is contained in:
committed by
Vishwas Shashidhar
parent
08ca667c3c
commit
a71d8cb2c7
@@ -1,572 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { isWindowsOS } = require('../js/utils/misc.js');
|
||||
|
||||
let executionPath = null;
|
||||
let userConfigDir = null;
|
||||
|
||||
let searchConfig;
|
||||
let SearchApi;
|
||||
let libSymphonySearch;
|
||||
|
||||
jest.mock('electron', function() {
|
||||
return {
|
||||
app: {
|
||||
getPath: mockedGetPath,
|
||||
getName: mockedGetName
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function mockedGetName() {
|
||||
return 'Symphony';
|
||||
}
|
||||
|
||||
function mockedGetPath(type) {
|
||||
if (type === 'exe') {
|
||||
return executionPath;
|
||||
}
|
||||
|
||||
if (type === 'userData') {
|
||||
return userConfigDir
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
describe('Tests for Search', function() {
|
||||
|
||||
let userId;
|
||||
let key;
|
||||
let dataFolderPath;
|
||||
let currentDate = new Date().getTime();
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
||||
|
||||
beforeAll(function (done) {
|
||||
userId = 12345678910112;
|
||||
key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd=';
|
||||
|
||||
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);
|
||||
|
||||
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)) {
|
||||
fs.unlinkSync(root);
|
||||
}
|
||||
let script = `${searchConfig.FOLDERS_CONSTANTS.USER_DATA_PATH}/.symphony`;
|
||||
if (fs.existsSync(script)) {
|
||||
deleteIndexFolders(script);
|
||||
}
|
||||
done();
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
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, true);
|
||||
} else {
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(location);
|
||||
}
|
||||
}
|
||||
|
||||
describe('Search Initial checks', function() {
|
||||
|
||||
it('should be initialized', function (done) {
|
||||
setTimeout(function () {
|
||||
|
||||
expect(SearchApi.isInitialized).toBe(true);
|
||||
expect(SearchApi.messageData).toEqual([]);
|
||||
expect(SearchApi.isRealTimeIndexing).toBe(false);
|
||||
|
||||
done();
|
||||
}, 3000)
|
||||
});
|
||||
|
||||
it('should isLibInit to true', function () {
|
||||
let init = SearchApi.isLibInit();
|
||||
expect(init).toEqual(true);
|
||||
});
|
||||
|
||||
it('should isLibInit to false', function () {
|
||||
SearchApi.isInitialized = false;
|
||||
let init = SearchApi.isLibInit();
|
||||
expect(init).toEqual(false);
|
||||
SearchApi.isInitialized = true;
|
||||
});
|
||||
|
||||
it('should exist index folder', function() {
|
||||
expect(fs.existsSync(path.join(userConfigDir, 'data', 'search_index_12345678910112'))).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Batch indexing process tests', function () {
|
||||
|
||||
it('should index in a batch', function (done) {
|
||||
let messages = [{
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "it works"
|
||||
}, {
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "it works"
|
||||
}, {
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "it works"
|
||||
}];
|
||||
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
|
||||
SearchApi.indexBatch(JSON.stringify(messages)).then(function () {
|
||||
expect(indexBatch).toHaveBeenCalledWith(JSON.stringify(messages));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not batch index', function (done) {
|
||||
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
|
||||
SearchApi.indexBatch().catch(function (err) {
|
||||
expect(indexBatch).toHaveBeenCalled();
|
||||
expect(err).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not batch index invalid object', function (done) {
|
||||
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
|
||||
SearchApi.indexBatch('message').catch(function (err) {
|
||||
expect(err).toBeTruthy();
|
||||
expect(indexBatch).toHaveBeenCalledWith('message');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not batch index parse error', function (done) {
|
||||
let message = {
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "it works"
|
||||
};
|
||||
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
|
||||
SearchApi.indexBatch(JSON.stringify(message)).catch(function (err) {
|
||||
expect(err).toBeTruthy();
|
||||
expect(indexBatch).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not batch index isInitialized is false', function (done) {
|
||||
SearchApi.isInitialized = false;
|
||||
let message = [ {
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "it fails"
|
||||
} ];
|
||||
const indexBatch = jest.spyOn(SearchApi, 'indexBatch');
|
||||
SearchApi.indexBatch(JSON.stringify(message)).catch(function (err) {
|
||||
expect(err).toBeTruthy();
|
||||
expect(indexBatch).toHaveBeenCalledWith(JSON.stringify(message));
|
||||
SearchApi.isInitialized = true;
|
||||
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 merge batch index to user index', function (done) {
|
||||
const memoryIndexToFSIndex = jest.spyOn(SearchApi, 'memoryIndexToFSIndex');
|
||||
SearchApi.memoryIndexToFSIndex().then(function () {
|
||||
expect(memoryIndexToFSIndex).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should exist data folder after ram index to fs index', function () {
|
||||
expect(fs.existsSync(dataFolderPath)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('RealTime indexing process', function () {
|
||||
|
||||
it('should index realTime message', function () {
|
||||
let message = [{
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "realtime working"
|
||||
}];
|
||||
|
||||
const batchRealTimeIndexing = jest.spyOn(SearchApi, 'batchRealTimeIndexing');
|
||||
SearchApi.batchRealTimeIndexing(message);
|
||||
expect(batchRealTimeIndexing).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should match message length', function (done) {
|
||||
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(searchQuery).toHaveBeenCalled();
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it('should not index realTime message', function (done) {
|
||||
let message = [{
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "isRealTimeIndexing"
|
||||
}];
|
||||
|
||||
const batchRealTimeIndexing = jest.spyOn(SearchApi, 'batchRealTimeIndexing');
|
||||
const realTimeIndexing = jest.spyOn(SearchApi, 'realTimeIndexing');
|
||||
SearchApi.isRealTimeIndexing = true;
|
||||
expect(SearchApi.checkIsRealTimeIndexing()).toBe(true);
|
||||
SearchApi.batchRealTimeIndexing(message);
|
||||
expect(batchRealTimeIndexing).toHaveBeenCalled();
|
||||
expect(realTimeIndexing).not.toBeCalled();
|
||||
setTimeout(function () {
|
||||
|
||||
SearchApi.searchQuery('isRealTimeIndexing', [], [], '', undefined, undefined, 25, 0, 0).then(function (res) {
|
||||
expect(res.messages.length).toEqual(0);
|
||||
done();
|
||||
});
|
||||
}, 6000)
|
||||
});
|
||||
|
||||
it('should not call the real-time index', function () {
|
||||
let message = [{
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "isRealTimeIndexing"
|
||||
}];
|
||||
|
||||
const batchRealTimeIndexing = jest.spyOn(SearchApi, 'batchRealTimeIndexing');
|
||||
const realTimeIndexing = jest.spyOn(SearchApi, 'realTimeIndexing');
|
||||
SearchApi.isRealTimeIndexing = true;
|
||||
SearchApi.batchRealTimeIndexing(message);
|
||||
expect(batchRealTimeIndexing).toHaveBeenCalled();
|
||||
expect(realTimeIndexing).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should not realTime index invalid object', function () {
|
||||
let message = [{
|
||||
messageId: "Jc+4K8RtPxHJfyuDQU9atX///qN3KHYXdA==",
|
||||
threadId: "Au8O2xKHyX1LtE6zW019GX///rZYegAtdA==",
|
||||
ingestionDate: currentDate.toString(),
|
||||
senderId: "71811853189212",
|
||||
chatType: "CHATROOM",
|
||||
isPublic: "false",
|
||||
sendingApp: "lc",
|
||||
text: "isRealTimeIndexing"
|
||||
}];
|
||||
const realTimeIndexing = jest.spyOn(SearchApi, 'realTimeIndexing');
|
||||
expect(function () {
|
||||
SearchApi.realTimeIndexing('message')
|
||||
}).toThrow();
|
||||
|
||||
expect(function () {
|
||||
SearchApi.realTimeIndexing()
|
||||
}).toThrow();
|
||||
|
||||
SearchApi.isInitialized = false;
|
||||
expect(function () {
|
||||
SearchApi.realTimeIndexing(JSON.stringify(message))
|
||||
}).toThrow(new Error('Library not initialized'));
|
||||
SearchApi.isInitialized = true;
|
||||
expect(realTimeIndexing).toHaveBeenCalled();
|
||||
expect(realTimeIndexing).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it('should return realTime bool', function () {
|
||||
const checkIsRealTimeIndexing = jest.spyOn(SearchApi, 'checkIsRealTimeIndexing');
|
||||
SearchApi.isRealTimeIndexing = true;
|
||||
expect(SearchApi.checkIsRealTimeIndexing()).toBe(true);
|
||||
SearchApi.isRealTimeIndexing = false;
|
||||
expect(SearchApi.checkIsRealTimeIndexing()).toBe(false);
|
||||
expect(checkIsRealTimeIndexing).toHaveBeenCalled();
|
||||
expect(checkIsRealTimeIndexing).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should delete realtime index', function () {
|
||||
const deleteRealTimeFolder = jest.spyOn(SearchApi, 'deleteRealTimeFolder');
|
||||
SearchApi.deleteRealTimeFolder();
|
||||
expect(deleteRealTimeFolder).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test for encryption of the index', function () {
|
||||
|
||||
it('should encrypt user index', function (done) {
|
||||
const encryptIndex = jest.spyOn(SearchApi, 'encryptIndex');
|
||||
SearchApi.encryptIndex(key);
|
||||
expect(encryptIndex).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
|
||||
it('should exist encrypted file', function (done) {
|
||||
setTimeout(function () {
|
||||
|
||||
expect(fs.existsSync(path.join(userConfigDir, 'search_index_12345678910112.enc'))).toBe(true);
|
||||
expect(fs.existsSync(path.join(userConfigDir, 'search_index_12345678910112.tar.lz4'))).toBe(false);
|
||||
|
||||
done();
|
||||
}, 3000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test for latest timestamp', function () {
|
||||
|
||||
it('should get the latest timestamp', function (done) {
|
||||
const getLatestMessageTimestamp = jest.spyOn(SearchApi, 'getLatestMessageTimestamp');
|
||||
SearchApi.getLatestMessageTimestamp().then(function (res) {
|
||||
expect(res).toEqual(currentDate.toString());
|
||||
expect(getLatestMessageTimestamp).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not get the latest timestamp', function (done) {
|
||||
const getLatestMessageTimestamp = jest.spyOn(SearchApi, 'getLatestMessageTimestamp');
|
||||
SearchApi.isInitialized = false;
|
||||
SearchApi.getLatestMessageTimestamp().catch(function (err) {
|
||||
expect(err).toEqual(new Error('Not initialized'));
|
||||
expect(getLatestMessageTimestamp).toHaveBeenCalled();
|
||||
SearchApi.isInitialized = true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be equal to 0000000000000', function (done) {
|
||||
const getLatestMessageTimestamp = jest.spyOn(SearchApi, 'getLatestMessageTimestamp');
|
||||
libSymphonySearch.symSEClearMainRAMIndex();
|
||||
libSymphonySearch.symSEClearRealtimeRAMIndex();
|
||||
SearchApi.getLatestMessageTimestamp().then(function (res) {
|
||||
expect(getLatestMessageTimestamp).toHaveBeenCalled();
|
||||
expect(getLatestMessageTimestamp).toHaveBeenCalledTimes(3);
|
||||
expect(res).toEqual('0000000000000');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test to decrypt the index', function () {
|
||||
|
||||
it('should decrypt the index', function (done) {
|
||||
setTimeout(function () {
|
||||
const decryptAndInit = jest.spyOn(SearchApi, 'decryptAndInit');
|
||||
SearchApi.decryptAndInit();
|
||||
expect(decryptAndInit).toHaveBeenCalled();
|
||||
done();
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
it('should get message from the decrypted index', function (done) {
|
||||
setTimeout(function () {
|
||||
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
|
||||
let endTime = new Date().getTime();
|
||||
let startTime = new Date().getTime() - (4 * 31 * 24 * 60 * 60 * 1000);
|
||||
SearchApi.searchQuery('it works', [], [], '', startTime.toString(), endTime.toString(), '0', 0.2, 0.1).then(function (res) {
|
||||
expect(res.messages.length).toEqual(3);
|
||||
expect(searchQuery).toHaveBeenCalled();
|
||||
done()
|
||||
});
|
||||
}, 3000)
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test for search functions', function () {
|
||||
|
||||
it('should search fail isInitialized is false', function (done) {
|
||||
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
|
||||
SearchApi.isInitialized = false;
|
||||
SearchApi.searchQuery('it works', [], [], '', '', '', 25, 0, 0).catch(function (err) {
|
||||
expect(err).toEqual(new Error('Library not initialized'));
|
||||
expect(searchQuery).toHaveBeenCalled();
|
||||
SearchApi.isInitialized = true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should filter search limit ', function (done) {
|
||||
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
|
||||
SearchApi.searchQuery('works', [], [], '', '', '', 2, 0, 0).then(function (res) {
|
||||
expect(res.messages.length).toBe(2);
|
||||
expect(searchQuery).toHaveBeenCalledTimes(6);
|
||||
expect(searchQuery).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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) {
|
||||
setTimeout(function () {
|
||||
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
|
||||
expect(SearchApi.isInitialized).toBe(true);
|
||||
SearchApi.searchQuery(undefined, [], [], '', '', '', 25, 0, 0).catch(function (err) {
|
||||
expect(err).toEqual(new Error('Search query error'));
|
||||
expect(searchQuery).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
it('should search for hashtag', function (done) {
|
||||
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
|
||||
SearchApi.searchQuery('#123 "testing"', [], [], 'attachment', '', '', 25, 0, 0).then(function (res) {
|
||||
expect(res.messages.length).toEqual(0);
|
||||
expect(searchQuery).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should search for pdf', function (done) {
|
||||
const searchQuery = jest.spyOn(SearchApi, 'searchQuery');
|
||||
SearchApi.searchQuery('', [], [], 'pdf', '', '', 25, 0, 0).then(function (res) {
|
||||
expect(res.messages.length).toEqual(0);
|
||||
expect(searchQuery).toHaveBeenCalled();
|
||||
expect(searchQuery).toHaveBeenCalledTimes(3);
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,162 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { isMac, isWindowsOS } = require('../js/utils/misc.js');
|
||||
|
||||
let executionPath = null;
|
||||
let userConfigDir = null;
|
||||
|
||||
let SearchUtilsAPI;
|
||||
let searchConfig;
|
||||
|
||||
jest.mock('electron', function() {
|
||||
return {
|
||||
app: {
|
||||
getPath: mockedGetPath
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function mockedGetPath(type) {
|
||||
switch (type) {
|
||||
case 'exe':
|
||||
return executionPath;
|
||||
case 'userData':
|
||||
return userConfigDir;
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
describe('Tests for Search Utils', function() {
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000;
|
||||
|
||||
beforeAll(function (done) {
|
||||
executionPath = path.join(__dirname, 'library');
|
||||
if (isWindowsOS) {
|
||||
executionPath = path.join(__dirname, '..', 'library');
|
||||
}
|
||||
userConfigDir = path.join(__dirname, '..');
|
||||
searchConfig = require('../js/search/searchConfig.js');
|
||||
const { SearchUtils } = require('../js/search/searchUtils.js');
|
||||
SearchUtilsAPI = new SearchUtils();
|
||||
SearchUtilsAPI.path = userConfigDir;
|
||||
if (fs.existsSync(searchConfig.FOLDERS_CONSTANTS.USER_CONFIG_FILE)) {
|
||||
fs.unlinkSync(searchConfig.FOLDERS_CONSTANTS.USER_CONFIG_FILE);
|
||||
}
|
||||
done();
|
||||
});
|
||||
|
||||
afterAll(function (done) {
|
||||
fs.unlinkSync(searchConfig.FOLDERS_CONSTANTS.USER_CONFIG_FILE);
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Tests for checking disk space', function () {
|
||||
|
||||
it('should return free space', function (done) {
|
||||
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
|
||||
SearchUtilsAPI.checkFreeSpace().then(function () {
|
||||
expect(checkFreeSpace).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error', function (done) {
|
||||
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
|
||||
if (isMac) {
|
||||
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 {
|
||||
searchConfig.FOLDERS_CONSTANTS.USER_DATA_PATH = undefined;
|
||||
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
|
||||
expect(err).toBeTruthy();
|
||||
expect(checkFreeSpace).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should return error invalid path', function (done) {
|
||||
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
|
||||
SearchUtilsAPI.path = './tp';
|
||||
if (isWindowsOS) {
|
||||
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");
|
||||
}
|
||||
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
|
||||
searchConfig.LIBRARY_CONSTANTS.FREE_DISK_SPACE = path.join(__dirname, '..',
|
||||
"library/FreeDiskSpace.exe");
|
||||
expect(checkFreeSpace).toHaveBeenCalled();
|
||||
expect(err).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test for search users config', function () {
|
||||
|
||||
it('should return null for new user config', function (done) {
|
||||
SearchUtilsAPI.getSearchUserConfig(1234567891011).then(function (res) {
|
||||
expect(res).toEqual(null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should exist users config file', function (done) {
|
||||
setTimeout(function () {
|
||||
expect(fs.existsSync(searchConfig.FOLDERS_CONSTANTS.USER_CONFIG_FILE)).toEqual(true);
|
||||
done();
|
||||
}, 2000)
|
||||
});
|
||||
|
||||
it('should exist users config file', function (done) {
|
||||
setTimeout(function () {
|
||||
SearchUtilsAPI.getSearchUserConfig(1234567891011).then(function (res) {
|
||||
expect(res).toEqual({});
|
||||
done();
|
||||
});
|
||||
}, 3000)
|
||||
});
|
||||
|
||||
it('should update user config file', function (done) {
|
||||
let data = {
|
||||
rotationId: 0,
|
||||
version: 1,
|
||||
language: 'en'
|
||||
};
|
||||
SearchUtilsAPI.updateUserConfig(1234567891011, data).then(function (res) {
|
||||
data.indexVersion = 'v1';
|
||||
expect(res).toEqual(data);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it('should modify user config file', function (done) {
|
||||
let data = {
|
||||
rotationId: 1,
|
||||
version: 1,
|
||||
language: 'en'
|
||||
};
|
||||
SearchUtilsAPI.updateUserConfig(1234567891011, data).then(function (res) {
|
||||
expect(res.rotationId).toEqual(1);
|
||||
expect(res.indexVersion).toEqual('v1');
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it('should create user if not exist', function (done) {
|
||||
SearchUtilsAPI.getSearchUserConfig(2234567891011).catch(function (err) {
|
||||
expect(err).toEqual(null);
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user