You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-13 00:10:37 +02:00
All: Allow modifying a resource metadata only when synchronising (#9114)
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
import { supportDir, setupDatabaseAndSynchronizer, switchClient, simulateReadOnlyShareEnv, expectThrow, createTempFile } from '../testing/test-utils';
|
||||
import { supportDir, setupDatabaseAndSynchronizer, switchClient, simulateReadOnlyShareEnv, expectThrow, createTempFile, msleep } from '../testing/test-utils';
|
||||
import Folder from '../models/Folder';
|
||||
import Note from '../models/Note';
|
||||
import Resource from '../models/Resource';
|
||||
import shim from '../shim';
|
||||
import { ErrorCode } from '../errors';
|
||||
import { remove, pathExists } from 'fs-extra';
|
||||
import { ResourceEntity } from '../services/database/types';
|
||||
|
||||
const testImagePath = `${supportDir}/photo.jpg`;
|
||||
|
||||
@ -95,6 +96,39 @@ describe('models/Resource', () => {
|
||||
expect(originalStat.size).toBe(newStat.size);
|
||||
}));
|
||||
|
||||
it('should set the blob_updated_time property if the blob is updated', (async () => {
|
||||
const note = await Note.save({});
|
||||
await shim.attachFileToNote(note, testImagePath);
|
||||
|
||||
const resourceA: ResourceEntity = (await Resource.all())[0];
|
||||
expect(resourceA.updated_time).toBe(resourceA.blob_updated_time);
|
||||
|
||||
await msleep(1);
|
||||
|
||||
await Resource.updateResourceBlobContent(resourceA.id, testImagePath);
|
||||
|
||||
const resourceB: ResourceEntity = (await Resource.all())[0];
|
||||
expect(resourceB.updated_time).toBeGreaterThan(resourceA.updated_time);
|
||||
expect(resourceB.blob_updated_time).toBeGreaterThan(resourceA.blob_updated_time);
|
||||
}));
|
||||
|
||||
it('should NOT set the blob_updated_time property if the blob is NOT updated', (async () => {
|
||||
const note = await Note.save({});
|
||||
await shim.attachFileToNote(note, testImagePath);
|
||||
|
||||
const resourceA: ResourceEntity = (await Resource.all())[0];
|
||||
|
||||
await msleep(1);
|
||||
|
||||
// We only update the resource metadata - so the blob timestamp should
|
||||
// not change
|
||||
await Resource.save({ id: resourceA.id, title: 'new title' });
|
||||
|
||||
const resourceB: ResourceEntity = (await Resource.all())[0];
|
||||
expect(resourceB.updated_time).toBeGreaterThan(resourceA.updated_time);
|
||||
expect(resourceB.blob_updated_time).toBe(resourceA.blob_updated_time);
|
||||
}));
|
||||
|
||||
it('should not allow modifying a read-only resource', async () => {
|
||||
const { cleanup, resource } = await setupFolderNoteResourceReadOnly('123456789');
|
||||
await expectThrow(async () => Resource.save({ id: resource.id, share_id: '123456789', title: 'cannot do this!' }), ErrorCode.IsReadOnly);
|
||||
|
Reference in New Issue
Block a user