mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-04 21:35:03 +02:00
All: Fixes #6261: Ensure that note revision markup type is set correctly
This commit is contained in:
parent
f4ec73ab0e
commit
addcfb0129
@ -4,10 +4,11 @@ import Setting from '../models/Setting';
|
|||||||
import Note from '../models/Note';
|
import Note from '../models/Note';
|
||||||
import ItemChange from '../models/ItemChange';
|
import ItemChange from '../models/ItemChange';
|
||||||
import Revision from '../models/Revision';
|
import Revision from '../models/Revision';
|
||||||
import BaseModel from '../BaseModel';
|
import BaseModel, { ModelType } from '../BaseModel';
|
||||||
import RevisionService from '../services/RevisionService';
|
import RevisionService from '../services/RevisionService';
|
||||||
|
import { MarkupLanguage } from '../../renderer';
|
||||||
|
|
||||||
describe('services_Revision', function() {
|
describe('services/RevisionService', function() {
|
||||||
|
|
||||||
beforeEach(async (done) => {
|
beforeEach(async (done) => {
|
||||||
await setupDatabaseAndSynchronizer(1);
|
await setupDatabaseAndSynchronizer(1);
|
||||||
@ -503,4 +504,51 @@ describe('services_Revision', function() {
|
|||||||
expect(error.message).toContain(corruptedMetadata);
|
expect(error.message).toContain(corruptedMetadata);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('note revisions should include certain required properties', async () => {
|
||||||
|
const revisions = [
|
||||||
|
{
|
||||||
|
id: '2b7d7aa51f944aa5b63b8453e1182cb0',
|
||||||
|
parent_id: '',
|
||||||
|
item_type: 1,
|
||||||
|
item_id: 'cc333327a8d64456a73773b13f22a1ce',
|
||||||
|
item_updated_time: 1647101206511,
|
||||||
|
title_diff: '[{"diffs":[[1,"hello"]],"start1":0,"start2":0,"length1":0,"length2":5}]',
|
||||||
|
body_diff: '[]',
|
||||||
|
metadata_diff: '{"new":{},"deleted":[]}',
|
||||||
|
encryption_applied: 0,
|
||||||
|
type_: 13,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'd2e1cd8433364bcba8e689aaa20dfef2',
|
||||||
|
parent_id: '2b7d7aa51f944aa5b63b8453e1182cb0',
|
||||||
|
item_type: 1,
|
||||||
|
item_id: 'cc333327a8d64456a73773b13f22a1ce',
|
||||||
|
item_updated_time: 1647101206622,
|
||||||
|
title_diff: '[{"diffs":[[0,"hello"],[1," welcome"]],"start1":0,"start2":0,"length1":5,"length2":13}]',
|
||||||
|
body_diff: '[]',
|
||||||
|
metadata_diff: '{"new":{},"deleted":[]}',
|
||||||
|
encryption_applied: 0,
|
||||||
|
type_: 13,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const note1 = await revisionService().revisionNote(revisions, 1);
|
||||||
|
|
||||||
|
expect(note1.title).toBe('hello welcome');
|
||||||
|
expect(note1.body).toBe('');
|
||||||
|
expect(note1.markup_language).toBe(MarkupLanguage.Markdown);
|
||||||
|
expect(note1.type_).toBe(ModelType.Note);
|
||||||
|
|
||||||
|
// Check that it's not overidding the property if it's already set
|
||||||
|
|
||||||
|
const revisions2 = revisions.slice();
|
||||||
|
revisions2[0] = {
|
||||||
|
...revisions2[0],
|
||||||
|
metadata_diff: '{"new":{"markup_language":2},"deleted":[]}',
|
||||||
|
};
|
||||||
|
|
||||||
|
const note2 = await revisionService().revisionNote(revisions2, 1);
|
||||||
|
expect(note2.markup_language).toBe(MarkupLanguage.Html);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,7 @@ import BaseService from './BaseService';
|
|||||||
import { _ } from '../locale';
|
import { _ } from '../locale';
|
||||||
import { ItemChangeEntity, NoteEntity, RevisionEntity } from './database/types';
|
import { ItemChangeEntity, NoteEntity, RevisionEntity } from './database/types';
|
||||||
import Logger from '../Logger';
|
import Logger from '../Logger';
|
||||||
|
import { MarkupLanguage } from '../../renderer';
|
||||||
const { substrWithEllipsis } = require('../string-utils');
|
const { substrWithEllipsis } = require('../string-utils');
|
||||||
const { sprintf } = require('sprintf-js');
|
const { sprintf } = require('sprintf-js');
|
||||||
const { wrapError } = require('../errorUtils');
|
const { wrapError } = require('../errorUtils');
|
||||||
@ -217,7 +218,7 @@ export default class RevisionService extends BaseService {
|
|||||||
return Revision.deleteOldRevisions(ttl);
|
return Revision.deleteOldRevisions(ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
async revisionNote(revisions: RevisionEntity[], index: number) {
|
public async revisionNote(revisions: RevisionEntity[], index: number) {
|
||||||
if (index < 0 || index >= revisions.length) throw new Error(`Invalid revision index: ${index}`);
|
if (index < 0 || index >= revisions.length) throw new Error(`Invalid revision index: ${index}`);
|
||||||
|
|
||||||
const rev = revisions[index];
|
const rev = revisions[index];
|
||||||
@ -233,6 +234,7 @@ export default class RevisionService extends BaseService {
|
|||||||
output.updated_time = output.user_updated_time;
|
output.updated_time = output.user_updated_time;
|
||||||
output.created_time = output.user_created_time;
|
output.created_time = output.user_created_time;
|
||||||
(output as any).type_ = BaseModel.TYPE_NOTE;
|
(output as any).type_ = BaseModel.TYPE_NOTE;
|
||||||
|
if (!('markup_language' in output)) output.markup_language = MarkupLanguage.Markdown;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user