Skip to content

Commit

Permalink
♻️Added one more testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
shepilov committed May 27, 2024
1 parent 4d1ad08 commit 9b05fff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tdrive/backend/node/src/services/documents/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type DriveItemDetails = {
export type BrowseDetails = DriveItemDetails & { nextPage: Paginable };

export type DriveFileAccessLevel = "read" | "write" | "manage";
export type publicAccessLevel = "write" | "read" | "none";
export type publicAccessLevel = "write" | "read" | "none" | "manage";

export type RootType = "root";
export type TrashType = "trash";
Expand Down
20 changes: 19 additions & 1 deletion tdrive/backend/node/test/e2e/common/user-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "./entities/mock_entities";
import { logger } from "../../../src/core/platform/framework";
import { expect } from "@jest/globals";
import { publicAccessLevel } from "../../../src/services/documents/types";
import { DriveFileAccessLevel, publicAccessLevel } from "../../../src/services/documents/types";
import { UserQuota } from "../../../src/services/user/web/types";
import { Api } from "../utils.api";
import { OidcJwtVerifier } from "../../../src/services/console/clients/remote-jwks-verifier";
Expand Down Expand Up @@ -285,6 +285,23 @@ export default class UserApi {
});
}

async shareWithPublicLinkWithOkCheck(doc: Partial<DriveFile> & { id: string }, accessLevel: publicAccessLevel) {
const shareResponse = await this.shareWithPublicLink(doc, accessLevel);
expect(shareResponse.statusCode).toBe(200);
return deserialize<DriveFile>(DriveFile, shareResponse.body);
}

async shareWithPermissions(doc: Partial<DriveFile> & { id: string }, toUserId: string, permissions: DriveFileAccessLevel) {
doc.access_info.entities.push({
type: "user",
id: toUserId,
level: permissions,
grantor: null,
});
console.log(`INFO:: ${doc.access_info}`);
return await this.updateDocument(doc.id, doc);
}

async getPublicLinkAccessToken(doc: Partial<DriveFile>) {
const accessRes = await this.platform.app.inject({
method: "POST",
Expand Down Expand Up @@ -435,6 +452,7 @@ export default class UserApi {
expect(response.statusCode).toBe(200);
const doc = deserialize<DriveItemDetailsMockClass>(DriveItemDetailsMockClass, response.body);
expect(doc.item?.id).toBe(id);
return doc;
};

async getFolderOKCheck(id: string | "root" | "trash" | "shared_with_me") {
Expand Down
23 changes: 22 additions & 1 deletion tdrive/backend/node/test/e2e/documents/trash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,28 @@ describe("the Drive's documents' trash feature", () => {
const deletionToTrashResponse = await currentUser.delete(anonymouslyUploadedDoc.id);
expect(deletionToTrashResponse.statusCode).toBe(200);

expect((await getTrashContentIds()).indexOf(anonymouslyUploadedDoc.id)).toBeGreaterThanOrEqual(0);
expect((await getTrashContentIds())).toContain(anonymouslyUploadedDoc.id);
});

it("If anonymous user deletes the files in should be in the users trash", async () => {
const publiclyWriteableFolder = await currentUser.createDirectory();
const anonymousUser = await UserApi.getInstance(platform);

const setPublicWriteableResponse = await currentUser.shareWithPublicLink(publiclyWriteableFolder, "manage");
expect(setPublicWriteableResponse.statusCode).toBe(200);

anonymousUser.jwt = (await anonymousUser.getPublicLinkAccessToken(publiclyWriteableFolder)).value;
const anonymouslyUploadedDoc = await anonymousUser.uploadRandomFileAndCreateDocument(publiclyWriteableFolder.id);

const deletionToTrashResponse = await anonymousUser.delete(anonymouslyUploadedDoc.id);
expect(deletionToTrashResponse.statusCode).toBe(200);

expect((await getTrashContentIds())).toContain(anonymouslyUploadedDoc.id);
});

it("if another user deletes the files it should be in the users trash", async () => {
//TODO
});

});
});

0 comments on commit 9b05fff

Please sign in to comment.