🪵 Logging file path and verify s3 test (#461)

* feat: logging file path while verifying ci
* fix: files e2e test

---------
Co-authored-by: Monta <monta@HP-ProBook-445-14-inch-G9-Notebook-PC-505aadfc.localdomain>
This commit is contained in:
Montassar Ghanmy
2024-03-15 16:12:09 +01:00
committed by GitHub
parent d856cf4e10
commit f777f55136
2 changed files with 13 additions and 17 deletions
@@ -46,6 +46,7 @@ export default class S3ConnectorService implements StorageConnectorAPI {
let err = null; let err = null;
for (let i = 0; i <= tries; i++) { for (let i = 0; i <= tries; i++) {
try { try {
console.log("🚀🚀 reading s3 object: ", path);
const stat = await this.client.statObject(this.minioConfiguration.bucket, path); const stat = await this.client.statObject(this.minioConfiguration.bucket, path);
if (stat?.size > 0) { if (stat?.size > 0) {
break; break;
@@ -3,11 +3,9 @@ import { afterAll, beforeAll, describe, expect, it } from "@jest/globals";
import { init, TestPlatform } from "../setup"; import { init, TestPlatform } from "../setup";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
import fs from "fs"; import S3ConnectorService from "../../../src/core/platform/services/storage/connectors/S3/s3-service";
import LocalConnectorService from "../../../src/core/platform/services/storage/connectors/local/service";
import UserApi from "../common/user-api"; import UserApi from "../common/user-api";
describe("The Files feature", () => { describe("The Files feature", () => {
const url = "/internal/services/files/v1"; const url = "/internal/services/files/v1";
let platform: TestPlatform; let platform: TestPlatform;
@@ -17,14 +15,17 @@ describe("The Files feature", () => {
platform = await init({ platform = await init({
services: ["webserver", "database", "storage", "files", "previews"], services: ["webserver", "database", "storage", "files", "previews"],
}); });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await platform.database.getConnector().init(); await platform.database.getConnector().init();
helpers = await UserApi.getInstance(platform) helpers = await UserApi.getInstance(platform);
}); });
afterAll(async () => { afterAll(async () => {
await platform?.tearDown(); await platform?.tearDown();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
platform = null; platform = null;
}); });
describe("On user send files", () => { describe("On user send files", () => {
@@ -34,10 +35,9 @@ describe("The Files feature", () => {
//given file //given file
const filesUpload = await helpers.uploadRandomFile(); const filesUpload = await helpers.uploadRandomFile();
expect(filesUpload.id).toBeTruthy(); expect(filesUpload.id).toBeTruthy();
//clean files directory // expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService);
expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService) const path = `tdrive/files/${platform.workspace.company_id}/${platform.currentUser.id}/${filesUpload.id}/chunk1`;
const path = (<LocalConnectorService>platform.storage.getConnector()).configuration.path; await platform.storage.getConnector().remove(path);
fs.readdirSync(path).forEach(f => fs.rmSync(`${path}/${f}`, {recursive: true, force: true}));
//when try to download the file //when try to download the file
const fileDownloadResponse = await platform.app.inject({ const fileDownloadResponse = await platform.app.inject({
method: "GET", method: "GET",
@@ -46,15 +46,14 @@ describe("The Files feature", () => {
//then file should be not found with 404 error and "File not found message" //then file should be not found with 404 error and "File not found message"
expect(fileDownloadResponse).toBeTruthy(); expect(fileDownloadResponse).toBeTruthy();
expect(fileDownloadResponse.statusCode).toBe(500); expect(fileDownloadResponse.statusCode).toBe(500);
}, 120000); }, 120000);
it("Download file should return 200 if file exists", async () => { it("Download file should return 200 if file exists", async () => {
//given file //given file
const filesUpload = await helpers.uploadRandomFile() const filesUpload = await helpers.uploadRandomFile();
expect(filesUpload.id).toBeTruthy(); expect(filesUpload.id).toBeTruthy();
//clean files directory //clean files directory
expect(platform.storage.getConnector()).toBeInstanceOf(LocalConnectorService) // expect(platform.storage.getConnector()).toBeInstanceOf(S3ConnectorService);
//when try to download the file //when try to download the file
const fileDownloadResponse = await platform.app.inject({ 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" //then file should be not found with 404 error and "File not found message"
expect(fileDownloadResponse).toBeTruthy(); expect(fileDownloadResponse).toBeTruthy();
expect(fileDownloadResponse.statusCode).toBe(200); expect(fileDownloadResponse.statusCode).toBe(200);
}, 120000); }, 120000);
it.skip("should save file and generate previews", async () => { it.skip("should save file and generate previews", async () => {
@@ -79,16 +77,13 @@ describe("The Files feature", () => {
for (const thumb of filesUpload.thumbnails) { for (const thumb of filesUpload.thumbnails) {
const thumbnails = await platform.app.inject({ const thumbnails = await platform.app.inject({
headers: {"authorization": `Bearer ${await platform.auth.getJWTToken()}`}, headers: { authorization: `Bearer ${await platform.auth.getJWTToken()}` },
method: "GET", method: "GET",
url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/thumbnails/${thumb.index}`, url: `${url}/companies/${platform.workspace.company_id}/files/${filesUpload.id}/thumbnails/${thumb.index}`,
}); });
expect(thumbnails.statusCode).toBe(200); expect(thumbnails.statusCode).toBe(200);
} }
} }
}, 1200000); }, 1200000);
}); });
}); });