文件
mynode/packages/lib/services/DecryptionWorker.test.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

51 行
1.5 KiB
TypeScript

import { setupDatabaseAndSynchronizer, switchClient, decryptionWorker } from '../testing/test-utils';
import BaseItem from '../models/BaseItem';
import Note from '../models/Note';
describe('services/DecryptionWorker', () => {
beforeEach(async () => {
await setupDatabaseAndSynchronizer(1);
await switchClient(1);
});
afterEach(() => {
jest.restoreAllMocks();
});
it('should not return null when a call to .start is cancelled', async () => {
const worker = decryptionWorker();
// Both calls should return a valid DecryptionResult, even if the
// queue skips one task due to concurrency.
const results = await Promise.all([
worker.start(),
worker.start(),
]);
for (const result of results) {
expect(result === null).toBe(false);
expect(result === undefined).toBe(false);
expect(result).toHaveProperty('error');
}
});
it('should skip a note that was decrypted on demand after the worker loaded it', async () => {
const note = await Note.save({ title: 'Test note', body: 'Test body' });
const encryptedSnapshot = { ...note, encryption_applied: 1, encryption_cipher_text: 'cipher text' };
const worker = decryptionWorker();
jest.spyOn(worker.encryptionService(), 'loadedMasterKeysCount').mockReturnValue(1);
jest.spyOn(BaseItem, 'itemsThatNeedDecryption').mockResolvedValue({
items: [encryptedSnapshot],
hasMore: false,
});
const decryptSpy = jest.spyOn(Note, 'decrypt');
const result = await worker.start();
expect(decryptSpy).not.toHaveBeenCalled();
expect(result.decryptedItemCount).toBe(1);
});
});