SymphonyElectron/spec/appCacheHandler.spec.ts
Vishwas Shashidhar 82543debfb
feat: SDA-1838: upgrade electron framework to 8.x (#895)
* add support for electron 8.x

* update node-abi to latest

* 8.x: fix unit tests

* upgrade dependencies

Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com>

* SDA-1838: removed unwanted console log

Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com>

* SDA-1838: refactor code

Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com>
2020-03-06 14:37:18 +05:30

46 lines
1.4 KiB
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import { cleanUpAppCache, createAppCacheFile } from '../src/app/app-cache-handler';
import { app, session } from './__mocks__/electron';
jest.mock('fs', () => ({
writeFileSync: jest.fn(),
existsSync: jest.fn(() => true),
unlinkSync: jest.fn(),
}));
jest.mock('../src/common/logger', () => {
return {
logger: {
error: jest.fn(),
info: jest.fn(),
},
};
});
describe('app cache handler', () => {
const cachePathExpected = path.join(app.getPath('userData'), 'CacheCheck');
it('should call `cleanUpAppCache` correctly', () => {
const spyFn = 'unlinkSync';
const spy = jest.spyOn(fs, spyFn);
cleanUpAppCache();
expect(spy).toBeCalledWith(cachePathExpected);
});
it('should call `clearCache` when `session.defaultSession` is not null', () => {
jest.spyOn(fs, 'existsSync').mockImplementation(() => false);
const spyFn = 'clearCache';
const spy = jest.spyOn(session.defaultSession, spyFn);
cleanUpAppCache();
expect(spy).toBeCalled();
});
it('should call `createAppCacheFile` correctly', () => {
const spyFn = 'writeFileSync';
const spy = jest.spyOn(fs, spyFn);
createAppCacheFile();
expect(spy).lastCalledWith(cachePathExpected, '');
});
});