Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metadata] Persist metadata changes on the DB #190

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/models/MetadataMongoDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export async function updatePublicUserMetadata(

metadataDoc.markModified("stats");
metadataDoc.markModified("node_information");
// await metadataDoc.save();
await metadataDoc.save();

return metadataDoc;
}
Expand Down Expand Up @@ -262,7 +262,7 @@ export async function sendCardToTrash(
metadataDoc.markModified("node_information");
metadataDoc.markModified("trashed_cards");

// await metadataDoc.save();
await metadataDoc.save();

return `Card moved to the trash. <span class="underline_bold_text clickable" onclick="restoreCardFromTrash('${card._id}', '${card.urgency}')">Undo Action</span>`;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ export async function restoreCardFromTrash(
card.tags,
"urgency",
);
// await metadataDoc.save();
await metadataDoc.save();

return `${card.title} has been restored!`;
}
Expand All @@ -320,7 +320,7 @@ export async function deleteCardFromTrash(
}

const metadataDoc = await removeCardFromMetadataTrash(card);
// await metadataDoc.save();
await metadataDoc.save();

return `${card.title} has been permanently deleted!`;
}
Expand Down Expand Up @@ -350,7 +350,7 @@ async function removeCardFromMetadataTrash(
if (cardIdentifier._id in metadataDoc.trashed_cards[0]) {
delete metadataDoc.trashed_cards[0][cardIdentifier._id];
metadataDoc.markModified("trashed_cards");
// await metadataDoc.save();
await metadataDoc.save();
return metadataDoc;
} else {
return Promise.reject("Card wasn't found in the trash");
Expand Down Expand Up @@ -510,7 +510,7 @@ export async function updateUserSettings(
}
metadataDoc.streak.dailyTarget = newUserSettings.dailyTarget;
metadataDoc.markModified("streak");
// await metadataDoc.save();
await metadataDoc.save();
}

return user.save();
Expand Down
42 changes: 41 additions & 1 deletion src/routes/InAppRouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,13 @@ describe("/trpc/updateCard", function() {
});

describe("/trpc/trashCard", function() {
let cardID: string;

this.beforeEach(async () => {
const gUser = await authenticateUser(authDetails);
gCaller = createCaller({ user: gUser });
return await createPublicAndPrivateCards(gUser);
({ samplePublicCardId: cardID } = await createPublicAndPrivateCards(gUser));
return Promise.resolve();
});

it("should use an input parser/validator", function(done) {
Expand All @@ -264,6 +267,43 @@ describe("/trpc/trashCard", function() {
passIfValidationError(e, done);
});
});

describe("when a card is trashed", function() {
this.beforeEach(async () => {
{
const trashedCards = (await gCaller.metadata())[0].trashed_cards;
expect(trashedCards.length).equal(0);
}

await gCaller.trashCard({ _id: cardID });

{
const trashedCards = (await gCaller.metadata())[0].trashed_cards;
expect(trashedCards.length).equal(1);
expect(Object.keys(trashedCards[0])).contains(cardID);
}
});

it("should delete the card via /trpc/deleteCard", async () => {
await gCaller.deleteCard({ _id: cardID });

const trashedCards = (await gCaller.metadata())[0].trashed_cards;
expect(trashedCards).deep.equal([{}]);

const card = await gCaller.fetchCard({ cardID: cardID });
expect(card).to.be.null;
});

it("should restore the card via /trpc/restoreCardFromTrash", async () => {
await gCaller.restoreCardFromTrash({ _id: cardID });

const trashedCards = (await gCaller.metadata())[0].trashed_cards;
expect(trashedCards).deep.equal([{}]);

const card = await gCaller.fetchCard({ cardID: cardID });
expect(card?._id.toString()).to.equal(cardID);
});
});
});

describe("/trpc/deleteCard", function() {
Expand Down
Loading