1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
This commit is contained in:
Laurent Cozic 2017-06-25 16:17:40 +01:00
parent 6b23039d95
commit 6622f18f76
16 changed files with 50 additions and 97 deletions

View File

@ -28,7 +28,7 @@ const fs = require('fs');
Log.setLevel(Log.LEVEL_DEBUG);
let db = new Database(new DatabaseDriverNode());
db.setDebugMode(true);
//db.setDebugMode(true);
db.open({ name: '/home/laurent/Temp/test.sqlite3' }).then(() => {
return db.selectAll('SELECT * FROM table_fields');
}).then((rows) => {

View File

@ -1,5 +1,3 @@
require('app-module-path').addPath(__dirname);
import { uuid } from 'lib/uuid.js';
import moment from 'moment';
import { promiseChain } from 'lib/promise-utils.js';

View File

@ -44,7 +44,7 @@ syncLogger.addTarget('file', { path: dataDir + '/log-sync.txt' });
syncLogger.setLevel(Logger.LEVEL_DEBUG);
let db = new Database(new DatabaseDriverNode());
db.setDebugMode(true);
//db.setDebugMode(true);
db.setLogger(dbLogger);
let synchronizer_ = null;

View File

@ -3,7 +3,6 @@ require('babel-plugin-transform-runtime');
import { OneDriveApi } from 'lib/onedrive-api.js';
const MicrosoftGraph = require("@microsoft/microsoft-graph-client");
const fs = require('fs-extra');
const path = require('path');

View File

@ -3,10 +3,7 @@
"version": "0.0.1",
"private": true,
"dependencies": {
"@microsoft/microsoft-graph-client": "^1.0.0",
"app-module-path": "^2.2.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.1.4",
"form-data": "^2.1.4",
"fs-extra": "^3.0.1",
"jssha": "^2.3.0",
@ -16,10 +13,8 @@
"node-fetch": "^1.7.1",
"promise": "^7.1.1",
"query-string": "4.3.4",
"react": "16.0.0-alpha.6",
"sax": "^1.2.2",
"server-destroy": "^1.0.1",
"source-map-support": "^0.4.15",
"sprintf-js": "^1.1.1",
"sqlite3": "^3.1.8",
"string-to-stream": "^1.1.0",
@ -32,9 +27,12 @@
"babel-cli": "^6.24.1",
"babel-plugin-syntax-async-functions": "^6.1.4",
"babel-plugin-transform-regenerator": "^6.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.1.4",
"babel-preset-env": "^1.5.1",
"babel-preset-es2015": "^6.1.4",
"babel-preset-react": "^6.24.1",
"source-map-support": "^0.4.15",
"jasmine": "^2.6.0"
},
"scripts": {

View File

@ -5,6 +5,7 @@ rm -f "$CLIENT_DIR/tests-build/lib"
mkdir -p "$CLIENT_DIR/tests-build/data"
ln -s "$CLIENT_DIR/build/lib" "$CLIENT_DIR/tests-build"
npm run build && NODE_PATH="$CLIENT_DIR/tests-build/" npm test tests-build/synchronizer.js tests-build/base-model.js
#npm run build && NODE_PATH="$CLIENT_DIR/tests-build/" npm test tests-build/base-model.js
#npm run build && NODE_PATH="$CLIENT_DIR/tests-build/" npm test tests-build/synchronizer.js
npm run build && NODE_PATH="$CLIENT_DIR/tests-build/" npm test tests-build/models/folder.js
#npm run build && NODE_PATH="$CLIENT_DIR/tests-build/" npm test tests-build/models/folder.js

View File

@ -20,19 +20,20 @@ describe('BaseItem', function() {
});
it('should create a deleted_items record', async (done) => {
let folder = await Folder.save({ title: 'folder1' });
let folder1 = await Folder.save({ title: 'folder1' });
let folder2 = await Folder.save({ title: 'folder2' });
await Folder.delete(folder.id);
await Folder.delete(folder1.id);
let items = await BaseModel.deletedItems();
expect(items.length).toBe(1);
expect(items[0].item_id).toBe(folder.id);
expect(items[0].item_type).toBe(folder.type_);
expect(items[0].item_id).toBe(folder1.id);
expect(items[0].item_type).toBe(folder1.type_);
let folders = await Folder.all();
expect(folders.length).toBe(0);
expect(folders.length).toBe(1);
done();
});

View File

@ -1,12 +0,0 @@
import { time } from 'lib/time-utils.js';
import { setupDatabase, setupDatabaseAndSynchronizer, db, synchronizer, fileApi, sleep, clearDatabase, switchClient } from 'test-utils.js';
import { createFoldersAndNotes } from 'test-data.js';
import { Folder } from 'lib/models/folder.js';
import { Note } from 'lib/models/note.js';
import { Setting } from 'lib/models/setting.js';
import { BaseItem } from 'lib/models/base-item.js';
import { BaseModel } from 'lib/base-model.js';
process.on('unhandledRejection', (reason, p) => {
console.error('Unhandled promise rejection at: Promise', p, 'reason:', reason);
});

View File

@ -1,38 +0,0 @@
import { promiseChain } from 'lib/promise-utils.js';
import { NoteFolderService } from 'lib/services/note-folder-service.js';
import { setupDatabaseAndSynchronizer } from 'test-utils.js';
import { createFoldersAndNotes } from 'test-data.js';
describe('NoteFolderServices', function() {
beforeEach(function(done) {
setupDatabaseAndSynchronizer(done);
});
it('should retrieve sync items', function(done) {
createFoldersAndNotes().then(() => {
return NoteFolderService.itemsThatNeedSync().then((context) => {
expect(context.items.length).toBe(2);
expect(context.hasMore).toBe(true);
return context;
});
}).then((context) => {
return NoteFolderService.itemsThatNeedSync(context, 2).then((context) => {
expect(context.items.length).toBe(2);
expect(context.hasMore).toBe(true);
return context;
});
}).then((context) => {
return NoteFolderService.itemsThatNeedSync(context, 2).then((context) => {
expect(context.items.length).toBe(1);
expect(context.hasMore).toBe(false);
return context;
});
}).then(() => {
done();
}).catch((error) => {
console.error(error);
});
});
});

View File

@ -11,6 +11,12 @@ process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
});
async function allItems() {
let folders = await Folder.all();
let notes = await Note.all();
return folders.concat(notes);
}
async function localItemsSameAsRemote(locals, expect) {
try {
let files = await fileApi().list();
@ -46,7 +52,7 @@ describe('Synchronizer', function() {
let folder = await Folder.save({ title: "folder1" });
await Note.save({ title: "un", parent_id: folder.id });
let all = await Folder.all({ includeNotes: true });
let all = await allItems();
await synchronizer().start();
@ -64,7 +70,7 @@ describe('Synchronizer', function() {
await Note.save({ title: "un UPDATE", id: note.id });
let all = await Folder.all({ includeNotes: true });
let all = await allItems();
await synchronizer().start();
await localItemsSameAsRemote(all, expect);
@ -81,7 +87,7 @@ describe('Synchronizer', function() {
await synchronizer().start();
let all = await Folder.all({ includeNotes: true });
let all = await allItems();
await localItemsSameAsRemote(all, expect);
done();
@ -109,7 +115,7 @@ describe('Synchronizer', function() {
await synchronizer().start();
let all = await Folder.all({ includeNotes: true });
let all = await allItems();
let files = await fileApi().list();
await localItemsSameAsRemote(all, expect);
@ -250,7 +256,7 @@ describe('Synchronizer', function() {
await synchronizer().start();
let items = await Folder.all({ includeNotes: true });
let items = await allItems();
expect(items.length).toBe(1);
@ -287,16 +293,13 @@ describe('Synchronizer', function() {
expect(conflictedNotes.length).toBe(1);
expect(conflictedNotes[0].title).toBe(newTitle);
let items = await Folder.all({ includeNotes: true });
expect(items.length).toBe(1);
done();
});
it('should handle conflict when remote folder is deleted then local folder is renamed', async (done) => {
let folder1 = await Folder.save({ title: "folder1" });
let folder2 = await Folder.save({ title: "folder2" });
let note1 = await Note.save({ title: "un", parent_id: folder1.id });
await synchronizer().start();
@ -319,9 +322,9 @@ describe('Synchronizer', function() {
await synchronizer().start();
let items = await Folder.all({ includeNotes: true });
let items = await allItems();
expect(items.length).toBe(0);
expect(items.length).toBe(1);
done();
});

View File

@ -4,6 +4,7 @@ import { DatabaseDriverNode } from 'lib/database-driver-node.js';
import { BaseModel } from 'lib/base-model.js';
import { Folder } from 'lib/models/folder.js';
import { Note } from 'lib/models/note.js';
import { Logger } from 'lib/logger.js';
import { Setting } from 'lib/models/setting.js';
import { BaseItem } from 'lib/models/base-item.js';
import { Synchronizer } from 'lib/synchronizer.js';
@ -15,6 +16,10 @@ let synchronizers_ = [];
let fileApi_ = null;
let currentClient_ = 1;
const logger = new Logger();
logger.addTarget('file', { path: __dirname + '/data/log-test.txt' });
logger.setLevel(Logger.LEVEL_DEBUG);
function sleep(n) {
return new Promise((resolve, reject) => {
setTimeout(() => {
@ -63,7 +68,7 @@ function setupDatabase(id = null) {
// Don't care if the file doesn't exist
}).then(() => {
databases_[id] = new Database(new DatabaseDriverNode());
databases_[id].setDebugMode(false);
databases_[id].setLogger(logger);
return databases_[id].open({ name: filePath }).then(() => {
BaseModel.db_ = databases_[id];
return setupDatabase(id);
@ -78,6 +83,7 @@ async function setupDatabaseAndSynchronizer(id = null) {
if (!synchronizers_[id]) {
synchronizers_[id] = new Synchronizer(db(id), fileApi());
synchronizers_[id].setLogger(logger);
}
await fileApi().format();
@ -90,7 +96,6 @@ function db(id = null) {
function synchronizer(id = null) {
if (id === null) id = currentClient_;
//console.info('SYNC', id);
return synchronizers_[id];
}
@ -98,6 +103,7 @@ function fileApi() {
if (fileApi_) return fileApi_;
fileApi_ = new FileApi('/root', new FileApiDriverMemory());
fileApi_.setLogger(logger);
return fileApi_;
}

View File

@ -190,7 +190,7 @@ class AppComponent extends React.Component {
componentDidMount() {
let db = new Database(new DatabaseDriverReactNative());
db.setDebugMode(false);
//db.setDebugMode(false);
BaseModel.dispatch = this.props.dispatch;
BaseModel.db_ = db;

View File

@ -140,7 +140,7 @@ class BaseModel {
static async all(options = null) {
let q = this.applySqlOptions(options, 'SELECT * FROM `' + this.tableName() + '`');
return await this.modelSelectAll(q.sql);
return this.modelSelectAll(q.sql);
}
static modelSelectOne(sql, params = null) {

View File

@ -140,14 +140,14 @@ class Database {
return this.logger_;
}
setDebugMode(v) {
//this.driver_.setDebugMode(v);
this.debugMode_ = v;
}
// setDebugMode(v) {
// //this.driver_.setDebugMode(v);
// this.debugMode_ = v;
// }
debugMode() {
return this.debugMode_;
}
// debugMode() {
// return this.debugMode_;
// }
initialized() {
return this.initialized_;
@ -295,10 +295,6 @@ class Database {
}
logQuery(sql, params = null) {
if (!this.debugMode()) return;
//console.info(sql, params);
this.logger().debug(sql);
if (params !== null && params.length) this.logger().debug(JSON.stringify(params));
}

View File

@ -69,7 +69,7 @@ class Folder extends BaseItem {
await Note.delete(noteIds[i]);
}
super.delete(folderId, options);
await super.delete(folderId, options);
this.dispatch({
type: 'FOLDER_DELETE',

View File

@ -112,9 +112,10 @@ class Note extends BaseItem {
return output;
}
static all(parentId) {
return this.modelSelectAll('SELECT * FROM notes WHERE is_conflict = 0 AND parent_id = ?', [parentId]);
}
// static all(options = null) {
// let q = this.applySqlOptions(options, 'SELECT * FROM notes WHERE is_conflict = 0 AND parent_id = ?', [parentId]);
// return this.modelSelectAll(q.sql, q.params);
// }
static save(o, options = null) {
return super.save(o, options).then((result) => {