✅♻️⚰️ back: add e2e test for trashing anonymously uploaded files, deleted e2e_deleteDocument (#433)
This commit is contained in:
committed by
ericlinagora
parent
882120bef0
commit
f228e07373
@@ -7,7 +7,6 @@ import { TestDbService } from "../utils.prepare.db";
|
||||
import {
|
||||
e2e_createDocumentFile,
|
||||
e2e_createVersion,
|
||||
e2e_deleteDocument,
|
||||
e2e_updateDocument,
|
||||
} from "./utils";
|
||||
import UserApi from "../common/user-api";
|
||||
@@ -68,22 +67,12 @@ describe("the Drive feature", () => {
|
||||
expect(result.item.name).toEqual("Shared Drive");
|
||||
});
|
||||
|
||||
it("did fetch the trash", async () => {
|
||||
await TestDbService.getInstance(platform, true);
|
||||
|
||||
const response = await currentUser.getDocument("trash");
|
||||
const result = deserialize<DriveItemDetailsMockClass>(DriveItemDetailsMockClass, response.body);
|
||||
|
||||
expect(result.item.id).toEqual("trash");
|
||||
expect(result.item.name).toEqual("Trash");
|
||||
});
|
||||
|
||||
it("did delete an item", async () => {
|
||||
const createItemResult = await currentUser.createDefaultDocument();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
|
||||
const deleteResponse = await e2e_deleteDocument(platform, createItemResult.id);
|
||||
const deleteResponse = await currentUser.delete(createItemResult.id);
|
||||
expect(deleteResponse.statusCode).toEqual(200);
|
||||
});
|
||||
|
||||
@@ -122,25 +111,6 @@ describe("the Drive feature", () => {
|
||||
expect(zipResponse.body.length).toBeGreaterThanOrEqual(100);
|
||||
});
|
||||
|
||||
it("did move an item to trash", async () => {
|
||||
const createItemResult = await currentUser.createDefaultDocument();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
|
||||
const moveToTrashResponse = await e2e_deleteDocument(platform, createItemResult.id);
|
||||
expect(moveToTrashResponse.statusCode).toEqual(200);
|
||||
|
||||
const listTrashResponse = await currentUser.getDocument("trash");
|
||||
const listTrashResult = deserialize<DriveItemDetailsMockClass>(
|
||||
DriveItemDetailsMockClass,
|
||||
listTrashResponse.body,
|
||||
);
|
||||
expect(listTrashResult.item.name).toEqual("Trash");
|
||||
expect(createItemResult).toBeDefined();
|
||||
expect(createItemResult.scope).toEqual("shared");
|
||||
expect(listTrashResult.children.some(({ id }) => id === createItemResult.id)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("did create a version for a drive item", async () => {
|
||||
const item = await currentUser.createDefaultDocument();
|
||||
const fileUploadResponse = await e2e_createDocumentFile(platform);
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import { describe, beforeAll, it, expect, afterAll } from "@jest/globals";
|
||||
import { deserialize } from "class-transformer";
|
||||
import type { DriveFile } from "../../../src/services/documents/entities/drive-file";
|
||||
import { init, TestPlatform } from "../setup";
|
||||
import { TestDbService } from "../utils.prepare.db";
|
||||
import UserApi from "../common/user-api";
|
||||
import {
|
||||
DriveItemDetailsMockClass,
|
||||
} from "../common/entities/mock_entities";
|
||||
|
||||
describe("the Drive's documents' trash feature", () => {
|
||||
let platform: TestPlatform | null;
|
||||
let currentUser: UserApi;
|
||||
|
||||
beforeAll(async () => {
|
||||
platform = await init({
|
||||
services: [
|
||||
"webserver",
|
||||
"database",
|
||||
"applications",
|
||||
"search",
|
||||
"storage",
|
||||
"message-queue",
|
||||
"user",
|
||||
"search",
|
||||
"files",
|
||||
"websocket",
|
||||
"messages",
|
||||
"auth",
|
||||
"realtime",
|
||||
"channels",
|
||||
"counter",
|
||||
"statistics",
|
||||
"platform-services",
|
||||
"documents",
|
||||
],
|
||||
});
|
||||
currentUser = await UserApi.getInstance(platform);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await platform?.tearDown();
|
||||
platform = null;
|
||||
});
|
||||
|
||||
it("did fetch the trash", async () => {
|
||||
await TestDbService.getInstance(platform!, true);
|
||||
|
||||
const response = await currentUser.getDocument("trash");
|
||||
const result = deserialize<DriveItemDetailsMockClass>(DriveItemDetailsMockClass, response.body);
|
||||
|
||||
expect(result.item.id).toEqual("trash");
|
||||
expect(result.item.name).toEqual("Trash");
|
||||
});
|
||||
|
||||
it("did move an item to trash", async () => {
|
||||
const createItemResult = await currentUser.createDefaultDocument();
|
||||
|
||||
expect(createItemResult.id).toBeDefined();
|
||||
|
||||
const moveToTrashResponse = await currentUser.delete(createItemResult.id);
|
||||
expect(moveToTrashResponse.statusCode).toEqual(200);
|
||||
|
||||
const listTrashResponse = await currentUser.getDocument("trash");
|
||||
const listTrashResult = deserialize<DriveItemDetailsMockClass>(
|
||||
DriveItemDetailsMockClass,
|
||||
listTrashResponse.body,
|
||||
);
|
||||
expect(listTrashResult.item.name).toEqual("Trash");
|
||||
expect(createItemResult).toBeDefined();
|
||||
expect(createItemResult.scope).toEqual("shared");
|
||||
expect(listTrashResult.children.some(({ id }) => id === createItemResult.id)).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("deleting a file uploaded by an anonymous user should go to the sharers trash", () => {
|
||||
async function getTrashContentIds() {
|
||||
const listTrashResponse = await currentUser.getDocument("trash");
|
||||
expect(listTrashResponse.statusCode).toBe(200);
|
||||
const listTrashResult = deserialize<DriveItemDetailsMockClass>(
|
||||
DriveItemDetailsMockClass,
|
||||
listTrashResponse.body,
|
||||
);
|
||||
return listTrashResult.children.map(({id}) => id);
|
||||
}
|
||||
|
||||
async function uploadFileAsAnonymousUser(destinationSharedFolder: DriveFile) {
|
||||
const publicToken = await currentUser.getPublicLinkAccessToken(destinationSharedFolder);
|
||||
expect(publicToken?.value?.length ?? "").toBeGreaterThan(0);
|
||||
return await currentUser.impersonateWithJWT(publicToken.value, () =>
|
||||
currentUser.createDefaultDocument({
|
||||
parent_id: destinationSharedFolder.id,
|
||||
}));
|
||||
}
|
||||
|
||||
it("finds the owner from the immediate parent folder", async () => {
|
||||
const publiclyWriteableFolder = await currentUser.createDirectory();
|
||||
const setPublicWriteableResponse = await currentUser.shareWithPublicLink(publiclyWriteableFolder, "write");
|
||||
expect(setPublicWriteableResponse.statusCode).toBe(200);
|
||||
|
||||
const anonymouslyUploadedDoc = await uploadFileAsAnonymousUser(publiclyWriteableFolder);
|
||||
|
||||
const deletionToTrashResponse = await currentUser.delete(anonymouslyUploadedDoc.id);
|
||||
expect(deletionToTrashResponse.statusCode).toBe(200);
|
||||
|
||||
expect((await getTrashContentIds()).indexOf(anonymouslyUploadedDoc.id)).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,18 +6,6 @@ import * as fs from "fs";
|
||||
|
||||
const url = "/internal/services/documents/v1";
|
||||
|
||||
export const e2e_deleteDocument = async (platform: TestPlatform, id: string | "root" | "trash") => {
|
||||
const token = await platform.auth.getJWTToken();
|
||||
|
||||
return await platform.app.inject({
|
||||
method: "DELETE",
|
||||
url: `${url}/companies/${platform.workspace.company_id}/item/${id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const e2e_updateDocument = async (
|
||||
platform: TestPlatform,
|
||||
id: string | "root" | "trash",
|
||||
@@ -35,7 +23,6 @@ export const e2e_updateDocument = async (
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const e2e_createVersion = async (
|
||||
platform: TestPlatform,
|
||||
id: string,
|
||||
|
||||
Reference in New Issue
Block a user