mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Removed requirement for unique folder title
This commit is contained in:
parent
09bcf8df35
commit
ab312d70f5
@ -3,12 +3,12 @@ require('babel-plugin-transform-runtime');
|
|||||||
|
|
||||||
import { time } from 'lib/time-utils.js';
|
import { time } from 'lib/time-utils.js';
|
||||||
import { Logger } from 'lib/logger.js';
|
import { Logger } from 'lib/logger.js';
|
||||||
|
import { dirname } from 'lib/path-utils.js';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
|
|
||||||
const exec = require('child_process').exec
|
const exec = require('child_process').exec
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
|
|
||||||
const baseDir = '/var/www/joplin/CliClient/tests/fuzzing';
|
const baseDir = dirname(__dirname) + '/tests/fuzzing';
|
||||||
const syncDir = baseDir + '/sync';
|
const syncDir = baseDir + '/sync';
|
||||||
const joplinAppPath = __dirname + '/main.js';
|
const joplinAppPath = __dirname + '/main.js';
|
||||||
let syncDurations = [];
|
let syncDurations = [];
|
||||||
@ -85,13 +85,21 @@ function execCommand(client, command, options = {}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function clientItems(client) {
|
||||||
|
let itemsJson = await execCommand(client, 'dump');
|
||||||
|
try {
|
||||||
|
return JSON.parse(itemsJson);
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('Cannot parse JSON: ' + itemsJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function execRandomCommand(client) {
|
async function execRandomCommand(client) {
|
||||||
let possibleCommands = [
|
let possibleCommands = [
|
||||||
['mkbook {word}', 40], // CREATE FOLDER
|
['mkbook {word}', 40], // CREATE FOLDER
|
||||||
['mknote {word}', 70], // CREATE NOTE
|
['mknote {word}', 70], // CREATE NOTE
|
||||||
[async () => { // DELETE RANDOM ITEM
|
[async () => { // DELETE RANDOM ITEM
|
||||||
let items = await execCommand(client, 'dump');
|
let items = clientItems(client);
|
||||||
items = JSON.parse(items);
|
|
||||||
let item = randomElement(items);
|
let item = randomElement(items);
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
@ -114,8 +122,7 @@ async function execRandomCommand(client) {
|
|||||||
return execCommand(client, 'sync --random-failures', options);
|
return execCommand(client, 'sync --random-failures', options);
|
||||||
}, 30],
|
}, 30],
|
||||||
[async () => { // UPDATE RANDOM ITEM
|
[async () => { // UPDATE RANDOM ITEM
|
||||||
let items = await execCommand(client, 'dump');
|
let items = clientItems(client);
|
||||||
items = JSON.parse(items);
|
|
||||||
let item = randomElement(items);
|
let item = randomElement(items);
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
|
0
CliClient/fuzzing.sh
Normal file → Executable file
0
CliClient/fuzzing.sh
Normal file → Executable file
@ -425,7 +425,7 @@ describe('Synchronizer', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow duplicate folder title and rename the new one', async (done) => {
|
it('should allow duplicate folder titles', async (done) => {
|
||||||
let localF1 = await Folder.save({ title: "folder" });
|
let localF1 = await Folder.save({ title: "folder" });
|
||||||
|
|
||||||
await switchClient(2);
|
await switchClient(2);
|
||||||
@ -441,7 +441,7 @@ describe('Synchronizer', function() {
|
|||||||
|
|
||||||
let localF2 = await Folder.load(remoteF2.id);
|
let localF2 = await Folder.load(remoteF2.id);
|
||||||
|
|
||||||
expect(localF2.title == remoteF2.title).toBe(false);
|
expect(localF2.title == remoteF2.title).toBe(true);
|
||||||
|
|
||||||
// Then that folder that has been renamed locally should be set in such a way
|
// Then that folder that has been renamed locally should be set in such a way
|
||||||
// that synchronizing it applies the title change remotely, and that new title
|
// that synchronizing it applies the title change remotely, and that new title
|
||||||
@ -460,5 +460,5 @@ describe('Synchronizer', function() {
|
|||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -18,6 +18,7 @@ let currentClient_ = 1;
|
|||||||
|
|
||||||
const logger = new Logger();
|
const logger = new Logger();
|
||||||
logger.addTarget('file', { path: __dirname + '/data/log-test.txt' });
|
logger.addTarget('file', { path: __dirname + '/data/log-test.txt' });
|
||||||
|
//logger.addTarget('console');
|
||||||
logger.setLevel(Logger.LEVEL_DEBUG);
|
logger.setLevel(Logger.LEVEL_DEBUG);
|
||||||
|
|
||||||
function sleep(n) {
|
function sleep(n) {
|
||||||
|
@ -86,20 +86,12 @@ class Folder extends BaseItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static save(o, options = null) {
|
static save(o, options = null) {
|
||||||
return Folder.loadByField('title', o.title).then((existingFolder) => {
|
return super.save(o, options).then((folder) => {
|
||||||
if (existingFolder && existingFolder.id != o.id) {
|
this.dispatch({
|
||||||
let error = new Error(_('A notebook with title "%s" already exists', o.title));
|
type: 'FOLDERS_UPDATE_ONE',
|
||||||
error.code = 'duplicateTitle';
|
folder: folder,
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.save(o, options).then((folder) => {
|
|
||||||
this.dispatch({
|
|
||||||
type: 'FOLDERS_UPDATE_ONE',
|
|
||||||
folder: folder,
|
|
||||||
});
|
|
||||||
return folder;
|
|
||||||
});
|
});
|
||||||
|
return folder;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,20 +319,7 @@ class Synchronizer {
|
|||||||
await Resource.setContent(newContent, remoteResourceContent);
|
await Resource.setContent(newContent, remoteResourceContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await ItemClass.save(newContent, options);
|
||||||
await ItemClass.save(newContent, options);
|
|
||||||
} catch (error) {
|
|
||||||
|
|
||||||
if (this.randomFailure(options, 3)) return;
|
|
||||||
|
|
||||||
if (error.code == 'duplicateTitle') {
|
|
||||||
newContent.title = newContent.title + '-' + newContent.created_time + '-' + (Math.floor(Math.random() * 1000));
|
|
||||||
newContent.updated_time = newContent.sync_time + 2;
|
|
||||||
await ItemClass.save(newContent, options);
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newContent.type_ == BaseModel.MODEL_TYPE_TAG) {
|
if (newContent.type_ == BaseModel.MODEL_TYPE_TAG) {
|
||||||
let noteIds = newContent.notes_.split(',');
|
let noteIds = newContent.notes_.split(',');
|
||||||
|
Loading…
Reference in New Issue
Block a user