2024-06-25 15:01:39 +02:00
|
|
|
import Setting, { Env } from './models/Setting';
|
2021-05-21 15:17:21 +02:00
|
|
|
import { reg } from './registry';
|
2021-03-29 10:35:39 +02:00
|
|
|
|
|
|
|
const sync = {
|
|
|
|
start: jest.fn().mockReturnValue({}),
|
|
|
|
};
|
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
describe('Registry', () => {
|
2021-03-29 10:35:39 +02:00
|
|
|
let originalSyncTarget: typeof reg.syncTarget;
|
|
|
|
|
|
|
|
beforeAll(() => {
|
2024-06-25 15:01:39 +02:00
|
|
|
Setting.setConstant('env', Env.Prod);
|
2021-03-29 10:35:39 +02:00
|
|
|
originalSyncTarget = reg.syncTarget;
|
|
|
|
reg.syncTarget = () => ({
|
|
|
|
isAuthenticated: () => true,
|
|
|
|
synchronizer: () => sync,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
2024-06-25 15:01:39 +02:00
|
|
|
Setting.setConstant('env', Env.Dev);
|
2021-03-29 10:35:39 +02:00
|
|
|
reg.syncTarget = originalSyncTarget;
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
Setting.setValue('sync.interval', 300);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
Setting.setValue('sync.interval', 0);
|
|
|
|
reg.setupRecurrentSync();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when on mobile data', () => {
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Setting.setValue('sync.mobileWifiOnly', true);
|
2021-08-16 19:05:22 +02:00
|
|
|
Setting.setValue('sync.target', 1);
|
2021-03-29 10:35:39 +02:00
|
|
|
reg.setIsOnMobileData(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not sync automatically', () => {
|
|
|
|
reg.setupRecurrentSync();
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
|
|
|
|
expect(sync.start).toHaveBeenCalledTimes(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sync if do wifi check is false', done => {
|
|
|
|
void reg.scheduleSync(1, null, false)
|
2022-09-30 18:23:14 +02:00
|
|
|
// eslint-disable-next-line promise/prefer-await-to-then -- Old code before rule was applied
|
2021-03-29 10:35:39 +02:00
|
|
|
.then(() =>{
|
|
|
|
expect(sync.start).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sync if "sync only over wifi" is disabled in settings', () => {
|
|
|
|
Setting.setValue('sync.mobileWifiOnly', false);
|
|
|
|
reg.setupRecurrentSync();
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
|
|
|
|
expect(sync.start).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when not on mobile data', () => {
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
Setting.setValue('sync.mobileWifiOnly', true);
|
|
|
|
reg.setIsOnMobileData(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should sync automatically', () => {
|
|
|
|
reg.setupRecurrentSync();
|
|
|
|
jest.runOnlyPendingTimers();
|
|
|
|
|
|
|
|
expect(sync.start).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|