diff --git a/tdrive/backend/node/test/e2e/files/files.spec.ts b/tdrive/backend/node/test/e2e/files/files.spec.ts index e645ce05..948433cb 100644 --- a/tdrive/backend/node/test/e2e/files/files.spec.ts +++ b/tdrive/backend/node/test/e2e/files/files.spec.ts @@ -1,8 +1,10 @@ import "reflect-metadata"; -import { afterAll, beforeAll, describe, expect, it } from "@jest/globals"; +import { afterAll, beforeAll, afterEach, describe, expect, it } from "@jest/globals"; import { init, TestPlatform } from "../setup"; import { getFilePath } from "../../../src/services/files/services"; import UserApi from "../common/user-api"; +import LocalConnectorService from "../../../src/core/platform/services/storage/connectors/local/service" +import { Client as MinioClient } from "minio" describe("The Files feature", () => { const url = "/internal/services/files/v1"; @@ -19,6 +21,10 @@ describe("The Files feature", () => { helpers = await UserApi.getInstance(platform); }); + afterEach(async () => { + jest.restoreAllMocks(); + }); + afterAll(async () => { await platform?.tearDown(); // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -46,6 +52,19 @@ describe("The Files feature", () => { expect(fileDownloadResponse.statusCode).toBe(500); }, 120000); + it("should fail an upload POST when the backend storage fails", async () => { + const thrower = () => { + throw new Error(""); + }; + const writeS3Mock = jest.spyOn(MinioClient.prototype, "putObject").mockImplementation(thrower); + const writeLocalMock = jest.spyOn(LocalConnectorService.prototype, "write").mockImplementation(thrower); + // const writeMock = jest.spyOn(platform.storage, "write").mockImplementation(thrower) + const response = await helpers.injectUploadRequest("dummy"); + expect(response).toBeTruthy(); + expect(response.statusCode).toBe(500); + expect(writeS3Mock.mock.calls.length + writeLocalMock.mock.calls.length).toEqual(1); + }, 120000); + it("Download file should return 200 if file exists", async () => { //given file const filesUpload = await helpers.uploadRandomFile();