Skip to content

Commit

Permalink
Updated tests for Drive v3
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Dec 29, 2024
1 parent 928d82c commit 367b4e3
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 452 deletions.
8 changes: 4 additions & 4 deletions __tests__/backend/listFolders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ test("listFolders works correctly", () => {

const rawResponse = {
files: [
{ id: "ID1", title: "FOLDER1" },
{ id: "ID2", title: "FOLDER2" },
{ id: "ID1", name: "FOLDER1" },
{ id: "ID2", name: "FOLDER2" },
],
nextPageToken: undefined,
};
Expand Down Expand Up @@ -78,12 +78,12 @@ test("listFolders works correctly with shortcuts", () => {
{
id: "ID1",
mimeType: "application/vnd.google-apps.shortcut",
name: "FOLDER1",
shortcutDetails: {
targetId: "TRUE_ID1",
},
title: "FOLDER1",
},
{ id: "ID2", title: "FOLDER2" },
{ id: "ID2", name: "FOLDER2" },
],
nextPageToken: undefined,
};
Expand Down
2 changes: 1 addition & 1 deletion __tests__/backend/listSharedDrives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test("listSharedDrives works correctly", () => {
{ id: "ID2", name: "DRIVE2" },
];
const rawResponse = {
items: response,
drives: response,
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Drives.list.mockReturnValueOnce(rawResponse);
Expand Down
74 changes: 37 additions & 37 deletions __tests__/backend/move/copyFileComments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ test("copyFileComments works correctly", () => {
}

const rawResponse = {
items: [
comments: [
{
author: { displayName: "COM1_AUTH", isAuthenticatedUser: false },
commentId: "SRC_COM1_ID",
author: { displayName: "COM1_AUTH", me: false },
content: "COM1_CONTENT",
id: "SRC_COM1_ID",
replies: [],
},
{
author: { displayName: "COM2_AUTH", isAuthenticatedUser: true },
commentId: "SRC_COM2_ID",
author: { displayName: "COM2_AUTH", me: true },
content: "COM2_CONTENT",
id: "SRC_COM2_ID",
replies: [],
},
],
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Comments.insert
driveServiceMock.Comments.create
.mockReturnValueOnce({
author: { displayName: "COM2_AUTH", isAuthenticatedUser: true },
commentId: "DEST_COM1_ID",
author: { displayName: "COM2_AUTH", me: true },
content: "*COM1_AUTH:*\nCOM1_CONTENT",
id: "DEST_COM1_ID",
replies: [],
})
.mockReturnValueOnce({
author: { displayName: "COM2_AUTH", isAuthenticatedUser: true },
commentId: "DEST_COM2_ID",
author: { displayName: "COM2_AUTH", me: true },
content: "COM2_CONTENT",
id: "DEST_COM2_ID",
replies: [],
});
driveServiceMock.Comments.list.mockReturnValueOnce(rawResponse);
Expand All @@ -63,23 +63,23 @@ test("copyFileComments works correctly", () => {
?.split(",")
.map((s) => s.trim()),
).toContain("nextPageToken");
expect(driveServiceMock.Comments.insert.mock.calls).toHaveLength(2);
expect(driveServiceMock.Comments.insert.mock.calls[0][0].content).toBe(
expect(driveServiceMock.Comments.create.mock.calls).toHaveLength(2);
expect(driveServiceMock.Comments.create.mock.calls[0][0].content).toBe(
"*COM1_AUTH:*\nCOM1_CONTENT",
);
expect(
driveServiceMock.Comments.insert.mock.calls[0][0].replies,
driveServiceMock.Comments.create.mock.calls[0][0].replies,
).toStrictEqual([]);
expect(driveServiceMock.Comments.insert.mock.calls[0][1]).toBe(
expect(driveServiceMock.Comments.create.mock.calls[0][1]).toBe(
"DEST_FILE_ID",
);
expect(driveServiceMock.Comments.insert.mock.calls[1][0].content).toBe(
expect(driveServiceMock.Comments.create.mock.calls[1][0].content).toBe(
"COM2_CONTENT",
);
expect(
driveServiceMock.Comments.insert.mock.calls[1][0].replies,
driveServiceMock.Comments.create.mock.calls[1][0].replies,
).toStrictEqual([]);
expect(driveServiceMock.Comments.insert.mock.calls[1][1]).toBe(
expect(driveServiceMock.Comments.create.mock.calls[1][1]).toBe(
"DEST_FILE_ID",
);
});
Expand All @@ -92,18 +92,18 @@ test("copyFileComments works correctly with replies", () => {
}

const rawResponse = {
items: [
comments: [
{
author: { displayName: "COM_AUTH", isAuthenticatedUser: true },
commentId: "SRC_COM_ID",
author: { displayName: "COM_AUTH", me: true },
content: "COM_CONTENT",
id: "SRC_COM_ID",
replies: [
{
author: { displayName: "REPLY1_AUTH", isAuthenticatedUser: false },
author: { displayName: "REPLY1_AUTH", me: false },
content: "REPLY1_CONTENT",
},
{
author: { displayName: "REPLY2_AUTH", isAuthenticatedUser: true },
author: { displayName: "REPLY2_AUTH", me: true },
content: "REPLY2_CONTENT",
},
],
Expand All @@ -112,14 +112,14 @@ test("copyFileComments works correctly with replies", () => {
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Comments.insert.mockReturnValueOnce({
author: { displayName: "COM_AUTH", isAuthenticatedUser: true },
commentId: "DEST_COM_ID",
driveServiceMock.Comments.create.mockReturnValueOnce({
author: { displayName: "COM_AUTH", me: true },
content: "COM_CONTENT",
id: "DEST_COM_ID",
replies: [],
});
driveServiceMock.Comments.list.mockReturnValueOnce(rawResponse);
driveServiceMock.Replies.insert.mockReturnValueOnce({});
driveServiceMock.Replies.create.mockReturnValueOnce({});

copyFileComments_("SRC_FILE_ID", "DEST_FILE_ID", driveServiceMock);

Expand All @@ -141,25 +141,25 @@ test("copyFileComments works correctly with replies", () => {
?.split(",")
.map((s) => s.trim()),
).toContain("nextPageToken");
expect(driveServiceMock.Comments.insert.mock.calls).toHaveLength(1);
expect(driveServiceMock.Comments.insert.mock.calls[0][0].content).toBe(
expect(driveServiceMock.Comments.create.mock.calls).toHaveLength(1);
expect(driveServiceMock.Comments.create.mock.calls[0][0].content).toBe(
"COM_CONTENT",
);
expect(
driveServiceMock.Comments.insert.mock.calls[0][0].replies,
driveServiceMock.Comments.create.mock.calls[0][0].replies,
).toStrictEqual([]);
expect(driveServiceMock.Comments.insert.mock.calls[0][1]).toBe(
expect(driveServiceMock.Comments.create.mock.calls[0][1]).toBe(
"DEST_FILE_ID",
);
expect(driveServiceMock.Replies.insert.mock.calls).toHaveLength(2);
expect(driveServiceMock.Replies.insert.mock.calls[0][0].content).toBe(
expect(driveServiceMock.Replies.create.mock.calls).toHaveLength(2);
expect(driveServiceMock.Replies.create.mock.calls[0][0].content).toBe(
"*REPLY1_AUTH:*\nREPLY1_CONTENT",
);
expect(driveServiceMock.Replies.insert.mock.calls[0][1]).toBe("DEST_FILE_ID");
expect(driveServiceMock.Replies.insert.mock.calls[0][2]).toBe("DEST_COM_ID");
expect(driveServiceMock.Replies.insert.mock.calls[1][0].content).toBe(
expect(driveServiceMock.Replies.create.mock.calls[0][1]).toBe("DEST_FILE_ID");
expect(driveServiceMock.Replies.create.mock.calls[0][2]).toBe("DEST_COM_ID");
expect(driveServiceMock.Replies.create.mock.calls[1][0].content).toBe(
"REPLY2_CONTENT",
);
expect(driveServiceMock.Replies.insert.mock.calls[1][1]).toBe("DEST_FILE_ID");
expect(driveServiceMock.Replies.insert.mock.calls[1][2]).toBe("DEST_COM_ID");
expect(driveServiceMock.Replies.create.mock.calls[1][1]).toBe("DEST_FILE_ID");
expect(driveServiceMock.Replies.create.mock.calls[1][2]).toBe("DEST_COM_ID");
});
34 changes: 17 additions & 17 deletions __tests__/backend/move/folderManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ test("listFilesInFolder works correctly", () => {
supportsAllDrives?: boolean;
}

const items = [
const files = [
{
capabilities: { canMoveItemOutOfDrive: true },
id: "FILE1_ID",
title: "FILE1_TITLE",
name: "FILE1_TITLE",
},
{
capabilities: { canMoveItemOutOfDrive: false },
id: "FILE2_ID",
title: "FILE2_TITLE",
name: "FILE2_TITLE",
},
];
const rawResponse = {
items,
files,
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Files.list.mockReturnValueOnce(rawResponse);

expect(listFilesInFolder_("FOLDER_ID", driveServiceMock)).toStrictEqual(
items,
files,
);

expect(driveServiceMock.Files.list.mock.calls).toHaveLength(1);
Expand All @@ -63,7 +63,7 @@ test("listFilesInFolder works correctly", () => {
expect(driveServiceMock.Files.list.mock.calls[0][0]).toStrictEqual({
capabilities: { canMoveItemOutOfDrive: true },
id: true,
title: true,
name: true,
});
});

Expand All @@ -76,27 +76,27 @@ test("listFoldersInFolder works correctly", () => {
supportsAllDrives?: boolean;
}

const items = [
const files = [
{
capabilities: { canMoveItemOutOfDrive: true },
id: "FILE1_ID",
title: "FILE1_TITLE",
name: "FILE1_TITLE",
},
{
capabilities: { canMoveItemOutOfDrive: false },
id: "FILE2_ID",
title: "FILE2_TITLE",
name: "FILE2_TITLE",
},
];
const rawResponse = {
items,
files,
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Files.list.mockReturnValueOnce(rawResponse);

expect(listFoldersInFolder_("FOLDER_ID", driveServiceMock)).toStrictEqual(
items,
files,
);

expect(driveServiceMock.Files.list.mock.calls).toHaveLength(1);
Expand All @@ -122,7 +122,7 @@ test("listFoldersInFolder works correctly", () => {
expect(driveServiceMock.Files.list.mock.calls[0][0]).toStrictEqual({
capabilities: { canMoveItemOutOfDrive: true },
id: true,
title: true,
name: true,
});
});

Expand All @@ -135,7 +135,7 @@ test("isFolderEmpty works correctly with an empty folder", () => {
}

const rawResponse = {
items: [],
files: [],
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Files.list.mockReturnValueOnce(rawResponse);
Expand Down Expand Up @@ -165,7 +165,7 @@ test("isFolderEmpty works correctly with a non-empty folder", () => {
}

const rawResponse = {
items: [{ id: "ID_FILE" }],
files: [{ id: "ID_FILE" }],
};
const driveServiceMock = mockedSafeDriveService();
driveServiceMock.Files.list.mockReturnValueOnce(rawResponse);
Expand Down Expand Up @@ -203,7 +203,7 @@ test.each(["owner", "organizer"] as Array<
userPermission: { role },
};
const listResponse = {
items: [],
files: [],
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
Expand Down Expand Up @@ -246,7 +246,7 @@ test("deleteFolderIfEmpty doesn't delete a non-empty folder", () => {
}

const listResponse = {
items: [{ userPermission: { role: "reader" } }],
files: [{ userPermission: { role: "reader" } }],
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
Expand Down Expand Up @@ -288,7 +288,7 @@ test.each(["fileOrganizer", "reader", "writer"] as Array<
userPermission: { role },
};
const listResponse = {
items: [],
files: [],
nextPageToken: undefined,
};
const driveServiceMock = mockedSafeDriveService();
Expand Down
Loading

0 comments on commit 367b4e3

Please sign in to comment.