core: make sure all tests are passing

This commit is contained in:
Abdullah Atta
2023-08-30 10:42:24 +05:00
committed by Abdullah Atta
parent fb26229715
commit a700787cf3
5 changed files with 85 additions and 46 deletions

View File

@@ -26,11 +26,14 @@ export default class Content extends Collection {
async add(content) {
if (!content) return;
if (
!!content.data &&
(!!content.data.data || (!content.data.iv && !content.data.cipher))
) {
if (content.data.data && content.data.data.length)
if (content.remote)
throw new Error(
"Please do not use this method for merging. Instead add the item directly to database."
);
if (content.deleted) return await this._collection.addItem(content);
if (typeof content.data === "object") {
if (typeof content.data.data === "string")
content.data = content.data.data;
else if (!content.data.iv && !content.data.cipher)
content.data = `<p>Content is invalid: ${JSON.stringify(

View File

@@ -66,10 +66,14 @@ class Migrator {
);
if (migrated || restore) {
if (collection.dbCollection.merge) {
if (collection.type === "settings") {
await collection.dbCollection.merge(item);
} else if (collection.dbCollection.add) {
await collection.dbCollection.add(item);
} else if (collection.dbCollection._collection) {
await collection.dbCollection._collection?.addItem(item);
} else {
throw new Error(
`No idea how to handle this kind of item: ${item.type}.`
);
}
// if id changed after migration, we need to delete the old one.