From ce77e26cb306a5a50befb24ad2f96b0915e442b3 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Wed, 20 Mar 2024 23:29:42 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Split=20e2e=20testing=20file=20uplo?= =?UTF-8?q?ad=20for=20raw=20requests=20(#418)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/node/test/e2e/common/user-api.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tdrive/backend/node/test/e2e/common/user-api.ts b/tdrive/backend/node/test/e2e/common/user-api.ts index 41999500..61ca55b6 100644 --- a/tdrive/backend/node/test/e2e/common/user-api.ts +++ b/tdrive/backend/node/test/e2e/common/user-api.ts @@ -1,5 +1,6 @@ // @ts-ignore import fs from "fs"; +import { Readable } from 'stream'; import { ResourceUpdateResponse, Workspace } from "../../../src/utils/types"; import { File } from "../../../src/services/files/entities/file"; import { deserialize } from "class-transformer"; @@ -79,18 +80,31 @@ export default class UserApi { return await this.uploadFile(UserApi.ALL_FILES[Math.floor((Math.random() * UserApi.ALL_FILES.length))]); } - async uploadFile(filename: string) { - logger.info(`Upload ${filename} for the user: ${this.user.id}`); - const fullPath = `${__dirname}/assets/${filename}`; + async injectUploadRequest(readable: Readable | string) { + function makeReadableFromString(str: string): Readable { + const result = new Readable(); + result._read = () => {}; + result.push(str); + result.push(null); + return result; + } + if (typeof readable === "string") + readable = makeReadableFromString(readable); const url = "/internal/services/files/v1"; - const form = formAutoContent({ file: fs.createReadStream(fullPath) }); + const form = formAutoContent({ file: readable }); form.headers["authorization"] = `Bearer ${this.jwt}`; - const filesUploadRaw = await this.platform.app.inject({ + return await this.platform.app.inject({ method: "POST", url: `${url}/companies/${this.platform.workspace.company_id}/files?thumbnail_sync=0`, ...form }); + } + + async uploadFile(filename: string) { + logger.info(`Upload ${filename} for the user: ${this.user.id}`); + const fullPath = `${__dirname}/assets/${filename}`; + const filesUploadRaw = await this.injectUploadRequest(fs.createReadStream(fullPath)); const filesUpload: ResourceUpdateResponse = deserialize>( ResourceUpdateResponse,