fix: some notes from backup not being restored

This commit is contained in:
thecodrr
2020-12-29 14:08:48 +05:00
parent e2025822d2
commit 5bb50b4e80
7 changed files with 8 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@@ -9,6 +9,7 @@ import v2Backup from "./__fixtures__/backup.v2.json";
import v3Backup from "./__fixtures__/backup.v3.json";
import v4Backup from "./__fixtures__/backup.v4.json";
import v42Backup from "./__fixtures__/backup.v4.2.json";
import v43Backup from "./__fixtures__/backup.v4.3.json";
beforeEach(() => {
StorageInterface.clear();
@@ -74,6 +75,7 @@ describe.each([
["v3", v3Backup],
["v4", v4Backup],
["v4.2", v42Backup],
["v4.3", v43Backup],
])("testing backup version: %s", (version, data) => {
test(`import ${version} backup`, () => {
return databaseTest().then(async (db) => {

View File

@@ -97,7 +97,7 @@ test("delete note from edited topic", () =>
})
));
test.only("editing one topic should not update dateEdited of all", () =>
test("editing one topic should not update dateEdited of all", () =>
notebookTest().then(async ({ db, id }) => {
let topics = db.notebooks.notebook(id).topics;

View File

@@ -44,8 +44,6 @@ const MAX_ITEMS = 5;
const tests = [
getMainCollectionParams("notes", TEST_NOTE),
getMainCollectionParams("notebooks", TEST_NOTEBOOK),
getTagsCollectionParams("tags", "someTag"),
getTagsCollectionParams("colors", "red"),
getMainCollectionParams("trash", {
id: 2141,
type: "note",

View File

@@ -39,8 +39,6 @@ test("null server response should return false", async () => {
const tests = [
mainCollectionParams("notes", "note", TEST_NOTE),
mainCollectionParams("notebooks", "notebook", TEST_NOTEBOOK),
tagsCollectionParams("tags", "someTag", "tag"),
tagsCollectionParams("colors", "red", "tag"),
];
describe.each(tests)(

View File

@@ -39,7 +39,7 @@ export default class Notes extends Collection {
await this._db.colors.add(noteArg.color, id);
}
if (noteArg.tags.length) {
if (noteArg.tags && noteArg.tags.length) {
for (let tag of noteArg.tags) {
await this._db.tags.add(tag, id);
}
@@ -53,7 +53,7 @@ export default class Notes extends Collection {
...noteArg,
};
if (!oldNote && !noteArg.content) return;
if (!oldNote && !noteArg.content && !noteArg.contentId) return;
if (noteArg.content && noteArg.content.data && noteArg.content.type) {
const { type, data, conflicted, resolved } = noteArg.content;

View File

@@ -11,11 +11,13 @@ class Migrator {
collection.index.map(async (id) => {
let item = get(id);
if (!item) return;
if (item.deleted)
return await collection.dbCollection._collection.addItem(item);
const migrate = migrations[version][item.type || id];
if (migrate) item = migrate(item);
if (!!collection.dbCollection.merge) {
await collection.dbCollection.merge(item);
} else {