From 7929c2d12c4b4c4d9c5420bb169dd15b2f4017b5 Mon Sep 17 00:00:00 2001 From: ericlinagora <162304020+ericlinagora@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:01:54 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20backend:=20fix=20bug=20with=20po?= =?UTF-8?q?stgres=20support=20when=20uploading=20files=20(#646)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 backend: fix bug with postgres support when uploading files and e2e fix by @MontaGhanmy (this is a squashed commit) Co-authored-by: Monta --- .../src/services/documents/services/index.ts | 4 +-- .../documents/documents-notifications.spec.ts | 29 +++++++++++++++++-- .../documents-pagination-sorting.spec.ts | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/tdrive/backend/node/src/services/documents/services/index.ts b/tdrive/backend/node/src/services/documents/services/index.ts index 28f32018..e6779ab4 100644 --- a/tdrive/backend/node/src/services/documents/services/index.ts +++ b/tdrive/backend/node/src/services/documents/services/index.ts @@ -227,7 +227,7 @@ export class DocumentsService { if (options?.pagination) { const { page_token, limitStr } = options.pagination; const pageNumber = - dbType === "mongodb" ? parseInt(page_token) : parseInt(page_token) / parseInt(limitStr) + 1; + dbType === "mongodb" ? parseInt(page_token) : parseInt(page_token) / parseInt(limitStr); pagination = new Pagination(`${pageNumber}`, `${limitStr}`, false); } @@ -441,7 +441,7 @@ export class DocumentsService { ); // TODO: notify the user a document has been added to the directory shared with them try { - if (driveItem.parent_id !== "root" && driveItem.parent_id !== "trash") { + if (!isVirtualFolder(driveItem.parent_id)) { const parentItem = await this.repository.findOne( { id: driveItem.parent_id, diff --git a/tdrive/backend/node/test/e2e/documents/documents-notifications.spec.ts b/tdrive/backend/node/test/e2e/documents/documents-notifications.spec.ts index a5993f92..e8b58886 100644 --- a/tdrive/backend/node/test/e2e/documents/documents-notifications.spec.ts +++ b/tdrive/backend/node/test/e2e/documents/documents-notifications.spec.ts @@ -1,6 +1,7 @@ import { describe, beforeEach, it, expect, afterAll, jest } from "@jest/globals"; import { init, TestPlatform } from "../setup"; import UserApi from "../common/user-api"; +import * as utils from "../../../src/services/documents/utils"; import { DocumentsEngine } from "../../../src/services/documents/services/engine"; import EmailPusherClass from "../../../src/core/platform/services/email-pusher"; import { deserialize } from "class-transformer"; @@ -10,6 +11,7 @@ import { e2e_createDocumentFile, e2e_createVersion } from "./utils"; describe("the Drive feature", () => { let platform: TestPlatform; + const isVirtualFolder = jest.spyOn(utils, "isVirtualFolder"); const notifyDocumentShared = jest.spyOn(DocumentsEngine.prototype, "notifyDocumentShared"); const notifyDocumentVersionUpdated = jest.spyOn( DocumentsEngine.prototype, @@ -38,7 +40,7 @@ describe("the Drive feature", () => { "statistics", "platform-services", "documents", - "email-pusher" + "email-pusher", ], }); currentUser = await UserApi.getInstance(platform); @@ -131,10 +133,31 @@ describe("the Drive feature", () => { ); }); + it("Did not attempt to notify the user if the parent folder is a virutal folder.", async () => { + // upload a file + const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" }); + const oneUserDrive = `user_${oneUser.user.id}`; + await oneUser.uploadRandomFileAndCreateDocument(oneUserDrive); + // expect the notification to not be sent + expect(isVirtualFolder).toHaveBeenCalled(); + expect(isVirtualFolder).toHaveReturnedWith(true); + expect(notifyDocumentShared).not.toHaveBeenCalledWith( + expect.objectContaining({ + notificationEmitter: oneUser.user.id, + }), + ); + }); + // Test the email language based on the user's language and the email subject it("Did notify the user after sharing a file in the user's language.", async () => { - const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin", preferences: { language: "en" } }); - const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin", preferences: { language: "fr" }}); + const oneUser = await UserApi.getInstance(platform, true, { + companyRole: "admin", + preferences: { language: "en" }, + }); + const anotherUser = await UserApi.getInstance(platform, true, { + companyRole: "admin", + preferences: { language: "fr" }, + }); //upload files const doc = await oneUser.uploadRandomFileAndCreateDocument(); const doc2 = await anotherUser.uploadRandomFileAndCreateDocument(); diff --git a/tdrive/backend/node/test/e2e/documents/documents-pagination-sorting.spec.ts b/tdrive/backend/node/test/e2e/documents/documents-pagination-sorting.spec.ts index 0ce3eddb..8b5969f3 100644 --- a/tdrive/backend/node/test/e2e/documents/documents-pagination-sorting.spec.ts +++ b/tdrive/backend/node/test/e2e/documents/documents-pagination-sorting.spec.ts @@ -56,7 +56,7 @@ describe("The Documents Browser Window and API", () => { paginate: { page_token, limitStr }, }); expect(docs).toBeDefined(); - expect(docs.children.length).toBeLessThanOrEqual(parseInt(limitStr)); + expect(docs.children).toHaveLength(parseInt(limitStr)); }); it("Should sort documents by name in ascending order", async () => {