diff --git a/__tests__/test-utils/gas-stubs.ts b/__tests__/test-utils/gas-stubs.ts index 9f4f91a1..46bc30dc 100644 --- a/__tests__/test-utils/gas-stubs.ts +++ b/__tests__/test-utils/gas-stubs.ts @@ -1,33 +1,29 @@ import { jest } from "@jest/globals"; -/* eslint-disable @typescript-eslint/naming-convention -- These are stubs for external functions */ +/* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any -- These are stubs for external functions */ export function mockedCommentsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.CommentsCollection { return { - get: jest.fn< - ( - fileId: string, - commentId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment - >(), - insert: + create: jest.fn< ( resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, fileId: string, ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment >(), + get: jest.fn< + ( + fileId: string, + commentId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment + >(), list: jest.fn< - (fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentList + ( + fileId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentList >(), - patch: - jest.fn< - ( - resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment, - fileId: string, - commentId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment - >(), remove: jest.fn<(fileId: string, commentId: string) => void>(), update: jest.fn< @@ -42,40 +38,88 @@ export function mockedCommentsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.C export function mockedDrive(): GoogleAppsScript.Drive { return { - newChannel: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel>(), - newChildReference: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ChildReference>(), - newComment: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment>(), - newCommentContext: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentContext>(), - newCommentReply: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply>(), + About: mockedAboutCollection(), + Apps: mockedAppsCollection(), + Changes: mockedChangesCollection(), + Channels: mockedChannelsCollection(), + Comments: mockedCommentsCollection(), + Drives: mockedDrivesCollection(), + Files: mockedFilesCollection(), + newChannel: + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel>(), + newComment: + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Comment>(), + newCommentQuotedFileContent: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentQuotedFileContent + >(), + newContentRestriction: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ContentRestriction + >(), newDrive: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), newDriveBackgroundImageFile: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveBackgroundImageFile>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveBackgroundImageFile + >(), newDriveCapabilities: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveCapabilities>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveCapabilities + >(), newDriveRestrictions: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveRestrictions>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveRestrictions + >(), newFile: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), newFileCapabilities: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileCapabilities>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileCapabilities + >(), + newFileContentHints: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileContentHints + >(), + newFileContentHintsThumbnail: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileContentHintsThumbnail + >(), newFileImageMediaMetadata: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileImageMediaMetadata>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileImageMediaMetadata + >(), newFileImageMediaMetadataLocation: jest.fn< () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileImageMediaMetadataLocation >(), - newFileIndexableText: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileIndexableText>(), - newFileLabels: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileLabels>(), - newFileThumbnail: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileThumbnail>(), + newFileLabelInfo: + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileLabelInfo>(), + newFileLinkShareMetadata: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileLinkShareMetadata + >(), + newFileShortcutDetails: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileShortcutDetails + >(), newFileVideoMediaMetadata: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileVideoMediaMetadata>(), - newParentReference: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ParentReference>(), - newPermission: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileVideoMediaMetadata + >(), + newLabel: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Label>(), + newLabelFieldModification: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.LabelFieldModification + >(), + newLabelModification: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.LabelModification + >(), + newModifyLabelsRequest: + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ModifyLabelsRequest + >(), + newPermission: + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission>(), newPermissionPermissionDetails: jest.fn< () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.PermissionPermissionDetails @@ -84,41 +128,68 @@ export function mockedDrive(): GoogleAppsScript.Drive { jest.fn< () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.PermissionTeamDrivePermissionDetails >(), - newProperty: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Property>(), - newRevision: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Revision>(), - newTeamDrive: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive>(), + newReply: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply>(), + newRevision: + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Revision>(), + newTeamDrive: + jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive>(), newTeamDriveBackgroundImageFile: jest.fn< () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveBackgroundImageFile >(), newTeamDriveCapabilities: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveCapabilities>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveCapabilities + >(), newTeamDriveRestrictions: - jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveRestrictions>(), + jest.fn< + () => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveRestrictions + >(), newUser: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.User>(), - newUserPicture: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.UserPicture>(), + Operation: mockedOperationCollection(), + Operations: mockedOperationsCollection(), + Permissions: mockedPermissionsCollection(), + Replies: mockedRepliesCollection(), + Revisions: mockedRevisionsCollection(), + Teamdrives: mockedTeamdrivesCollection(), }; } export function mockedDrivesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.DrivesCollection { return { - get: jest.fn<(driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), - hide: jest.fn<(driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), - insert: + create: jest.fn< ( resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive, requestId: string, ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive >(), - list: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveList>(), - remove: jest.fn<(driveId: string) => void>(), - unhide: jest.fn<(driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive>(), + get: jest.fn< + ( + driveId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive + >(), + hide: jest.fn< + (driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive + >(), + list: jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.DriveList + >(), + remove: + jest.fn<(driveId: string, optionalArgs?: Record) => void>(), + unhide: + jest.fn< + (driveId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive + >(), update: jest.fn< ( resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive, driveId: string, + optionalArgs?: Record, ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Drive >(), }; @@ -130,48 +201,70 @@ export function mockedFilesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Coll ( resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, + optionalArgs?: Record, ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File >(), - emptyTrash: jest.fn<() => void>(), + create: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, + mediaData?: GoogleAppsScript.Base.Blob, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File + >(), + download: + jest.fn< + ( + fileId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Operation + >(), + emptyTrash: jest.fn<(optionalArgs?: Record) => void>(), export: jest.fn<(fileId: string, mimeType: string) => void>(), - generateIds: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.GeneratedIds>(), + generateIds: + jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.GeneratedIds + >(), get: jest.fn() as { ( fileId: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- From upstream types optionalArgs?: Record & { alt: "media" }, ): string; ( fileId: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- From upstream types optionalArgs?: Record, ): GoogleAppsScript.Drive_v3.Drive.V3.Schema.File; }, - insert: + list: jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileList + >(), + listLabels: jest.fn< ( - resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, - mediaData?: Blob, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File + fileId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.LabelList >(), - list: jest.fn<() => GoogleAppsScript.Drive_v3.Drive.V3.Schema.FileList>(), - patch: + modifyLabels: jest.fn< ( - resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.ModifyLabelsRequest, fileId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ModifyLabelsResponse >(), - remove: jest.fn<(fileId: string) => void>(), - touch: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), - trash: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), - untrash: jest.fn<(fileId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File>(), + remove: + jest.fn<(fileId: string, optionalArgs?: Record) => void>(), update: jest.fn< ( resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.File, fileId: string, - mediaData?: Blob, + mediaData?: GoogleAppsScript.Base.Blob, + optionalArgs?: Record, ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.File >(), watch: @@ -179,6 +272,7 @@ export function mockedFilesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Coll ( resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel, fileId: string, + optionalArgs?: Record, ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel >(), }; @@ -263,46 +357,39 @@ export function mockedHtmlTemplate(): GoogleAppsScript.HTML.HtmlTemplate { export function mockedRepliesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.RepliesCollection { return { + create: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply, + fileId: string, + commentId: string, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply + >(), get: jest.fn< ( fileId: string, commentId: string, replyId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply >(), - insert: - jest.fn< - ( - resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply, - fileId: string, - commentId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply - >(), list: jest.fn< ( fileId: string, commentId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReplyList + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ReplyList >(), - patch: - jest.fn< - ( - resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply, - fileId: string, - commentId: string, - replyId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply - >(), remove: jest.fn<(fileId: string, commentId: string, replyId: string) => void>(), update: jest.fn< ( - resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply, + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply, fileId: string, commentId: string, replyId: string, - ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.CommentReply + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Reply >(), }; } @@ -416,7 +503,6 @@ export function mockedUtilities(): GoogleAppsScript.Utilities.Utilities { format: string, ) => string >(), - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- From Google apps script types formatString: jest.fn<(template: string, ...args: Array) => string>(), getUuid: jest.fn<() => string>(), gzip: jest.fn< @@ -425,9 +511,7 @@ export function mockedUtilities(): GoogleAppsScript.Utilities.Utilities { name?: string, ) => GoogleAppsScript.Base.Blob >(), - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- From Google apps script types jsonParse: jest.fn<(jsonString: string) => any>(), - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- From Google apps script types jsonStringify: jest.fn<(obj: any) => string>(), MacAlgorithm: { HMAC_MD5: 0, @@ -471,4 +555,182 @@ export function mockedUtilities(): GoogleAppsScript.Utilities.Utilities { }; } +function mockedAboutCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.AboutCollection { + return { + get: jest.fn< + ( + optionalArgs: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.About + >(), + }; +} + +function mockedAppsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.AppsCollection { + return { + get: jest.fn< + (appId: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.App + >(), + list: jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.AppList + >(), + }; +} + +function mockedChangesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.ChangesCollection { + return { + getStartPageToken: + jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.StartPageToken + >(), + list: jest.fn< + ( + pageToken: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ChangeList + >(), + watch: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel, + pageToken: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel + >(), + }; +} + +function mockedChannelsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.ChannelsCollection { + return { + stop: jest.fn< + (resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Channel) => void + >(), + }; +} + +function mockedOperationCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.OperationCollection { + return { + cancel: jest.fn<(name: string) => void>(), + remove: jest.fn<(name: string) => void>(), + }; +} + +function mockedOperationsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.OperationsCollection { + return { + get: jest.fn< + (name: string) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Operation + >(), + list: jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.ListOperationsResponse + >(), + }; +} + +function mockedPermissionsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.PermissionsCollection { + return { + create: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission, + fileId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission + >(), + get: jest.fn< + ( + fileId: string, + permissionId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission + >(), + list: jest.fn< + ( + fileId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.PermissionList + >(), + remove: + jest.fn< + ( + fileId: string, + permissionId: string, + optionalArgs?: Record, + ) => void + >(), + update: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission, + fileId: string, + permissionId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Permission + >(), + }; +} + +function mockedRevisionsCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.RevisionsCollection { + return { + get: jest.fn< + ( + fileId: string, + revisionId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Revision + >(), + list: jest.fn< + ( + fileId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.RevisionList + >(), + remove: jest.fn<(fileId: string, revisionId: string) => void>(), + update: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.Revision, + fileId: string, + revisionId: string, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.Revision + >(), + }; +} + +function mockedTeamdrivesCollection(): GoogleAppsScript.Drive_v3.Drive.V3.Collection.TeamdrivesCollection { + return { + create: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive, + requestId: string, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive + >(), + get: jest.fn< + ( + teamDriveId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive + >(), + list: jest.fn< + ( + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDriveList + >(), + remove: jest.fn<(teamDriveId: string) => void>(), + update: + jest.fn< + ( + resource: GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive, + teamDriveId: string, + optionalArgs?: Record, + ) => GoogleAppsScript.Drive_v3.Drive.V3.Schema.TeamDrive + >(), + }; +} + /* eslint-enable */