Files
workavia-drive/tdrive/backend/node/test/e2e/documents/documents-quota.spec.ts
T
Anton SHEPILOV 2884193072 🐛Fix bug with sending files with response stream
Also updated another dependencies and removed old version of the fastify multipart plugin
2024-05-24 11:49:58 +02:00

114 lines
3.6 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";
import { init, TestPlatform } from "../setup";
import UserApi from "../common/user-api";
import config from "config";
import { e2e_createDocumentFile, e2e_createVersion } from "./utils";
import { deserialize } from "class-transformer";
import { ResourceUpdateResponse } from "../../../src/utils/types";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
jest.mock("config");
describe("the Drive feature", () => {
const filesUrl = "/internal/services/files/v1";
let platform: TestPlatform;
let currentUser: UserApi;
let configHasSpy: jest.SpyInstance;
let configGetSpy: jest.SpyInstance;
beforeEach(async () => {
configHasSpy = jest.spyOn(config, "has");
configGetSpy = jest.spyOn(config, "get");
configHasSpy.mockImplementation((setting: string) => {
return jest.requireActual("config").has(setting);
});
configGetSpy.mockImplementation((setting: string) => {
if (setting === "drive.featureUserQuota") {
return true;
}
if (setting === "drive.defaultUserQuota") {
return 1000000;
}
return jest.requireActual("config").get(setting);
});
platform = await init({
services: [
"webserver",
"database",
"applications",
"search",
"storage",
"message-queue",
"user",
"search",
"files",
"messages",
"auth",
"channels",
"counter",
"statistics",
"platform-services",
"documents",
],
});
currentUser = await UserApi.getInstance(platform);
});
afterEach(async () => {
await platform?.tearDown();
platform = null;
configGetSpy.mockRestore();
});
it("did create the drive item with size under quota", async () => {
const result = await currentUser.uploadFileAndCreateDocument("sample.doc");
expect(result).toBeDefined();
});
it("did not upload the drive item with size above quota", async () => {
const item = await currentUser.uploadFile("sample.mp4");
expect(item).toBeDefined();
const result: any = await currentUser.createDocumentFromFile(item);
expect(result).toBeDefined();
expect(result.statusCode).toBe(403);
expect(result.error).toBe("Forbidden");
expect(result.message).toContain("Not enough space");
const fileDownloadResponse = await platform.app.inject({
method: "GET",
url: `${filesUrl}/companies/${platform.workspace.company_id}/files/${item.id}/download`,
});
// make sure the file was removed
expect(fileDownloadResponse).toBeTruthy();
expect(fileDownloadResponse.statusCode).toBe(404);
});
it("did create a version for a drive item", async () => {
const item = await currentUser.createDefaultDocument();
const fileUploadResponse = await e2e_createDocumentFile(
platform,
"../common/assets/sample.mp4",
);
const fileUploadResult: any = deserialize<ResourceUpdateResponse<File>>(
ResourceUpdateResponse,
fileUploadResponse.body,
);
const file_metadata = { external_id: fileUploadResult.resource.id };
const result: any = await e2e_createVersion(platform, item.id, {
filename: "file2",
file_metadata,
});
expect(result).toBeDefined();
expect(result.statusCode).toBe(403);
const fileDownloadResponse = await platform.app.inject({
method: "GET",
url: `${filesUrl}/companies/${platform.workspace.company_id}/files/${item.id}/download`,
});
// make sure the file was removed
expect(fileDownloadResponse).toBeTruthy();
expect(fileDownloadResponse.statusCode).toBe(404);
});
});