From 5db838bb4124111d4b75472bb25ab9c70bfc9b58 Mon Sep 17 00:00:00 2001 From: Monta Date: Fri, 15 Mar 2024 16:26:11 +0100 Subject: [PATCH] ref: files e2e test --- .../services/storage/connectors/S3/s3-service.ts | 1 - .../node/src/services/files/services/index.ts | 4 ++-- tdrive/backend/node/test/e2e/files/files.spec.ts | 12 +++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tdrive/backend/node/src/core/platform/services/storage/connectors/S3/s3-service.ts b/tdrive/backend/node/src/core/platform/services/storage/connectors/S3/s3-service.ts index 6bbe18ba2..11182817f 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/connectors/S3/s3-service.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/connectors/S3/s3-service.ts @@ -46,7 +46,6 @@ export default class S3ConnectorService implements StorageConnectorAPI { let err = null; for (let i = 0; i <= tries; i++) { try { - console.log("🚀🚀 reading s3 object: ", path); const stat = await this.client.statObject(this.minioConfiguration.bucket, path); if (stat?.size > 0) { break; diff --git a/tdrive/backend/node/src/services/files/services/index.ts b/tdrive/backend/node/src/services/files/services/index.ts index 6c87736fe..63ee95e57 100644 --- a/tdrive/backend/node/src/services/files/services/index.ts +++ b/tdrive/backend/node/src/services/files/services/index.ts @@ -461,8 +461,8 @@ export class FileServiceImpl { } } } -function getFilePath(entity: File): string { +export const getFilePath = (entity: File): string => { return `${gr.platformServices.storage.getHomeDir()}/files/${entity.company_id}/${ entity.user_id || "anonymous" }/${entity.id}`; -} +}; diff --git a/tdrive/backend/node/test/e2e/files/files.spec.ts b/tdrive/backend/node/test/e2e/files/files.spec.ts index 2e4895b2e..e645ce05a 100644 --- a/tdrive/backend/node/test/e2e/files/files.spec.ts +++ b/tdrive/backend/node/test/e2e/files/files.spec.ts @@ -1,9 +1,7 @@ import "reflect-metadata"; import { afterAll, beforeAll, describe, expect, it } from "@jest/globals"; import { init, TestPlatform } from "../setup"; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -import S3ConnectorService from "../../../src/core/platform/services/storage/connectors/S3/s3-service"; +import { getFilePath } from "../../../src/services/files/services"; import UserApi from "../common/user-api"; describe("The Files feature", () => { @@ -33,15 +31,15 @@ describe("The Files feature", () => { it("Download file should return 500 if file doesn't exists", async () => { //given file - const filesUpload = await helpers.uploadRandomFile(); - expect(filesUpload.id).toBeTruthy(); + const fileUpload = await helpers.uploadRandomFile(); + expect(fileUpload.id).toBeTruthy(); // expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService); - const path = `tdrive/files/${platform.workspace.company_id}/${platform.currentUser.id}/${filesUpload.id}/chunk1`; + const path = `${getFilePath(fileUpload)}/chunk1`; await platform.storage.getConnector().remove(path); //when try to download the file const fileDownloadResponse = await platform.app.inject({ method: "GET", - url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/download`, + url: `${url}/companies/${platform.workspace.company_id}/files/${fileUpload.id}/download`, }); //then file should be not found with 404 error and "File not found message" expect(fileDownloadResponse).toBeTruthy();