SEARCH-569

- Fixed tests for Windows
This commit is contained in:
Keerthi Niranjan
2018-01-12 12:23:34 +05:30
parent 665f35b08e
commit 68f65248d7
3 changed files with 32 additions and 10 deletions

View File

@@ -21,7 +21,11 @@ class SearchUtils {
checkFreeSpace() {
return new Promise((resolve, reject) => {
if (!isMac) {
this.path = this.path.substring(0, 2);
try {
this.path = this.path.substring(0, 2);
} catch (e) {
reject(new Error('Invalid Path : ' + e));
}
}
checkDiskSpace(this.path, resolve, reject);
});

View File

@@ -1,6 +1,7 @@
const childProcess = require('child_process');
const path = require('path');
const fs = require('fs');
const { isMac } = require('../js/utils/misc.js');
let executionPath = null;
let userConfigDir = null;
@@ -45,6 +46,9 @@ describe('Tests for Search', function() {
key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd=';
executionPath = path.join(__dirname, 'library');
if (!isMac) {
executionPath = path.join(__dirname, '..', 'library');
}
userConfigDir = path.join(__dirname, '..');
searchConfig = require('../js/search/searchConfig.js');
@@ -77,7 +81,7 @@ describe('Tests for Search', function() {
function deleteIndexFolders(location) {
if (fs.existsSync(location)) {
fs.readdirSync(location).forEach(function(file) {
let curPath = location + "/" + file;
let curPath = path.join(location, file);
if (fs.lstatSync(curPath).isDirectory()) {
deleteIndexFolders(curPath);
} else {
@@ -425,7 +429,8 @@ describe('Tests for Search', function() {
const getLatestMessageTimestamp = jest.spyOn(SearchApi, 'getLatestMessageTimestamp');
SearchApi.getLatestMessageTimestamp().catch(function (err) {
expect(err).toEqual(new Error('Index folder does not exist.'));
SearchApi.indexFolderName = `${dataFolderPath}/${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}`;
let folderName = `${searchConfig.FOLDERS_CONSTANTS.PREFIX_NAME}_${userId}`;
SearchApi.indexFolderName = path.join(dataFolderPath, folderName);
expect(getLatestMessageTimestamp).toHaveBeenCalled();
expect(getLatestMessageTimestamp).toHaveBeenCalledTimes(3);
done();

View File

@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const { isMac } = require('../js/utils/misc.js');
let executionPath = null;
let userConfigDir = null;
@@ -60,20 +61,32 @@ describe('Tests for Search Utils', function() {
it('should return error', function (done) {
const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace');
SearchUtilsAPI.path = undefined;
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
expect(err).toEqual(new Error("Please provide path"));
expect(checkFreeSpace).toHaveBeenCalled();
done();
});
if (isMac) {
SearchUtilsAPI.path = undefined;
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
expect(err).toEqual(new Error("Please provide path"));
expect(checkFreeSpace).toHaveBeenCalled();
done();
});
} else {
SearchUtilsAPI.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 (!isMac) {
SearchUtilsAPI.path = 'A://test';
}
SearchUtilsAPI.checkFreeSpace().catch(function (err) {
expect(checkFreeSpace).toHaveBeenCalled();
expect(err).toEqual(err);
expect(err).toBeTruthy();
done();
});
});