diff --git a/package-lock.json b/package-lock.json index 88b1e48..faf7476 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,6 @@ "dependencies": { "@octokit/auth-app": "6.0.3", "@octokit/auth-token": "4.0.0", - "@octokit/core": "5.0.2", - "@octokit/plugin-throttling": "8.1.3", "@octokit/types": "12.4.0", "@primer/octicons-react": "19.8.0", "@primer/react": "35.32.2", @@ -23,6 +21,7 @@ "@trpc/server": "10.44.1", "next": "13.5.5", "next-auth": "4.24.5", + "octokit": "^3.1.2", "probot": "12.3.3", "react": "18.2.0", "react-dom": "18.2.0", @@ -1736,6 +1735,76 @@ "node": ">= 8" } }, + "node_modules/@octokit/app": { + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/@octokit/app/-/app-14.0.2.tgz", + "integrity": "sha512-NCSCktSx+XmjuSUVn2dLfqQ9WIYePGP95SDJs4I9cn/0ZkeXcPkaoCLl64Us3dRKL2ozC7hArwze5Eu+/qt1tg==", + "dependencies": { + "@octokit/auth-app": "^6.0.0", + "@octokit/auth-unauthenticated": "^5.0.0", + "@octokit/core": "^5.0.0", + "@octokit/oauth-app": "^6.0.0", + "@octokit/plugin-paginate-rest": "^9.0.0", + "@octokit/types": "^12.0.0", + "@octokit/webhooks": "^12.0.4" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/app/node_modules/@octokit/auth-unauthenticated": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-5.0.1.tgz", + "integrity": "sha512-oxeWzmBFxWd+XolxKTc4zr+h3mt+yofn4r7OfoIkR/Cj/o70eEGmPsFbueyJE2iBAGpjgTnEOKM3pnuEGVmiqg==", + "dependencies": { + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/app/node_modules/@octokit/plugin-paginate-rest": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.1.5.tgz", + "integrity": "sha512-WKTQXxK+bu49qzwv4qKbMMRXej1DU2gq017euWyKVudA6MldaSSQuxtz+vGbhxV4CjxpUxjZu6rM2wfc1FiWVg==", + "dependencies": { + "@octokit/types": "^12.4.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/@octokit/app/node_modules/@octokit/webhooks": { + "version": "12.1.1", + "resolved": "https://registry.npmjs.org/@octokit/webhooks/-/webhooks-12.1.1.tgz", + "integrity": "sha512-h7PyYf4VR9kvmm6SYdkmju5BOQmpJ3Fvf1rNQaEsfs70EOu0vspm/Fzr1j5LnP6UGblSW2kuEKiuEwEf5H3OTw==", + "dependencies": { + "@octokit/request-error": "^5.0.0", + "@octokit/webhooks-methods": "^4.0.0", + "@octokit/webhooks-types": "7.3.2", + "aggregate-error": "^3.1.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/app/node_modules/@octokit/webhooks-methods": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/webhooks-methods/-/webhooks-methods-4.0.0.tgz", + "integrity": "sha512-M8mwmTXp+VeolOS/kfRvsDdW+IO0qJ8kYodM/sAysk093q6ApgmBXwK1ZlUvAwXVrp/YVHp6aArj4auAxUAOFw==", + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/app/node_modules/@octokit/webhooks-types": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-7.3.2.tgz", + "integrity": "sha512-JWOoOgtWTFnTSAamPXXyjTY5/apttvNxF+vPBnwdSu5cj5snrd7FO0fyw4+wTXy8fHduq626JjhO+TwCyyA6vA==" + }, "node_modules/@octokit/auth-app": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-6.0.3.tgz", @@ -1890,6 +1959,36 @@ "node": ">= 18" } }, + "node_modules/@octokit/oauth-app": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@octokit/oauth-app/-/oauth-app-6.1.0.tgz", + "integrity": "sha512-nIn/8eUJ/BKUVzxUXd5vpzl1rwaVxMyYbQkNZjHrF7Vk/yu98/YDF/N2KeWO7uZ0g3b5EyiFXFkZI8rJ+DH1/g==", + "dependencies": { + "@octokit/auth-oauth-app": "^7.0.0", + "@octokit/auth-oauth-user": "^4.0.0", + "@octokit/auth-unauthenticated": "^5.0.0", + "@octokit/core": "^5.0.0", + "@octokit/oauth-authorization-url": "^6.0.2", + "@octokit/oauth-methods": "^4.0.0", + "@types/aws-lambda": "^8.10.83", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/oauth-app/node_modules/@octokit/auth-unauthenticated": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-5.0.1.tgz", + "integrity": "sha512-oxeWzmBFxWd+XolxKTc4zr+h3mt+yofn4r7OfoIkR/Cj/o70eEGmPsFbueyJE2iBAGpjgTnEOKM3pnuEGVmiqg==", + "dependencies": { + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/@octokit/oauth-authorization-url": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-6.0.2.tgz", @@ -1950,6 +2049,17 @@ "@octokit/openapi-types": "^12.11.0" } }, + "node_modules/@octokit/plugin-paginate-graphql": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-graphql/-/plugin-paginate-graphql-4.0.0.tgz", + "integrity": "sha512-7HcYW5tP7/Z6AETAPU14gp5H5KmCPT3hmJrS/5tO7HIgbwenYmgw4OY9Ma54FDySuxMwD+wsJlxtuGWwuZuItA==", + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, "node_modules/@octokit/plugin-paginate-rest": { "version": "2.21.3", "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz", @@ -2625,6 +2735,11 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, + "node_modules/@types/aws-lambda": { + "version": "8.10.133", + "resolved": "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.133.tgz", + "integrity": "sha512-sr852MAL/79rjDelXP6ZuJ6GwOvXIRrFAoC8a+w91mZ5XR71CuzSgo1d0+pG1qgfPhjFgaibu7SWaoC5BA7pyQ==" + }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -8871,6 +8986,26 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/octokit": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/octokit/-/octokit-3.1.2.tgz", + "integrity": "sha512-MG5qmrTL5y8KYwFgE1A4JWmgfQBaIETE/lOlfwNYx1QOtCQHGVxkRJmdUJltFc1HVn73d61TlMhMyNTOtMl+ng==", + "dependencies": { + "@octokit/app": "^14.0.2", + "@octokit/core": "^5.0.0", + "@octokit/oauth-app": "^6.0.0", + "@octokit/plugin-paginate-graphql": "^4.0.0", + "@octokit/plugin-paginate-rest": "^9.0.0", + "@octokit/plugin-rest-endpoint-methods": "^10.0.0", + "@octokit/plugin-retry": "^6.0.0", + "@octokit/plugin-throttling": "^8.0.0", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/octokit-auth-probot": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/octokit-auth-probot/-/octokit-auth-probot-1.2.9.tgz", @@ -9149,6 +9284,50 @@ "node": "14 || >=16.14" } }, + "node_modules/octokit/node_modules/@octokit/plugin-paginate-rest": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.1.5.tgz", + "integrity": "sha512-WKTQXxK+bu49qzwv4qKbMMRXej1DU2gq017euWyKVudA6MldaSSQuxtz+vGbhxV4CjxpUxjZu6rM2wfc1FiWVg==", + "dependencies": { + "@octokit/types": "^12.4.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/octokit/node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.2.0.tgz", + "integrity": "sha512-ePbgBMYtGoRNXDyKGvr9cyHjQ163PbwD0y1MkDJCpkO2YH4OeXX40c4wYHKikHGZcpGPbcRLuy0unPUuafco8Q==", + "dependencies": { + "@octokit/types": "^12.3.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/octokit/node_modules/@octokit/plugin-retry": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-6.0.1.tgz", + "integrity": "sha512-SKs+Tz9oj0g4p28qkZwl/topGcb0k0qPNX/i7vBKmDsjoeqnVfFUquqrE/O9oJY7+oLzdCtkiWSXLpLjvl6uog==", + "dependencies": { + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0", + "bottleneck": "^2.15.3" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, "node_modules/oidc-token-hash": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz", diff --git a/package.json b/package.json index 04a0d8a..7743458 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,6 @@ "dependencies": { "@octokit/auth-app": "6.0.3", "@octokit/auth-token": "4.0.0", - "@octokit/core": "5.0.2", - "@octokit/plugin-throttling": "8.1.3", "@octokit/types": "12.4.0", "@primer/octicons-react": "19.8.0", "@primer/react": "35.32.2", @@ -31,6 +29,7 @@ "@trpc/server": "10.44.1", "next": "13.5.5", "next-auth": "4.24.5", + "octokit": "^3.1.2", "probot": "12.3.3", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/src/bot/octokit.ts b/src/bot/octokit.ts index 07ef0f0..5456a7c 100644 --- a/src/bot/octokit.ts +++ b/src/bot/octokit.ts @@ -1,6 +1,6 @@ import { createAppAuth } from '@octokit/auth-app' +import { Octokit } from 'octokit' import { logger } from 'utils/logger' -import { Octokit } from './rest' const personalOctokitLogger = logger.getSubLogger({ name: 'personal-octokit' }) const appOctokitLogger = logger.getSubLogger({ name: 'app-octokit' }) diff --git a/src/bot/rest.ts b/src/bot/rest.ts deleted file mode 100644 index d0b1b34..0000000 --- a/src/bot/rest.ts +++ /dev/null @@ -1,17 +0,0 @@ -// This is directly copied from https://github.com/octokit/rest.js/blob/main/src/index.ts -// The only change is that we get rid of request logging since we cannot format it -// See https://github.com/octokit/rest.js/issues/393 for more details - -import { Octokit as Core } from '@octokit/core' -import { paginateRest } from '@octokit/plugin-paginate-rest' -import { legacyRestEndpointMethods } from '@octokit/plugin-rest-endpoint-methods' -export type { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods' - -export const Octokit = Core.plugin( - legacyRestEndpointMethods, - paginateRest, -).defaults({ - userAgent: `octokit-rest.js/repo-sync-bot`, -}) - -export type Octokit = InstanceType diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts index 6a12b8b..bfa5a5a 100644 --- a/src/pages/api/auth/[...nextauth].ts +++ b/src/pages/api/auth/[...nextauth].ts @@ -15,7 +15,7 @@ export const verifySession = async (token: string | undefined) => { const octokit = personalOctokit(token) try { - await octokit.users.getAuthenticated() + await octokit.rest.users.getAuthenticated() return true } catch (error) { return false diff --git a/src/pages/organizations.tsx b/src/pages/organizations.tsx index f01d3e2..fd72cff 100644 --- a/src/pages/organizations.tsx +++ b/src/pages/organizations.tsx @@ -16,7 +16,7 @@ const Organizations: FC = () => { // fetch all the organizations a user is in via octokit const getAllOrganizations = async (accessToken: string) => { const octokit = personalOctokit(accessToken) - const data = await octokit.orgs.listForAuthenticatedUser() + const data = await octokit.rest.orgs.listForAuthenticatedUser() return data.data } diff --git a/src/pages/orgs/[organizationId]/forks/[forkId].tsx b/src/pages/orgs/[organizationId]/forks/[forkId].tsx index e13632d..a668fd4 100644 --- a/src/pages/orgs/[organizationId]/forks/[forkId].tsx +++ b/src/pages/orgs/[organizationId]/forks/[forkId].tsx @@ -5,18 +5,18 @@ import { getAuthServerSideProps } from 'components/auth-guard' import { CreateMirrorDialog } from 'components/create-mirror' import { useRouter } from 'next/router' import type { InferGetServerSidePropsType } from 'next/types' +import { Octokit } from 'octokit' import { useCallback, useEffect, useState } from 'react' import { trpc } from 'utils/trpc' -import { Octokit } from '../../../../bot/rest' const getOrgInformation = async (accessToken: string, orgId: string) => { - return (await personalOctokit(accessToken).orgs.get({ org: orgId })).data + return (await personalOctokit(accessToken).rest.orgs.get({ org: orgId })).data } const getForkById = async ( accessToken: string, repoId: string, -): Promise>['data']> => { +): Promise>['data']> => { return ( await personalOctokit(accessToken).request('GET /repositories/:id', { id: repoId, @@ -30,7 +30,7 @@ const findMirrors = async ( forkName: string, ) => { return ( - await personalOctokit(accessToken).search.repos({ + await personalOctokit(accessToken).rest.search.repos({ q: `org:${orgName} in:description "mirror:${orgName}/${forkName}"`, }) ).data diff --git a/src/pages/orgs/[organizationId]/index.tsx b/src/pages/orgs/[organizationId]/index.tsx index 11df458..7759221 100644 --- a/src/pages/orgs/[organizationId]/index.tsx +++ b/src/pages/orgs/[organizationId]/index.tsx @@ -14,12 +14,12 @@ const getOrganizationInformation = async ( accessToken: string, orgId: string, ) => { - return (await personalOctokit(accessToken).orgs.get({ org: orgId })).data + return (await personalOctokit(accessToken).rest.orgs.get({ org: orgId })).data } const getForksInOrg = async (accessToken: string, owner: string) => { return ( - await personalOctokit(accessToken).repos.listForOrg({ + await personalOctokit(accessToken).rest.repos.listForOrg({ per_page: 100, type: 'forks', org: owner, @@ -29,7 +29,7 @@ const getForksInOrg = async (accessToken: string, owner: string) => { const getParent = async (accessToken: string, owner: string, repo: string) => { return ( - await personalOctokit(accessToken).repos.get({ + await personalOctokit(accessToken).rest.repos.get({ owner, repo, }) diff --git a/src/server/routers/git.ts b/src/server/routers/git.ts index 46e777c..b83a59b 100644 --- a/src/server/routers/git.ts +++ b/src/server/routers/git.ts @@ -10,6 +10,11 @@ import { import { logger } from '../../utils/logger' import { procedure, router } from '../trpc' +const config = { + contributionOrg: 'github-ospo-test', + privateOrg: 'github-ospo-test-emu', +} + /** * Generates a git url with the access token in it * @param accessToken Access token for the app @@ -46,18 +51,18 @@ export const gitRouter = router({ ) .mutation(async (opts) => { gitLogger.info('getDiff', { input: opts.input }) - const installationId = await appOctokit().apps.getOrgInstallation({ + const installationId = await appOctokit().rest.apps.getOrgInstallation({ org: opts.input.orgId, }) const octokit = installationOctokit(String(installationId.data.id)) - const forkRepo = await octokit.repos.get({ + const forkRepo = await octokit.rest.repos.get({ owner: opts.input.forkOwner, repo: opts.input.forkName, }) - const mirrorRepo = await octokit.repos.get({ + const mirrorRepo = await octokit.rest.repos.get({ owner: opts.input.mirrorOwner, repo: opts.input.mirrorName, }) @@ -108,7 +113,7 @@ export const gitRouter = router({ ) .mutation(async (opts) => { gitLogger.info('syncRepos', { input: opts.input }) - const installationId = await appOctokit().apps.getOrgInstallation({ + const installationId = await appOctokit().rest.apps.getOrgInstallation({ org: opts.input.orgId, }) @@ -118,12 +123,12 @@ export const gitRouter = router({ String(installationId.data.id), ) - const forkRepo = await octokit.repos.get({ + const forkRepo = await octokit.rest.repos.get({ owner: opts.input.forkOwner, repo: opts.input.forkName, }) - const mirrorRepo = await octokit.repos.get({ + const mirrorRepo = await octokit.rest.repos.get({ owner: opts.input.mirrorOwner, repo: opts.input.mirrorName, }) @@ -213,7 +218,7 @@ export const gitRouter = router({ ) .mutation(async (opts) => { gitLogger.info('createMirror', { input: opts.input }) - const installationId = await appOctokit().apps.getOrgInstallation({ + const installationId = await appOctokit().rest.apps.getOrgInstallation({ org: opts.input.orgId, }) @@ -222,12 +227,12 @@ export const gitRouter = router({ ) const octokit = installationOctokit(String(installationId.data.id)) - const orgData = await octokit.orgs.get({ + const orgData = await octokit.rest.orgs.get({ org: opts.input.orgId, }) try { - const exists = await octokit.repos.get({ + const exists = await octokit.rest.repos.get({ owner: orgData.data.login, repo: opts.input.newRepoName, }) @@ -252,7 +257,7 @@ export const gitRouter = router({ } try { - const forkData = await octokit.repos.get({ + const forkData = await octokit.rest.repos.get({ owner: opts.input.forkRepoOwner, repo: opts.input.forkRepoName, }) @@ -280,7 +285,7 @@ export const gitRouter = router({ branch: opts.input.newBranchName, } - const newRepo = await octokit.repos.createInOrg({ + const newRepo = await octokit.rest.repos.createInOrg({ name: opts.input.newRepoName, org: opts.input.orgId, private: true, @@ -308,7 +313,7 @@ export const gitRouter = router({ } } catch (e) { // Clean up the repo made - await octokit.repos.delete({ + await octokit.rest.repos.delete({ owner: orgData.data.login, repo: opts.input.newRepoName, }) diff --git a/src/server/routers/octokit.ts b/src/server/routers/octokit.ts index 9d48710..c439acd 100644 --- a/src/server/routers/octokit.ts +++ b/src/server/routers/octokit.ts @@ -15,7 +15,7 @@ export const octokitRouter = router({ const { orgId } = opts.input try { - const installationId = await appOctokit().apps.getOrgInstallation({ + const installationId = await appOctokit().rest.apps.getOrgInstallation({ org: orgId, }) diff --git a/test/octomock/index.ts b/test/octomock/index.ts index 702a0bf..b566b9f 100644 --- a/test/octomock/index.ts +++ b/test/octomock/index.ts @@ -1,298 +1,300 @@ // This is taken from https://github.com/Chocrates/octomock let mockFunctions = { - apps: { - getOrgInstallation: jest.fn(), - }, - orgs: { - list: jest.fn(), - get: jest.fn(), - update: jest.fn(), - listBlockedUsers: jest.fn(), - checkBlockedUser: jest.fn(), - blockUser: jest.fn(), - unblockUser: jest.fn(), - listHooks: jest.fn(), - createHook: jest.fn(), - getHook: jest.fn(), - updateHook: jest.fn(), - deleteHook: jest.fn(), - pingHook: jest.fn(), - listInstallations: jest.fn(), - listPendingInvitations: jest.fn(), - createInvitation: jest.fn(), - listInvitationTeams: jest.fn(), - listMembers: jest.fn(), - checkMembership: jest.fn(), - removeMember: jest.fn(), - getMembership: jest.fn(), - addOrUpdateMembership: jest.fn(), - removeMembership: jest.fn(), - listOutsideCollaborators: jest.fn(), - removeOutsideCollaborator: jest.fn(), - convertMemberToOutsideCollaborator: jest.fn(), - listPublicMembers: jest.fn(), - checkPublicMembership: jest.fn(), - publicizeMembership: jest.fn(), - concealMembership: jest.fn(), - listMemberships: jest.fn(), - getMembershipForAuthenticatedUser: jest.fn(), - updateMembership: jest.fn(), - listForAuthenticatedUser: jest.fn(), - listForUser: jest.fn(), - }, - repos: { - listForOrg: jest.fn(), - createInOrg: jest.fn(), - get: jest.fn(), - update: jest.fn(), - delete: jest.fn(), - enableAutomatedSecurityFixes: jest.fn(), - disableAutomatedSecurityFixes: jest.fn(), - listBranches: jest.fn(), - getBranch: jest.fn(), - getBranchProtection: jest.fn(), - updateBranchProtection: jest.fn(), - removeBranchProtection: jest.fn(), - getProtectedBranchAdminEnforcement: jest.fn(), - addProtectedBranchAdminEnforcement: jest.fn(), - removeProtectedBranchAdminEnforcement: jest.fn(), - getProtectedBranchPullRequestReviewEnforcement: jest.fn(), - updateProtectedBranchPullRequestReviewEnforcement: jest.fn(), - removeProtectedBranchPullRequestReviewEnforcement: jest.fn(), - getProtectedBranchRequiredSignatures: jest.fn(), - addProtectedBranchRequiredSignatures: jest.fn(), - removeProtectedBranchRequiredSignatures: jest.fn(), - getProtectedBranchRequiredStatusChecks: jest.fn(), - updateProtectedBranchRequiredStatusChecks: jest.fn(), - removeProtectedBranchRequiredStatusChecks: jest.fn(), - listProtectedBranchRequiredStatusChecksContexts: jest.fn(), - replaceProtectedBranchRequiredStatusChecksContexts: jest.fn(), - addProtectedBranchRequiredStatusChecksContexts: jest.fn(), - removeProtectedBranchRequiredStatusChecksContext: jest.fn(), - getProtectedBranchRestrictions: jest.fn(), - removeProtectedBranchRestrictions: jest.fn(), - getAppsWithAccessToProtectedBranch: jest.fn(), - listAppsWithAccessToProtectedBranch: jest.fn(), - replaceProtectedBranchAppRestrictions: jest.fn(), - addProtectedBranchAppRestrictions: jest.fn(), - removeProtectedBranchAppRestrictions: jest.fn(), - getTeamsWithAccessToProtectedBranch: jest.fn(), - listProtectedBranchTeamRestrictions: jest.fn(), - listTeamsWithAccessToProtectedBranch: jest.fn(), - replaceProtectedBranchTeamRestrictions: jest.fn(), - addProtectedBranchTeamRestrictions: jest.fn(), - removeProtectedBranchTeamRestrictions: jest.fn(), - getUsersWithAccessToProtectedBranch: jest.fn(), - listProtectedBranchUserRestrictions: jest.fn(), - listUsersWithAccessToProtectedBranch: jest.fn(), - replaceProtectedBranchUserRestrictions: jest.fn(), - addProtectedBranchUserRestrictions: jest.fn(), - removeProtectedBranchUserRestrictions: jest.fn(), - listCollaborators: jest.fn(), - checkCollaborator: jest.fn(), - addCollaborator: jest.fn(), - removeCollaborator: jest.fn(), - getCollaboratorPermissionLevel: jest.fn(), - listCommitComments: jest.fn(), - getCommitComment: jest.fn(), - updateCommitComment: jest.fn(), - deleteCommitComment: jest.fn(), - listCommits: jest.fn(), - listBranchesForHeadCommit: jest.fn(), - listCommentsForCommit: jest.fn(), - createCommitComment: jest.fn(), - listPullRequestAssociatedWithCommit: jest.fn(), - getCommit: jest.fn(), - getCombinedStatusForRef: jest.fn(), - listStatusesForRef: jest.fn(), - retrieveCommunityProfileMetrics: jest.fn(), - compareCommits: jest.fn(), - getContents: jest.fn(), - createOrUpdateFile: jest.fn(), - createFile: jest.fn(), - updateFile: jest.fn(), - deleteFile: jest.fn(), - listContributors: jest.fn(), - listDeployments: jest.fn(), - createDeployment: jest.fn(), - getDeployment: jest.fn(), - listDeploymentStatuses: jest.fn(), - createDeploymentStatus: jest.fn(), - getDeploymentStatus: jest.fn(), - createDispatchEvent: jest.fn(), - listDownloads: jest.fn(), - getDownload: jest.fn(), - deleteDownload: jest.fn(), - listForks: jest.fn(), - createFork: jest.fn(), - listHooks: jest.fn(), - createHook: jest.fn(), - getHook: jest.fn(), - updateHook: jest.fn(), - deleteHook: jest.fn(), - pingHook: jest.fn(), - testPushHook: jest.fn(), - listInvitations: jest.fn(), - deleteInvitation: jest.fn(), - updateInvitation: jest.fn(), - listDeployKeys: jest.fn(), - addDeployKey: jest.fn(), - getDeployKey: jest.fn(), - removeDeployKey: jest.fn(), - listLanguages: jest.fn(), - merge: jest.fn(), - getPages: jest.fn(), - enablePagesSite: jest.fn(), - disablePagesSite: jest.fn(), - updateInformationAboutPagesSite: jest.fn(), - requestPageBuild: jest.fn(), - listPagesBuilds: jest.fn(), - getLatestPagesBuild: jest.fn(), - getPagesBuild: jest.fn(), - getReadme: jest.fn(), - listReleases: jest.fn(), - createRelease: jest.fn(), - getReleaseAsset: jest.fn(), - updateReleaseAsset: jest.fn(), - deleteReleaseAsset: jest.fn(), - getLatestRelease: jest.fn(), - getReleaseByTag: jest.fn(), - getRelease: jest.fn(), - updateRelease: jest.fn(), - deleteRelease: jest.fn(), - listAssetsForRelease: jest.fn(), - uploadReleaseAsset: jest.fn(), - getCodeFrequencyStats: jest.fn(), - getCommitActivityStats: jest.fn(), - getContributorsStats: jest.fn(), - getParticipationStats: jest.fn(), - getPunchCardStats: jest.fn(), - createStatus: jest.fn(), - listTags: jest.fn(), - listTeams: jest.fn(), - listTopics: jest.fn(), - replaceTopics: jest.fn(), - getClones: jest.fn(), - getTopPaths: jest.fn(), - getTopReferrers: jest.fn(), - getViews: jest.fn(), - transfer: jest.fn(), - checkVulnerabilityAlerts: jest.fn(), - enableVulnerabilityAlerts: jest.fn(), - disableVulnerabilityAlerts: jest.fn(), - getArchiveLink: jest.fn(), - createUsingTemplate: jest.fn(), - listPublic: jest.fn(), - list: jest.fn(), - createForAuthenticatedUser: jest.fn(), - listInvitationsForAuthenticatedUser: jest.fn(), - acceptInvitation: jest.fn(), - declineInvitation: jest.fn(), - listForUser: jest.fn(), - getCommitRefSha: jest.fn(), - }, - issues: { - list: jest.fn(), - listForOrg: jest.fn(), - listAssignees: jest.fn(), - checkAssignee: jest.fn(), - listForRepo: jest.fn(), - create: jest.fn(), - listCommentsForRepo: jest.fn(), - getComment: jest.fn(), - updateComment: jest.fn(), - deleteComment: jest.fn(), - listEventsForRepo: jest.fn(), - getEvent: jest.fn(), - get: jest.fn(), - update: jest.fn(), - addAssignees: jest.fn(), - removeAssignees: jest.fn(), - listComments: jest.fn(), - createComment: jest.fn(), - listEvents: jest.fn(), - listLabelsOnIssue: jest.fn(), - addLabels: jest.fn(), - replaceLabels: jest.fn(), - removeLabels: jest.fn(), - removeLabel: jest.fn(), - lock: jest.fn(), - unlock: jest.fn(), - listEventsForTimeline: jest.fn(), - listLabelsForRepo: jest.fn(), - createLabel: jest.fn(), - getLabel: jest.fn(), - updateLabel: jest.fn(), - deleteLabel: jest.fn(), - listMilestonesForRepo: jest.fn(), - createMilestone: jest.fn(), - getMilestone: jest.fn(), - updateMilestone: jest.fn(), - deleteMilestone: jest.fn(), - listLabelsForMilestone: jest.fn(), - listForAuthenticatedUser: jest.fn(), - }, - actions: { - cancelWorkflowRun: jest.fn(), - createOrUpdateSecretForRepo: jest.fn(), - createRegistrationToken: jest.fn(), - createRemoveToken: jest.fn(), - deleteArtifact: jest.fn(), - deleteSecretFromRepo: jest.fn(), - downloadArtifact: jest.fn(), - getArtifact: jest.fn(), - getPublicKey: jest.fn(), - getSecret: jest.fn(), - getSelfHostedRunner: jest.fn(), - getWorkflow: jest.fn(), - getWorkflowJob: jest.fn(), - getWorkflowRun: jest.fn(), - listArtifactsForRepo: jest.fn(), - listDownloadsForSelfHostedRunnerApplication: jest.fn(), - listJobsForWorkflowRun: jest.fn(), - listRepoWorkflowRuns: jest.fn(), - listRepoWorkflows: jest.fn(), - listSecretsForRepo: jest.fn(), - listSelfHostedRunnersForRepo: jest.fn(), - listWorkflowJobLogs: jest.fn(), - listWorkflowRunArtifacts: jest.fn(), - listWorkflowRunLogs: jest.fn(), - listWorkflowRuns: jest.fn(), - reRunWorkflow: jest.fn(), - removeSelfHostedRunner: jest.fn(), - }, - core: { - exportVariable: jest.fn(), - setSecret: jest.fn(), - addPath: jest.fn(), - getInput: jest.fn((value) => value), - setOutput: jest.fn(), - setFailed: jest.fn((message) => { - console.log(`MOCK FAILED: ${message}`) - }), - debug: jest.fn((message) => { - console.log(`MOCK DEBUG: ${message}`) - }), - error: jest.fn((message) => { - console.log(`MOCK ERROR: ${message}`) - }), - warning: jest.fn((message) => { - console.log(`MOCK WARNING: ${message}`) - }), - info: jest.fn((message) => { - console.log(`MOCK INFO: ${message}`) - }), - startGroup: jest.fn(), - endGroup: jest.fn(), - group: jest.fn(), - saveState: jest.fn(), - getState: jest.fn(), + rest: { + apps: { + getOrgInstallation: jest.fn(), + }, + orgs: { + list: jest.fn(), + get: jest.fn(), + update: jest.fn(), + listBlockedUsers: jest.fn(), + checkBlockedUser: jest.fn(), + blockUser: jest.fn(), + unblockUser: jest.fn(), + listHooks: jest.fn(), + createHook: jest.fn(), + getHook: jest.fn(), + updateHook: jest.fn(), + deleteHook: jest.fn(), + pingHook: jest.fn(), + listInstallations: jest.fn(), + listPendingInvitations: jest.fn(), + createInvitation: jest.fn(), + listInvitationTeams: jest.fn(), + listMembers: jest.fn(), + checkMembership: jest.fn(), + removeMember: jest.fn(), + getMembership: jest.fn(), + addOrUpdateMembership: jest.fn(), + removeMembership: jest.fn(), + listOutsideCollaborators: jest.fn(), + removeOutsideCollaborator: jest.fn(), + convertMemberToOutsideCollaborator: jest.fn(), + listPublicMembers: jest.fn(), + checkPublicMembership: jest.fn(), + publicizeMembership: jest.fn(), + concealMembership: jest.fn(), + listMemberships: jest.fn(), + getMembershipForAuthenticatedUser: jest.fn(), + updateMembership: jest.fn(), + listForAuthenticatedUser: jest.fn(), + listForUser: jest.fn(), + }, + repos: { + listForOrg: jest.fn(), + createInOrg: jest.fn(), + get: jest.fn(), + update: jest.fn(), + delete: jest.fn(), + enableAutomatedSecurityFixes: jest.fn(), + disableAutomatedSecurityFixes: jest.fn(), + listBranches: jest.fn(), + getBranch: jest.fn(), + getBranchProtection: jest.fn(), + updateBranchProtection: jest.fn(), + removeBranchProtection: jest.fn(), + getProtectedBranchAdminEnforcement: jest.fn(), + addProtectedBranchAdminEnforcement: jest.fn(), + removeProtectedBranchAdminEnforcement: jest.fn(), + getProtectedBranchPullRequestReviewEnforcement: jest.fn(), + updateProtectedBranchPullRequestReviewEnforcement: jest.fn(), + removeProtectedBranchPullRequestReviewEnforcement: jest.fn(), + getProtectedBranchRequiredSignatures: jest.fn(), + addProtectedBranchRequiredSignatures: jest.fn(), + removeProtectedBranchRequiredSignatures: jest.fn(), + getProtectedBranchRequiredStatusChecks: jest.fn(), + updateProtectedBranchRequiredStatusChecks: jest.fn(), + removeProtectedBranchRequiredStatusChecks: jest.fn(), + listProtectedBranchRequiredStatusChecksContexts: jest.fn(), + replaceProtectedBranchRequiredStatusChecksContexts: jest.fn(), + addProtectedBranchRequiredStatusChecksContexts: jest.fn(), + removeProtectedBranchRequiredStatusChecksContext: jest.fn(), + getProtectedBranchRestrictions: jest.fn(), + removeProtectedBranchRestrictions: jest.fn(), + getAppsWithAccessToProtectedBranch: jest.fn(), + listAppsWithAccessToProtectedBranch: jest.fn(), + replaceProtectedBranchAppRestrictions: jest.fn(), + addProtectedBranchAppRestrictions: jest.fn(), + removeProtectedBranchAppRestrictions: jest.fn(), + getTeamsWithAccessToProtectedBranch: jest.fn(), + listProtectedBranchTeamRestrictions: jest.fn(), + listTeamsWithAccessToProtectedBranch: jest.fn(), + replaceProtectedBranchTeamRestrictions: jest.fn(), + addProtectedBranchTeamRestrictions: jest.fn(), + removeProtectedBranchTeamRestrictions: jest.fn(), + getUsersWithAccessToProtectedBranch: jest.fn(), + listProtectedBranchUserRestrictions: jest.fn(), + listUsersWithAccessToProtectedBranch: jest.fn(), + replaceProtectedBranchUserRestrictions: jest.fn(), + addProtectedBranchUserRestrictions: jest.fn(), + removeProtectedBranchUserRestrictions: jest.fn(), + listCollaborators: jest.fn(), + checkCollaborator: jest.fn(), + addCollaborator: jest.fn(), + removeCollaborator: jest.fn(), + getCollaboratorPermissionLevel: jest.fn(), + listCommitComments: jest.fn(), + getCommitComment: jest.fn(), + updateCommitComment: jest.fn(), + deleteCommitComment: jest.fn(), + listCommits: jest.fn(), + listBranchesForHeadCommit: jest.fn(), + listCommentsForCommit: jest.fn(), + createCommitComment: jest.fn(), + listPullRequestAssociatedWithCommit: jest.fn(), + getCommit: jest.fn(), + getCombinedStatusForRef: jest.fn(), + listStatusesForRef: jest.fn(), + retrieveCommunityProfileMetrics: jest.fn(), + compareCommits: jest.fn(), + getContents: jest.fn(), + createOrUpdateFile: jest.fn(), + createFile: jest.fn(), + updateFile: jest.fn(), + deleteFile: jest.fn(), + listContributors: jest.fn(), + listDeployments: jest.fn(), + createDeployment: jest.fn(), + getDeployment: jest.fn(), + listDeploymentStatuses: jest.fn(), + createDeploymentStatus: jest.fn(), + getDeploymentStatus: jest.fn(), + createDispatchEvent: jest.fn(), + listDownloads: jest.fn(), + getDownload: jest.fn(), + deleteDownload: jest.fn(), + listForks: jest.fn(), + createFork: jest.fn(), + listHooks: jest.fn(), + createHook: jest.fn(), + getHook: jest.fn(), + updateHook: jest.fn(), + deleteHook: jest.fn(), + pingHook: jest.fn(), + testPushHook: jest.fn(), + listInvitations: jest.fn(), + deleteInvitation: jest.fn(), + updateInvitation: jest.fn(), + listDeployKeys: jest.fn(), + addDeployKey: jest.fn(), + getDeployKey: jest.fn(), + removeDeployKey: jest.fn(), + listLanguages: jest.fn(), + merge: jest.fn(), + getPages: jest.fn(), + enablePagesSite: jest.fn(), + disablePagesSite: jest.fn(), + updateInformationAboutPagesSite: jest.fn(), + requestPageBuild: jest.fn(), + listPagesBuilds: jest.fn(), + getLatestPagesBuild: jest.fn(), + getPagesBuild: jest.fn(), + getReadme: jest.fn(), + listReleases: jest.fn(), + createRelease: jest.fn(), + getReleaseAsset: jest.fn(), + updateReleaseAsset: jest.fn(), + deleteReleaseAsset: jest.fn(), + getLatestRelease: jest.fn(), + getReleaseByTag: jest.fn(), + getRelease: jest.fn(), + updateRelease: jest.fn(), + deleteRelease: jest.fn(), + listAssetsForRelease: jest.fn(), + uploadReleaseAsset: jest.fn(), + getCodeFrequencyStats: jest.fn(), + getCommitActivityStats: jest.fn(), + getContributorsStats: jest.fn(), + getParticipationStats: jest.fn(), + getPunchCardStats: jest.fn(), + createStatus: jest.fn(), + listTags: jest.fn(), + listTeams: jest.fn(), + listTopics: jest.fn(), + replaceTopics: jest.fn(), + getClones: jest.fn(), + getTopPaths: jest.fn(), + getTopReferrers: jest.fn(), + getViews: jest.fn(), + transfer: jest.fn(), + checkVulnerabilityAlerts: jest.fn(), + enableVulnerabilityAlerts: jest.fn(), + disableVulnerabilityAlerts: jest.fn(), + getArchiveLink: jest.fn(), + createUsingTemplate: jest.fn(), + listPublic: jest.fn(), + list: jest.fn(), + createForAuthenticatedUser: jest.fn(), + listInvitationsForAuthenticatedUser: jest.fn(), + acceptInvitation: jest.fn(), + declineInvitation: jest.fn(), + listForUser: jest.fn(), + getCommitRefSha: jest.fn(), + }, + issues: { + list: jest.fn(), + listForOrg: jest.fn(), + listAssignees: jest.fn(), + checkAssignee: jest.fn(), + listForRepo: jest.fn(), + create: jest.fn(), + listCommentsForRepo: jest.fn(), + getComment: jest.fn(), + updateComment: jest.fn(), + deleteComment: jest.fn(), + listEventsForRepo: jest.fn(), + getEvent: jest.fn(), + get: jest.fn(), + update: jest.fn(), + addAssignees: jest.fn(), + removeAssignees: jest.fn(), + listComments: jest.fn(), + createComment: jest.fn(), + listEvents: jest.fn(), + listLabelsOnIssue: jest.fn(), + addLabels: jest.fn(), + replaceLabels: jest.fn(), + removeLabels: jest.fn(), + removeLabel: jest.fn(), + lock: jest.fn(), + unlock: jest.fn(), + listEventsForTimeline: jest.fn(), + listLabelsForRepo: jest.fn(), + createLabel: jest.fn(), + getLabel: jest.fn(), + updateLabel: jest.fn(), + deleteLabel: jest.fn(), + listMilestonesForRepo: jest.fn(), + createMilestone: jest.fn(), + getMilestone: jest.fn(), + updateMilestone: jest.fn(), + deleteMilestone: jest.fn(), + listLabelsForMilestone: jest.fn(), + listForAuthenticatedUser: jest.fn(), + }, + actions: { + cancelWorkflowRun: jest.fn(), + createOrUpdateSecretForRepo: jest.fn(), + createRegistrationToken: jest.fn(), + createRemoveToken: jest.fn(), + deleteArtifact: jest.fn(), + deleteSecretFromRepo: jest.fn(), + downloadArtifact: jest.fn(), + getArtifact: jest.fn(), + getPublicKey: jest.fn(), + getSecret: jest.fn(), + getSelfHostedRunner: jest.fn(), + getWorkflow: jest.fn(), + getWorkflowJob: jest.fn(), + getWorkflowRun: jest.fn(), + listArtifactsForRepo: jest.fn(), + listDownloadsForSelfHostedRunnerApplication: jest.fn(), + listJobsForWorkflowRun: jest.fn(), + listRepoWorkflowRuns: jest.fn(), + listRepoWorkflows: jest.fn(), + listSecretsForRepo: jest.fn(), + listSelfHostedRunnersForRepo: jest.fn(), + listWorkflowJobLogs: jest.fn(), + listWorkflowRunArtifacts: jest.fn(), + listWorkflowRunLogs: jest.fn(), + listWorkflowRuns: jest.fn(), + reRunWorkflow: jest.fn(), + removeSelfHostedRunner: jest.fn(), + }, + core: { + exportVariable: jest.fn(), + setSecret: jest.fn(), + addPath: jest.fn(), + getInput: jest.fn((value) => value), + setOutput: jest.fn(), + setFailed: jest.fn((message) => { + console.log(`MOCK FAILED: ${message}`) + }), + debug: jest.fn((message) => { + console.log(`MOCK DEBUG: ${message}`) + }), + error: jest.fn((message) => { + console.log(`MOCK ERROR: ${message}`) + }), + warning: jest.fn((message) => { + console.log(`MOCK WARNING: ${message}`) + }), + info: jest.fn((message) => { + console.log(`MOCK INFO: ${message}`) + }), + startGroup: jest.fn(), + endGroup: jest.fn(), + group: jest.fn(), + saveState: jest.fn(), + getState: jest.fn(), + }, }, } export class Octomock { - mockFunctions: Record> + mockFunctions: { rest: Record> } defaultContext: { payload: { issue: { body: string; user: {} } } } mockGitHubImplementation: { @@ -342,21 +344,21 @@ export class Octomock { } this.mockCoreImplementation = { - exportVariable: this.mockFunctions.core.exportVariable, - setSecret: this.mockFunctions.core.setSecret, - addPath: this.mockFunctions.core.addPath, - getInput: this.mockFunctions.core.getInput, - setOutput: this.mockFunctions.core.setOutput, - setFailed: this.mockFunctions.core.setFailed, - debug: this.mockFunctions.core.debug, - error: this.mockFunctions.core.error, - warning: this.mockFunctions.core.warning, - info: this.mockFunctions.core.info, - startGroup: this.mockFunctions.core.startGroup, - endGroup: this.mockFunctions.core.endGroup, - group: this.mockFunctions.core.group, - saveState: this.mockFunctions.core.saveState, - getState: this.mockFunctions.core.getState, + exportVariable: this.mockFunctions.rest.core.exportVariable, + setSecret: this.mockFunctions.rest.core.setSecret, + addPath: this.mockFunctions.rest.core.addPath, + getInput: this.mockFunctions.rest.core.getInput, + setOutput: this.mockFunctions.rest.core.setOutput, + setFailed: this.mockFunctions.rest.core.setFailed, + debug: this.mockFunctions.rest.core.debug, + error: this.mockFunctions.rest.core.error, + warning: this.mockFunctions.rest.core.warning, + info: this.mockFunctions.rest.core.info, + startGroup: this.mockFunctions.rest.core.startGroup, + endGroup: this.mockFunctions.rest.core.endGroup, + group: this.mockFunctions.rest.core.group, + saveState: this.mockFunctions.rest.core.saveState, + getState: this.mockFunctions.rest.core.getState, } } @@ -380,30 +382,10 @@ export class Octomock { return this.mockCoreImplementation } - updateCoreImplementation(implementation: { - exportVariable: any - setSecret: any - addPath: any - getInput: any - setOutput: any - setFailed: any - debug: any - error: any - warning: any - info: any - startGroup: any - endGroup: any - group: any - saveState: any - getState: any - }) { - this.mockCoreImplementation = implementation - } - resetMocks() { - for (let ctx in this.mockFunctions) { - for (let func in this.mockFunctions[ctx]) { - this.mockFunctions[ctx][func].mockClear() + for (let ctx in this.mockFunctions.rest) { + for (let func in this.mockFunctions.rest[ctx]) { + this.mockFunctions.rest[ctx][func].mockClear() } } } diff --git a/test/server/git.test.ts b/test/server/git.test.ts index 932e8b6..0c5e8ed 100644 --- a/test/server/git.test.ts +++ b/test/server/git.test.ts @@ -77,13 +77,13 @@ describe('Git router', () => { test('should create a mirror when repo does not exist exist', async () => { const caller = gitRouter.createCaller({}) - om.mockFunctions.apps.getOrgInstallation.mockResolvedValue( + om.mockFunctions.rest.apps.getOrgInstallation.mockResolvedValue( fakeOrgInstallation, ) - om.mockFunctions.orgs.get.mockResolvedValue(fakeOrg) - om.mockFunctions.repos.get.mockResolvedValueOnce(repoNotFound) - om.mockFunctions.repos.get.mockResolvedValueOnce(fakeForkRepo) - om.mockFunctions.repos.createInOrg.mockResolvedValue(fakeMirrorRepo) + om.mockFunctions.rest.orgs.get.mockResolvedValue(fakeOrg) + om.mockFunctions.rest.repos.get.mockResolvedValueOnce(repoNotFound) + om.mockFunctions.rest.repos.get.mockResolvedValueOnce(fakeForkRepo) + om.mockFunctions.rest.repos.createInOrg.mockResolvedValue(fakeMirrorRepo) const res = await caller.createMirror({ forkId: 'test', @@ -95,7 +95,7 @@ describe('Git router', () => { }) // TODO: use real git operations and verify fs state after - expect(om.mockFunctions.repos.get).toHaveBeenCalledTimes(2) + expect(om.mockFunctions.rest.repos.get).toHaveBeenCalledTimes(2) expect(stubbedGit.clone).toHaveBeenCalledTimes(1) expect(stubbedGit.addRemote).toHaveBeenCalledTimes(1) expect(stubbedGit.push).toHaveBeenCalledTimes(2) @@ -109,12 +109,12 @@ describe('Git router', () => { test('should throw an error when repo already exists', async () => { const caller = gitRouter.createCaller({}) - om.mockFunctions.apps.getOrgInstallation.mockResolvedValue( + om.mockFunctions.rest.apps.getOrgInstallation.mockResolvedValue( fakeOrgInstallation, ) - om.mockFunctions.orgs.get.mockResolvedValue(fakeOrg) - om.mockFunctions.repos.get.mockResolvedValue(fakeMirrorRepo) - om.mockFunctions.repos.delete.mockResolvedValue({}) + om.mockFunctions.rest.orgs.get.mockResolvedValue(fakeOrg) + om.mockFunctions.rest.repos.get.mockResolvedValue(fakeMirrorRepo) + om.mockFunctions.rest.repos.delete.mockResolvedValue({}) await caller .createMirror({ @@ -129,21 +129,21 @@ describe('Git router', () => { expect(error.message).toEqual('Repo github-test/test already exists') }) - expect(om.mockFunctions.repos.get).toHaveBeenCalledTimes(1) - expect(om.mockFunctions.repos.delete).toHaveBeenCalledTimes(0) + expect(om.mockFunctions.rest.repos.get).toHaveBeenCalledTimes(1) + expect(om.mockFunctions.rest.repos.delete).toHaveBeenCalledTimes(0) expect(stubbedGit.clone).toHaveBeenCalledTimes(0) }) test('should cleanup repos when there is an error', async () => { const caller = gitRouter.createCaller({}) - om.mockFunctions.apps.getOrgInstallation.mockResolvedValue( + om.mockFunctions.rest.apps.getOrgInstallation.mockResolvedValue( fakeOrgInstallation, ) - om.mockFunctions.orgs.get.mockResolvedValue(fakeOrg) - om.mockFunctions.repos.get.mockResolvedValueOnce(repoNotFound) - om.mockFunctions.repos.get.mockResolvedValueOnce(fakeMirrorRepo) - om.mockFunctions.repos.delete.mockResolvedValue({}) + om.mockFunctions.rest.orgs.get.mockResolvedValue(fakeOrg) + om.mockFunctions.rest.repos.get.mockResolvedValueOnce(repoNotFound) + om.mockFunctions.rest.repos.get.mockResolvedValueOnce(fakeMirrorRepo) + om.mockFunctions.rest.repos.delete.mockResolvedValue({}) stubbedGit.clone.mockRejectedValue(new Error('clone error')) @@ -160,8 +160,8 @@ describe('Git router', () => { expect(error.message).toEqual('clone error') }) - expect(om.mockFunctions.repos.get).toHaveBeenCalledTimes(2) - expect(om.mockFunctions.repos.delete).toHaveBeenCalledTimes(1) + expect(om.mockFunctions.rest.repos.get).toHaveBeenCalledTimes(2) + expect(om.mockFunctions.rest.repos.delete).toHaveBeenCalledTimes(1) expect(stubbedGit.clone).toHaveBeenCalledTimes(1) }) })