From f777f55136f8a56b0c818502030baf6509c90be4 Mon Sep 17 00:00:00 2001 From: Montassar Ghanmy Date: Fri, 15 Mar 2024 16:12:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B5=20Logging=20file=20path=20and=20ve?= =?UTF-8?q?rify=20s3=20test=20(#461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: logging file path while verifying ci * fix: files e2e test --------- Co-authored-by: Monta --- .../storage/connectors/S3/s3-service.ts | 1 + .../backend/node/test/e2e/files/files.spec.ts | 29 ++++++++----------- 2 files changed, 13 insertions(+), 17 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 11182817..6bbe18ba 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,6 +46,7 @@ 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/test/e2e/files/files.spec.ts b/tdrive/backend/node/test/e2e/files/files.spec.ts index 32336ba2..2e4895b2 100644 --- a/tdrive/backend/node/test/e2e/files/files.spec.ts +++ b/tdrive/backend/node/test/e2e/files/files.spec.ts @@ -3,11 +3,9 @@ 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 fs from "fs"; -import LocalConnectorService from "../../../src/core/platform/services/storage/connectors/local/service"; +import S3ConnectorService from "../../../src/core/platform/services/storage/connectors/S3/s3-service"; import UserApi from "../common/user-api"; - describe("The Files feature", () => { const url = "/internal/services/files/v1"; let platform: TestPlatform; @@ -17,14 +15,17 @@ describe("The Files feature", () => { platform = await init({ services: ["webserver", "database", "storage", "files", "previews"], }); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore await platform.database.getConnector().init(); - helpers = await UserApi.getInstance(platform) + helpers = await UserApi.getInstance(platform); }); afterAll(async () => { await platform?.tearDown(); + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore platform = null; - }); describe("On user send files", () => { @@ -34,10 +35,9 @@ describe("The Files feature", () => { //given file const filesUpload = await helpers.uploadRandomFile(); expect(filesUpload.id).toBeTruthy(); - //clean files directory - expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService) - const path = (platform.storage.getConnector()).configuration.path; - fs.readdirSync(path).forEach(f => fs.rmSync(`${path}/${f}`, {recursive: true, force: true})); + // expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService); + const path = `tdrive/files/${platform.workspace.company_id}/${platform.currentUser.id}/${filesUpload.id}/chunk1`; + await platform.storage.getConnector().remove(path); //when try to download the file const fileDownloadResponse = await platform.app.inject({ method: "GET", @@ -46,15 +46,14 @@ describe("The Files feature", () => { //then file should be not found with 404 error and "File not found message" expect(fileDownloadResponse).toBeTruthy(); expect(fileDownloadResponse.statusCode).toBe(500); - }, 120000); it("Download file should return 200 if file exists", async () => { //given file - const filesUpload = await helpers.uploadRandomFile() + const filesUpload = await helpers.uploadRandomFile(); expect(filesUpload.id).toBeTruthy(); //clean files directory - expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService) + // expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService); //when try to download the file const fileDownloadResponse = await platform.app.inject({ @@ -64,7 +63,6 @@ describe("The Files feature", () => { //then file should be not found with 404 error and "File not found message" expect(fileDownloadResponse).toBeTruthy(); expect(fileDownloadResponse.statusCode).toBe(200); - }, 120000); it.skip("should save file and generate previews", async () => { @@ -79,16 +77,13 @@ describe("The Files feature", () => { for (const thumb of filesUpload.thumbnails) { const thumbnails = await platform.app.inject({ - headers: {"authorization": `Bearer ${await platform.auth.getJWTToken()}`}, + headers: { authorization: `Bearer ${await platform.auth.getJWTToken()}` }, method: "GET", url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/thumbnails/${thumb.index}`, }); expect(thumbnails.statusCode).toBe(200); } } - - }, 1200000); }); }); -