@sanity/cli 6.0.0-alpha.4 → 6.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/dev/startStudioDevServer.js +3 -8
- package/dist/actions/dev/startStudioDevServer.js.map +1 -1
- package/dist/actions/dev/types.d.ts +1 -3
- package/dist/actions/dev/types.js.map +1 -1
- package/dist/actions/documents/validate.d.ts +0 -2
- package/dist/actions/documents/validate.js +21 -1
- package/dist/actions/documents/validate.js.map +1 -1
- package/dist/actions/exec/execScript.js +1 -1
- package/dist/actions/exec/execScript.js.map +1 -1
- package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js +1 -1
- package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js.map +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.js +1 -1
- package/dist/actions/graphql/getGraphQLAPIs.js.map +1 -1
- package/dist/actions/manifest/extractManifest.js +1 -4
- package/dist/actions/manifest/extractManifest.js.map +1 -1
- package/dist/actions/schema/deleteSchemaAction.d.ts +13 -5
- package/dist/actions/schema/deleteSchemaAction.js +12 -17
- package/dist/actions/schema/deleteSchemaAction.js.map +1 -1
- package/dist/actions/schema/deploySchemas.d.ts +15 -0
- package/dist/actions/schema/deploySchemas.js +98 -0
- package/dist/actions/schema/deploySchemas.js.map +1 -0
- package/dist/actions/schema/listSchemas.d.ts +12 -0
- package/dist/actions/schema/listSchemas.js +119 -0
- package/dist/actions/schema/listSchemas.js.map +1 -0
- package/dist/actions/schema/schemaStoreTypes.d.ts +0 -11
- package/dist/actions/schema/schemaStoreTypes.js.map +1 -1
- package/dist/actions/schema/utils/debug.d.ts +2 -0
- package/dist/actions/schema/utils/debug.js +5 -0
- package/dist/actions/schema/utils/debug.js.map +1 -0
- package/dist/actions/schema/utils/manifestExtractor.d.ts +3 -8
- package/dist/actions/schema/utils/manifestExtractor.js +12 -17
- package/dist/actions/schema/utils/manifestExtractor.js.map +1 -1
- package/dist/actions/schema/utils/manifestReader.d.ts +2 -9
- package/dist/actions/schema/utils/manifestReader.js +6 -12
- package/dist/actions/schema/utils/manifestReader.js.map +1 -1
- package/dist/actions/schema/utils/schemaStoreOutStrings.d.ts +0 -1
- package/dist/actions/schema/utils/schemaStoreOutStrings.js +1 -1
- package/dist/actions/schema/utils/schemaStoreOutStrings.js.map +1 -1
- package/dist/actions/schema/utils/schemaStoreValidation.d.ts +10 -62
- package/dist/actions/schema/utils/schemaStoreValidation.js +38 -125
- package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
- package/dist/actions/schema/utils/uniqByProjectIdDataset.d.ts +14 -0
- package/dist/actions/schema/utils/uniqByProjectIdDataset.js +9 -0
- package/dist/actions/schema/utils/uniqByProjectIdDataset.js.map +1 -0
- package/dist/actions/users/getMembersForProject.d.ts +1 -3
- package/dist/actions/users/getMembersForProject.js +6 -17
- package/dist/actions/users/getMembersForProject.js.map +1 -1
- package/dist/actions/users/types.d.ts +0 -11
- package/dist/actions/users/types.js.map +1 -1
- package/dist/commands/__tests__/debug.test.js +113 -220
- package/dist/commands/__tests__/debug.test.js.map +1 -1
- package/dist/commands/__tests__/deploy.test.js +325 -293
- package/dist/commands/__tests__/deploy.test.js.map +1 -1
- package/dist/commands/__tests__/dev.test.js +62 -19
- package/dist/commands/__tests__/dev.test.js.map +1 -1
- package/dist/commands/__tests__/init/init.authentication.test.js +40 -27
- package/dist/commands/__tests__/init/init.authentication.test.js.map +1 -1
- package/dist/commands/__tests__/init/init.create-new-project.test.js +84 -85
- package/dist/commands/__tests__/init/init.create-new-project.test.js.map +1 -1
- package/dist/commands/__tests__/init/init.plan.test.js +103 -44
- package/dist/commands/__tests__/init/init.plan.test.js.map +1 -1
- package/dist/commands/__tests__/init/init.setup.test.js +85 -29
- package/dist/commands/__tests__/init/init.setup.test.js.map +1 -1
- package/dist/commands/__tests__/install.test.js +46 -22
- package/dist/commands/__tests__/install.test.js.map +1 -1
- package/dist/commands/__tests__/logout.test.js +8 -5
- package/dist/commands/__tests__/logout.test.js.map +1 -1
- package/dist/commands/__tests__/manage.test.js +29 -24
- package/dist/commands/__tests__/manage.test.js.map +1 -1
- package/dist/commands/__tests__/versions.test.js +22 -14
- package/dist/commands/__tests__/versions.test.js.map +1 -1
- package/dist/commands/backup/__tests__/disable.test.js +72 -75
- package/dist/commands/backup/__tests__/disable.test.js.map +1 -1
- package/dist/commands/backup/__tests__/download.test.js +166 -77
- package/dist/commands/backup/__tests__/download.test.js.map +1 -1
- package/dist/commands/backup/__tests__/enable.test.js +109 -140
- package/dist/commands/backup/__tests__/enable.test.js.map +1 -1
- package/dist/commands/backup/__tests__/list.test.js +84 -75
- package/dist/commands/backup/__tests__/list.test.js.map +1 -1
- package/dist/commands/backup/disable.js +5 -11
- package/dist/commands/backup/disable.js.map +1 -1
- package/dist/commands/backup/enable.js +5 -11
- package/dist/commands/backup/enable.js.map +1 -1
- package/dist/commands/backup/list.js +7 -8
- package/dist/commands/backup/list.js.map +1 -1
- package/dist/commands/cors/__tests__/add.test.js +68 -38
- package/dist/commands/cors/__tests__/add.test.js.map +1 -1
- package/dist/commands/cors/__tests__/delete.test.js +52 -37
- package/dist/commands/cors/__tests__/delete.test.js.map +1 -1
- package/dist/commands/cors/__tests__/list.test.js +80 -57
- package/dist/commands/cors/__tests__/list.test.js.map +1 -1
- package/dist/commands/cors/add.js +5 -13
- package/dist/commands/cors/add.js.map +1 -1
- package/dist/commands/cors/delete.js +7 -15
- package/dist/commands/cors/delete.js.map +1 -1
- package/dist/commands/cors/list.js +2 -10
- package/dist/commands/cors/list.js.map +1 -1
- package/dist/commands/dataset/__tests__/copy.test.js +197 -89
- package/dist/commands/dataset/__tests__/copy.test.js.map +1 -1
- package/dist/commands/dataset/__tests__/create.test.js +147 -117
- package/dist/commands/dataset/__tests__/create.test.js.map +1 -1
- package/dist/commands/dataset/__tests__/delete.test.js +75 -68
- package/dist/commands/dataset/__tests__/delete.test.js.map +1 -1
- package/dist/commands/dataset/__tests__/export.test.js +123 -83
- package/dist/commands/dataset/__tests__/export.test.js.map +1 -1
- package/dist/commands/dataset/__tests__/list.test.js +107 -65
- package/dist/commands/dataset/__tests__/list.test.js.map +1 -1
- package/dist/commands/dataset/alias/__tests__/create.test.js +114 -74
- package/dist/commands/dataset/alias/__tests__/create.test.js.map +1 -1
- package/dist/commands/dataset/alias/__tests__/delete.test.js +40 -29
- package/dist/commands/dataset/alias/__tests__/delete.test.js.map +1 -1
- package/dist/commands/dataset/alias/__tests__/link.test.js +114 -74
- package/dist/commands/dataset/alias/__tests__/link.test.js.map +1 -1
- package/dist/commands/dataset/alias/__tests__/unlink.test.js +44 -29
- package/dist/commands/dataset/alias/__tests__/unlink.test.js.map +1 -1
- package/dist/commands/dataset/export.js +4 -4
- package/dist/commands/dataset/export.js.map +1 -1
- package/dist/commands/dataset/visibility/__tests__/get.test.js +48 -67
- package/dist/commands/dataset/visibility/__tests__/get.test.js.map +1 -1
- package/dist/commands/dataset/visibility/__tests__/set.test.js +76 -123
- package/dist/commands/dataset/visibility/__tests__/set.test.js.map +1 -1
- package/dist/commands/dev.js +0 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/docs/__tests__/search.test.js +8 -7
- package/dist/commands/docs/__tests__/search.test.js.map +1 -1
- package/dist/commands/documents/__tests__/create.test.js +328 -265
- package/dist/commands/documents/__tests__/create.test.js.map +1 -1
- package/dist/commands/documents/__tests__/delete.test.js +119 -87
- package/dist/commands/documents/__tests__/delete.test.js.map +1 -1
- package/dist/commands/documents/__tests__/get.test.js +68 -95
- package/dist/commands/documents/__tests__/get.test.js.map +1 -1
- package/dist/commands/documents/__tests__/query.test.js +84 -189
- package/dist/commands/documents/__tests__/query.test.js.map +1 -1
- package/dist/commands/documents/__tests__/validate.test.js +52 -29
- package/dist/commands/documents/__tests__/validate.test.js.map +1 -1
- package/dist/commands/documents/create.d.ts +1 -0
- package/dist/commands/documents/create.js +10 -9
- package/dist/commands/documents/create.js.map +1 -1
- package/dist/commands/documents/delete.js +2 -3
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/get.js +2 -3
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/query.js +2 -3
- package/dist/commands/documents/query.js.map +1 -1
- package/dist/commands/documents/validate.js +0 -20
- package/dist/commands/documents/validate.js.map +1 -1
- package/dist/commands/graphql/__tests__/list.test.js +57 -45
- package/dist/commands/graphql/__tests__/list.test.js.map +1 -1
- package/dist/commands/graphql/__tests__/undeploy.test.js +85 -59
- package/dist/commands/graphql/__tests__/undeploy.test.js.map +1 -1
- package/dist/commands/graphql/list.js +2 -2
- package/dist/commands/graphql/list.js.map +1 -1
- package/dist/commands/graphql/undeploy.js +4 -9
- package/dist/commands/graphql/undeploy.js.map +1 -1
- package/dist/commands/hook/__tests__/attempt.test.js +48 -33
- package/dist/commands/hook/__tests__/attempt.test.js.map +1 -1
- package/dist/commands/hook/__tests__/create.test.js +49 -51
- package/dist/commands/hook/__tests__/create.test.js.map +1 -1
- package/dist/commands/hook/__tests__/delete.test.js +43 -30
- package/dist/commands/hook/__tests__/delete.test.js.map +1 -1
- package/dist/commands/hook/__tests__/list.test.js +38 -31
- package/dist/commands/hook/__tests__/list.test.js.map +1 -1
- package/dist/commands/hook/__tests__/logs.test.js +68 -40
- package/dist/commands/hook/__tests__/logs.test.js.map +1 -1
- package/dist/commands/hook/create.js +2 -6
- package/dist/commands/hook/create.js.map +1 -1
- package/dist/commands/hook/delete.js +5 -17
- package/dist/commands/hook/delete.js.map +1 -1
- package/dist/commands/hook/list.js +2 -8
- package/dist/commands/hook/list.js.map +1 -1
- package/dist/commands/manifest/__tests__/extract.test.js +22 -13
- package/dist/commands/manifest/__tests__/extract.test.js.map +1 -1
- package/dist/commands/media/__tests__/create-aspect.test.js +41 -28
- package/dist/commands/media/__tests__/create-aspect.test.js.map +1 -1
- package/dist/commands/media/__tests__/delete-aspect.test.js +44 -35
- package/dist/commands/media/__tests__/delete-aspect.test.js.map +1 -1
- package/dist/commands/media/__tests__/deploy-aspect.test.js +67 -80
- package/dist/commands/media/__tests__/deploy-aspect.test.js.map +1 -1
- package/dist/commands/media/__tests__/export.test.js +365 -66
- package/dist/commands/media/__tests__/export.test.js.map +1 -1
- package/dist/commands/media/__tests__/import.test.js +171 -105
- package/dist/commands/media/__tests__/import.test.js.map +1 -1
- package/dist/commands/media/export.js +2 -2
- package/dist/commands/media/export.js.map +1 -1
- package/dist/commands/media/import.js +2 -2
- package/dist/commands/media/import.js.map +1 -1
- package/dist/commands/projects/__tests__/list.test.js +5 -4
- package/dist/commands/projects/__tests__/list.test.js.map +1 -1
- package/dist/commands/projects/list.js +2 -6
- package/dist/commands/projects/list.js.map +1 -1
- package/dist/commands/schema/__tests__/delete.test.js +396 -151
- package/dist/commands/schema/__tests__/delete.test.js.map +1 -1
- package/dist/commands/schema/__tests__/deploy.test.js +348 -0
- package/dist/commands/schema/__tests__/deploy.test.js.map +1 -0
- package/dist/commands/schema/__tests__/extract.test.js +19 -11
- package/dist/commands/schema/__tests__/extract.test.js.map +1 -1
- package/dist/commands/schema/__tests__/list.test.js +399 -0
- package/dist/commands/schema/__tests__/list.test.js.map +1 -0
- package/dist/commands/schema/__tests__/validate.test.js +27 -10
- package/dist/commands/schema/__tests__/validate.test.js.map +1 -1
- package/dist/commands/schema/delete.d.ts +1 -1
- package/dist/commands/schema/delete.js +20 -23
- package/dist/commands/schema/delete.js.map +1 -1
- package/dist/commands/schema/deploy.d.ts +16 -0
- package/dist/commands/schema/deploy.js +98 -0
- package/dist/commands/schema/deploy.js.map +1 -0
- package/dist/commands/schema/list.d.ts +15 -0
- package/dist/commands/schema/list.js +104 -0
- package/dist/commands/schema/list.js.map +1 -0
- package/dist/commands/telemetry/__tests__/disable.test.js +7 -5
- package/dist/commands/telemetry/__tests__/disable.test.js.map +1 -1
- package/dist/commands/telemetry/__tests__/enable.test.js +7 -5
- package/dist/commands/telemetry/__tests__/enable.test.js.map +1 -1
- package/dist/commands/telemetry/__tests__/status.test.js +7 -5
- package/dist/commands/telemetry/__tests__/status.test.js.map +1 -1
- package/dist/commands/tokens/__tests__/add.test.js +55 -40
- package/dist/commands/tokens/__tests__/add.test.js.map +1 -1
- package/dist/commands/tokens/__tests__/delete.test.js +72 -42
- package/dist/commands/tokens/__tests__/delete.test.js.map +1 -1
- package/dist/commands/tokens/__tests__/list.test.js +87 -60
- package/dist/commands/tokens/__tests__/list.test.js.map +1 -1
- package/dist/commands/tokens/add.js +3 -5
- package/dist/commands/tokens/add.js.map +1 -1
- package/dist/commands/users/__tests__/invite.test.js +100 -79
- package/dist/commands/users/__tests__/invite.test.js.map +1 -1
- package/dist/commands/users/__tests__/list.test.js +186 -180
- package/dist/commands/users/__tests__/list.test.js.map +1 -1
- package/dist/commands/users/invite.js +6 -17
- package/dist/commands/users/invite.js.map +1 -1
- package/dist/commands/users/list.js +4 -7
- package/dist/commands/users/list.js.map +1 -1
- package/dist/config/createCliConfig.d.ts +4 -4
- package/dist/services/backup.d.ts +8 -0
- package/dist/services/backup.js +19 -0
- package/dist/services/backup.js.map +1 -1
- package/dist/services/cors.d.ts +23 -0
- package/dist/services/cors.js +38 -0
- package/dist/services/cors.js.map +1 -0
- package/dist/services/graphql.d.ts +7 -0
- package/dist/services/graphql.js +11 -0
- package/dist/services/graphql.js.map +1 -1
- package/dist/services/hooks.d.ts +2 -0
- package/dist/services/hooks.js +19 -0
- package/dist/services/hooks.js.map +1 -1
- package/dist/services/organizations.d.ts +1 -1
- package/dist/services/organizations.js +1 -1
- package/dist/services/organizations.js.map +1 -1
- package/dist/services/projects.d.ts +11 -0
- package/dist/services/projects.js +41 -0
- package/dist/services/projects.js.map +1 -1
- package/dist/services/schemas.d.ts +4 -0
- package/dist/services/schemas.js +40 -0
- package/dist/services/schemas.js.map +1 -0
- package/dist/services/user.d.ts +8 -0
- package/dist/services/user.js +15 -2
- package/dist/services/user.js.map +1 -1
- package/dist/util/__tests__/getCliVersion.test.js +2 -2
- package/dist/util/__tests__/getCliVersion.test.js.map +1 -1
- package/dist/util/errorMessages.d.ts +1 -0
- package/dist/util/errorMessages.js +1 -0
- package/dist/util/errorMessages.js.map +1 -1
- package/dist/util/getCliVersion.js +1 -1
- package/dist/util/getCliVersion.js.map +1 -1
- package/dist/util/readPackageJson.d.ts +1 -15
- package/dist/util/readPackageJson.js +1 -1
- package/dist/util/readPackageJson.js.map +1 -1
- package/dist/util/uniqBy.d.ts +1 -0
- package/dist/util/uniqBy.js +14 -0
- package/dist/util/uniqBy.js.map +1 -0
- package/oclif.manifest.json +172 -27
- package/package.json +27 -28
- package/dist/actions/cors/constants.d.ts +0 -1
- package/dist/actions/cors/constants.js +0 -3
- package/dist/actions/cors/constants.js.map +0 -1
- package/dist/actions/cors/types.d.ts +0 -9
- package/dist/actions/cors/types.js +0 -3
- package/dist/actions/cors/types.js.map +0 -1
- package/dist/actions/schema/__tests__/deleteSchemaAction.test.js +0 -294
- package/dist/actions/schema/__tests__/deleteSchemaAction.test.js.map +0 -1
- package/dist/actions/schema/schemaStoreConstants.d.ts +0 -1
- package/dist/actions/schema/schemaStoreConstants.js +0 -4
- package/dist/actions/schema/schemaStoreConstants.js.map +0 -1
- package/dist/actions/schema/utils/schemaActionHelpers.d.ts +0 -1
- package/dist/actions/schema/utils/schemaActionHelpers.js +0 -5
- package/dist/actions/schema/utils/schemaActionHelpers.js.map +0 -1
- package/dist/actions/schema/utils/schemaApiClient.d.ts +0 -6
- package/dist/actions/schema/utils/schemaApiClient.js +0 -17
- package/dist/actions/schema/utils/schemaApiClient.js.map +0 -1
- package/dist/actions/users/apiVersion.d.ts +0 -6
- package/dist/actions/users/apiVersion.js +0 -7
- package/dist/actions/users/apiVersion.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/commands/graphql/__tests__/undeploy.test.ts"],"sourcesContent":["import {runCommand} from '@oclif/test'\nimport {getCliConfig} from '@sanity/cli-core'\nimport {mockApi, testCommand} from '@sanity/cli-test'\nimport nock from 'nock'\nimport {createSchema} from 'sanity'\nimport {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {getGraphQLAPIs} from '../../../actions/graphql/getGraphQLAPIs.js'\nimport {GRAPHQL_API_VERSION} from '../../../services/graphql.js'\nimport {NO_PROJECT_ID} from '../../../util/errorMessages.js'\nimport {Undeploy} from '../undeploy.js'\n\n// Mock the config functions\nvi.mock('../../../../../cli-core/src/config/findProjectRoot.js', () => ({\n findProjectRoot: vi.fn().mockResolvedValue({\n directory: '/test/path',\n root: '/test/path',\n type: 'studio',\n }),\n}))\n\nvi.mock('../../../../../cli-core/src/config/cli/getCliConfig.js', () => ({\n getCliConfig: vi.fn().mockResolvedValue({\n api: {\n dataset: 'production',\n projectId: 'test-project',\n },\n }),\n}))\n\nvi.mock('../../../../../cli-core/src/services/getCliToken.js', () => ({\n getCliToken: vi.fn().mockResolvedValue('test-token'),\n}))\n\n// Mock getGraphQLAPIs\nvi.mock('../../../actions/graphql/getGraphQLAPIs.js', () => ({\n getGraphQLAPIs: vi.fn(),\n}))\n\nconst mockGetCliConfig = vi.mocked(getCliConfig)\nconst mockGetGraphQLAPIs = vi.mocked(getGraphQLAPIs)\nconst mockConfirm = vi.hoisted(() => vi.fn())\nconst schema = createSchema({name: 'default', types: []})\n\n// Mock inquirer prompts\nvi.mock('@sanity/cli-core/ux', () => ({\n confirm: mockConfirm,\n}))\n\ndescribe('graphql undeploy', () => {\n beforeEach(() => {\n vi.clearAllMocks()\n // Reset getCliConfig to default values for each test\n mockGetCliConfig.mockResolvedValue({\n api: {\n dataset: 'production',\n projectId: 'test-project',\n },\n })\n })\n\n afterEach(() => {\n const pending = nock.pendingMocks()\n nock.cleanAll()\n expect(pending, 'pending mocks').toEqual([])\n })\n\n test('--help works', async () => {\n const {stdout} = await runCommand(['graphql undeploy', '--help'])\n\n expect(stdout).toMatchInlineSnapshot(`\n \"Remove a deployed GraphQL API\n\n USAGE\n $ sanity graphql undeploy [--api <value>] [--dataset <value>] [--force]\n [--project <value>] [--tag <value>]\n\n FLAGS\n --api=<value> Undeploy API with this ID (project, dataset and tag flags\n take precedence)\n --dataset=<value> Dataset to undeploy GraphQL API from\n --force Skip confirmation prompt\n --project=<value> Project ID to delete GraphQL API for\n --tag=<value> [default: default] Tag to undeploy GraphQL API from\n\n DESCRIPTION\n Remove a deployed GraphQL API\n\n EXAMPLES\n Undeploy GraphQL API for current project and dataset\n\n $ sanity graphql undeploy\n\n Undeploy API with ID \"ios\"\n\n $ sanity graphql undeploy --api ios\n\n Undeploy GraphQL API for staging dataset\n\n $ sanity graphql undeploy --dataset staging\n\n Undeploy GraphQL API for staging dataset with \"next\" tag\n\n $ sanity graphql undeploy --dataset staging --tag next\n\n Undeploy GraphQL API without confirmation prompt\n\n $ sanity graphql undeploy --force\n\n \"\n `)\n })\n\n test('successfully undeploys GraphQL API with default tag', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy)\n\n expect(mockConfirm).toHaveBeenCalledWith({\n default: false,\n message:\n 'Are you absolutely sure you want to delete the current GraphQL API connected to the \"production\" dataset in project test-project?',\n })\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('successfully undeploys GraphQL API with custom tag', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/beta',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--tag', 'beta'])\n\n expect(mockConfirm).toHaveBeenCalledWith({\n default: false,\n message:\n 'Are you absolutely sure you want to delete the GraphQL API connected to the \"production\" dataset in project test-project, tagged \"beta\"?',\n })\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('successfully undeploys with --dataset flag', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/staging/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--dataset', 'staging'])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('uses --project flag when specified', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://custom-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--project', 'custom-project', '--force'])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('successfully undeploys with all flags combined', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockApi({\n apiHost: 'https://custom-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/staging/experimental',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, [\n '--project',\n 'custom-project',\n '--dataset',\n 'staging',\n '--tag',\n 'experimental',\n ])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(mockConfirm).toHaveBeenCalledWith({\n default: false,\n message:\n 'Are you absolutely sure you want to delete the GraphQL API connected to the \"staging\" dataset in project custom-project, tagged \"experimental\"?',\n })\n })\n\n test('successfully undeploys with --force flag (skips confirmation)', async () => {\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--force'])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(mockConfirm).not.toHaveBeenCalled()\n })\n\n test('cancels deletion when user declines confirmation', async () => {\n mockConfirm.mockResolvedValue(false)\n const {stdout} = await testCommand(Undeploy)\n expect(stdout).toBe('Operation cancelled\\n')\n expect(nock.pendingMocks()).toHaveLength(0) // No API call should be made\n })\n\n test('successfully undeploys with --api flag', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'ios-dataset',\n id: 'ios',\n projectId: 'test-project',\n schema,\n tag: 'mobile',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/ios-dataset/mobile',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--api', 'ios'])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(mockGetGraphQLAPIs).toHaveBeenCalledWith(process.cwd())\n })\n\n test('throws error when --api flag references non-existent API', async () => {\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'production',\n id: 'web',\n projectId: 'test-project',\n schema,\n tag: 'default',\n },\n ])\n\n const {error} = await testCommand(Undeploy, ['--api', 'ios'])\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('GraphQL API \"ios\" not found')\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('warns when both --api and --dataset are specified', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'ios-dataset',\n id: 'ios',\n projectId: 'test-project',\n schema,\n tag: 'default',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/staging/default',\n }).reply(204)\n\n const {stderr, stdout} = await testCommand(Undeploy, ['--api', 'ios', '--dataset', 'staging'])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(stderr).toContain('Both --api and --dataset specified, using --dataset staging')\n })\n\n test('warns when both --api and --project are specified', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'production',\n id: 'ios',\n projectId: 'ios-project',\n schema,\n tag: 'default',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stderr, stdout} = await testCommand(Undeploy, [\n '--api',\n 'ios',\n '--project',\n 'test-project',\n ])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(stderr).toContain('Both --api and --project specified, using --project test-project')\n })\n\n test('warns when both --api and --tag are specified', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'production',\n id: 'ios',\n projectId: 'test-project',\n schema,\n tag: 'mobile',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/beta',\n }).reply(204)\n\n const {stderr, stdout} = await testCommand(Undeploy, ['--api', 'ios', '--tag', 'beta'])\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(stderr).toContain('Both --api and --tag specified, using --tag beta')\n })\n\n test('throws error when project ID is not defined', async () => {\n mockGetCliConfig.mockResolvedValue({\n api: {\n dataset: 'production',\n projectId: undefined,\n },\n })\n\n const {error} = await testCommand(Undeploy, ['--force'])\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toEqual(NO_PROJECT_ID)\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('throws error when dataset is not defined and not in config', async () => {\n mockGetCliConfig.mockResolvedValue({\n api: {\n dataset: undefined,\n projectId: 'test-project',\n },\n })\n\n const {error} = await testCommand(Undeploy, ['--force'])\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain(\n 'Dataset is required. Specify it with --dataset or configure it in your project.',\n )\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('handles API deletion error', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(404, {message: 'GraphQL API not found'})\n\n const {error} = await testCommand(Undeploy)\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('GraphQL API deletion failed')\n expect(error?.message).toContain('GraphQL API not found')\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('handles user cancelling confirmation prompt', async () => {\n mockConfirm.mockRejectedValue(new Error('User cancelled'))\n\n const {error} = await testCommand(Undeploy)\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toBe('Operation cancelled')\n expect(error?.oclif?.exit).toBe(1)\n })\n})\n"],"names":["runCommand","getCliConfig","mockApi","testCommand","nock","createSchema","afterEach","beforeEach","describe","expect","test","vi","getGraphQLAPIs","GRAPHQL_API_VERSION","NO_PROJECT_ID","Undeploy","mock","findProjectRoot","fn","mockResolvedValue","directory","root","type","api","dataset","projectId","getCliToken","mockGetCliConfig","mocked","mockGetGraphQLAPIs","mockConfirm","hoisted","schema","name","types","confirm","clearAllMocks","pending","pendingMocks","cleanAll","toEqual","stdout","toMatchInlineSnapshot","mockResolvedValueOnce","apiHost","apiVersion","method","uri","reply","toHaveBeenCalledWith","default","message","toBe","not","toHaveBeenCalled","toHaveLength","id","tag","process","cwd","error","toBeInstanceOf","Error","toContain","oclif","exit","stderr","undefined","mockRejectedValue"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAa;AACtC,SAAQC,YAAY,QAAO,mBAAkB;AAC7C,SAAQC,OAAO,EAAEC,WAAW,QAAO,mBAAkB;AACrD,OAAOC,UAAU,OAAM;AACvB,SAAQC,YAAY,QAAO,SAAQ;AACnC,SAAQC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAExE,SAAQC,cAAc,QAAO,6CAA4C;AACzE,SAAQC,mBAAmB,QAAO,+BAA8B;AAChE,SAAQC,aAAa,QAAO,iCAAgC;AAC5D,SAA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CAAC;QAE9BjB,QAAQ;YACN0C,SAAS;YACTC,YAAYhC;YACZiC,QAAQ;YACRC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAK;YAACG,SAAS;QAAuB;QAE/C,MAAM,EAACS,KAAK,EAAC,GAAG,MAAMzD,YAAYY;QAElCN,OAAOmD,OAAOC,cAAc,CAACC;QAC7BrD,OAAOmD,OAAOT,SAASY,SAAS,CAAC;QACjCtD,OAAOmD,OAAOT,SAASY,SAAS,CAAC;QACjCtD,OAAOmD,OAAOI,OAAOC,MAAMb,IAAI,CAAC;IAClC;IAEA1C,KAAK,+CAA+C;QAClDoB,YAAYsC,iBAAiB,CAAC,IAAIN,MAAM;QAExC,MAAM,EAACF,KAAK,EAAC,GAAG,MAAMzD,YAAYY;QAElCN,OAAOmD,OAAOC,cAAc,CAACC;QAC7BrD,OAAOmD,OAAOT,SAASC,IAAI,CAAC;QAC5B3C,OAAOmD,OAAOI,OAAOC,MAAMb,IAAI,CAAC;IAClC;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/graphql/__tests__/undeploy.test.ts"],"sourcesContent":["import {runCommand} from '@oclif/test'\nimport {mockApi, testCommand} from '@sanity/cli-test'\nimport nock from 'nock'\nimport {createSchema} from 'sanity'\nimport {afterEach, beforeEach, describe, expect, test, vi} from 'vitest'\n\nimport {getGraphQLAPIs} from '../../../actions/graphql/getGraphQLAPIs.js'\nimport {GRAPHQL_API_VERSION} from '../../../services/graphql.js'\nimport {NO_PROJECT_ID} from '../../../util/errorMessages.js'\nimport {Undeploy} from '../undeploy.js'\n\n// Mock getGraphQLAPIs\nvi.mock('../../../actions/graphql/getGraphQLAPIs.js', () => ({\n getGraphQLAPIs: vi.fn(),\n}))\n\nconst testProjectId = 'test-project'\n\nconst defaultMocks = {\n cliConfig: {api: {dataset: 'production', projectId: testProjectId}},\n projectRoot: {\n directory: '/test/path',\n path: '/test/path/sanity.config.ts',\n type: 'studio' as const,\n },\n token: 'test-token',\n}\n\nconst mockGetGraphQLAPIs = vi.mocked(getGraphQLAPIs)\nconst mockConfirm = vi.hoisted(() => vi.fn())\nconst schema = createSchema({name: 'default', types: []})\n\nvi.mock('@sanity/cli-core/ux', async () => {\n const actual = await vi.importActual<typeof import('@sanity/cli-core/ux')>('@sanity/cli-core/ux')\n return {\n ...actual,\n confirm: mockConfirm,\n }\n})\n\ndescribe('graphql undeploy', () => {\n beforeEach(() => {\n vi.clearAllMocks()\n })\n\n afterEach(() => {\n const pending = nock.pendingMocks()\n nock.cleanAll()\n expect(pending, 'pending mocks').toEqual([])\n })\n\n test('--help works', async () => {\n const {stdout} = await runCommand(['graphql undeploy', '--help'])\n\n expect(stdout).toMatchInlineSnapshot(`\n \"Remove a deployed GraphQL API\n\n USAGE\n $ sanity graphql undeploy [--api <value>] [--dataset <value>] [--force]\n [--project <value>] [--tag <value>]\n\n FLAGS\n --api=<value> Undeploy API with this ID (project, dataset and tag flags\n take precedence)\n --dataset=<value> Dataset to undeploy GraphQL API from\n --force Skip confirmation prompt\n --project=<value> Project ID to delete GraphQL API for\n --tag=<value> [default: default] Tag to undeploy GraphQL API from\n\n DESCRIPTION\n Remove a deployed GraphQL API\n\n EXAMPLES\n Undeploy GraphQL API for current project and dataset\n\n $ sanity graphql undeploy\n\n Undeploy API with ID \"ios\"\n\n $ sanity graphql undeploy --api ios\n\n Undeploy GraphQL API for staging dataset\n\n $ sanity graphql undeploy --dataset staging\n\n Undeploy GraphQL API for staging dataset with \"next\" tag\n\n $ sanity graphql undeploy --dataset staging --tag next\n\n Undeploy GraphQL API without confirmation prompt\n\n $ sanity graphql undeploy --force\n\n \"\n `)\n })\n\n test('successfully undeploys GraphQL API with default tag', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, [], {mocks: defaultMocks})\n\n expect(mockConfirm).toHaveBeenCalledWith({\n default: false,\n message:\n 'Are you absolutely sure you want to delete the current GraphQL API connected to the \"production\" dataset in project test-project?',\n })\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('successfully undeploys GraphQL API with custom tag', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/beta',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--tag', 'beta'], {mocks: defaultMocks})\n\n expect(mockConfirm).toHaveBeenCalledWith({\n default: false,\n message:\n 'Are you absolutely sure you want to delete the GraphQL API connected to the \"production\" dataset in project test-project, tagged \"beta\"?',\n })\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('successfully undeploys with --dataset flag', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/staging/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--dataset', 'staging'], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('uses --project flag when specified', async () => {\n mockConfirm.mockResolvedValueOnce(true)\n\n mockApi({\n apiHost: 'https://custom-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--project', 'custom-project', '--force'], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n })\n\n test('successfully undeploys with all flags combined', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockApi({\n apiHost: 'https://custom-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/staging/experimental',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, [\n '--project',\n 'custom-project',\n '--dataset',\n 'staging',\n '--tag',\n 'experimental',\n ], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(mockConfirm).toHaveBeenCalledWith({\n default: false,\n message:\n 'Are you absolutely sure you want to delete the GraphQL API connected to the \"staging\" dataset in project custom-project, tagged \"experimental\"?',\n })\n })\n\n test('successfully undeploys with --force flag (skips confirmation)', async () => {\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--force'], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(mockConfirm).not.toHaveBeenCalled()\n })\n\n test('cancels deletion when user declines confirmation', async () => {\n mockConfirm.mockResolvedValue(false)\n const {stdout} = await testCommand(Undeploy, [], {mocks: defaultMocks})\n expect(stdout).toBe('Operation cancelled\\n')\n expect(nock.pendingMocks()).toHaveLength(0) // No API call should be made\n })\n\n test('successfully undeploys with --api flag', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'ios-dataset',\n id: 'ios',\n projectId: 'test-project',\n schema,\n tag: 'mobile',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/ios-dataset/mobile',\n }).reply(204)\n\n const {stdout} = await testCommand(Undeploy, ['--api', 'ios'], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(mockGetGraphQLAPIs).toHaveBeenCalledWith(process.cwd())\n })\n\n test('throws error when --api flag references non-existent API', async () => {\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'production',\n id: 'web',\n projectId: 'test-project',\n schema,\n tag: 'default',\n },\n ])\n\n const {error} = await testCommand(Undeploy, ['--api', 'ios'], {mocks: defaultMocks})\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('GraphQL API \"ios\" not found')\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('warns when both --api and --dataset are specified', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'ios-dataset',\n id: 'ios',\n projectId: 'test-project',\n schema,\n tag: 'default',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/staging/default',\n }).reply(204)\n\n const {stderr, stdout} = await testCommand(Undeploy, ['--api', 'ios', '--dataset', 'staging'], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(stderr).toContain('Both --api and --dataset specified, using --dataset staging')\n })\n\n test('warns when both --api and --project are specified', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'production',\n id: 'ios',\n projectId: 'ios-project',\n schema,\n tag: 'default',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(204)\n\n const {stderr, stdout} = await testCommand(Undeploy, [\n '--api',\n 'ios',\n '--project',\n 'test-project',\n ], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(stderr).toContain('Both --api and --project specified, using --project test-project')\n })\n\n test('warns when both --api and --tag are specified', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockGetGraphQLAPIs.mockResolvedValueOnce([\n {\n dataset: 'production',\n id: 'ios',\n projectId: 'test-project',\n schema,\n tag: 'mobile',\n },\n ])\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/beta',\n }).reply(204)\n\n const {stderr, stdout} = await testCommand(Undeploy, ['--api', 'ios', '--tag', 'beta'], {mocks: defaultMocks})\n\n expect(stdout).toBe('GraphQL API deleted\\n')\n expect(stderr).toContain('Both --api and --tag specified, using --tag beta')\n })\n\n test('throws error when project ID is not defined', async () => {\n const {error} = await testCommand(Undeploy, ['--force'], {\n mocks: {\n ...defaultMocks,\n cliConfig: {api: {dataset: 'production', projectId: undefined}},\n },\n })\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toEqual(NO_PROJECT_ID)\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('throws error when dataset is not defined and not in config', async () => {\n const {error} = await testCommand(Undeploy, ['--force'], {\n mocks: {\n ...defaultMocks,\n cliConfig: {api: {dataset: undefined, projectId: testProjectId}},\n },\n })\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain(\n 'Dataset is required. Specify it with --dataset or configure it in your project.',\n )\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('handles API deletion error', async () => {\n mockConfirm.mockResolvedValue(true)\n\n mockApi({\n apiHost: 'https://test-project.api.sanity.io',\n apiVersion: GRAPHQL_API_VERSION,\n method: 'delete',\n uri: '/apis/graphql/production/default',\n }).reply(404, {message: 'GraphQL API not found'})\n\n const {error} = await testCommand(Undeploy, [], {mocks: defaultMocks})\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('GraphQL API deletion failed')\n expect(error?.message).toContain('GraphQL API not found')\n expect(error?.oclif?.exit).toBe(1)\n })\n\n test('handles user cancelling confirmation prompt', async () => {\n mockConfirm.mockRejectedValue(new Error('User cancelled'))\n\n const {error} = await testCommand(Undeploy, [], {mocks: defaultMocks})\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toBe('Operation cancelled')\n expect(error?.oclif?.exit).toBe(1)\n })\n})\n"],"names":["runCommand","mockApi","testCommand","nock","createSchema","afterEach","beforeEach","describe","expect","test","vi","getGraphQLAPIs","GRAPHQL_API_VERSION","NO_PROJECT_ID","Undeploy","mock","fn","testProjectId","defaultMocks","cliConfig","api","dataset","projectId","projectRoot","directory","path","type","token","mockGetGraphQLAPIs","mocked","mockConfirm","hoisted","schema","name","types","actual","importActual","confirm","clearAllMocks","pending","pendingMocks","cleanAll","toEqual","stdout","toMatchInlineSnapshot","mockResolvedValueOnce","apiHost","apiVersion","method","uri","reply","mocks","toHaveBeenCalledWith","default","message","toBe","mockResolvedValue","not","toHaveBeenCalled","toHaveLength","id","tag","process","cwd","error","toBeInstanceOf","Error","toContain","oclif","exit","stderr","undefined","mockRejectedValue"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAa;AACtC,SAAQC,OAAO,EAAEC,WAAW,QAAO,mBAAkB;AACrD,OAAOC,UAAU,OAAM;AACvB,SAAQC,YAAY,QAAO,SAAQ;AACnC,SAAQC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAExE,SAAQC,cAAc,QAAO,6CAA4C;AACzE,SAAQC,mBAAmB,QAAO,+BAA8B;AAChE,SAAQC,aAAa,QAAO,iCAAgC;AAC5D,SAAQC,QAAQ,QAAO,iBAAgB;AAEvC,sBAAsB;AACtBJ,GAAGK,IAAI,CAAC,8CAA8C,IAAO,CAAA;QAC3DJ,gBAAgBD,GAAGM,EAAE;IACvB,CAAA;AAEA,MAAMC,gBAAgB;AAEtB,MAAMC,eAAe;IACnBC,WAAW;QAACC,KAAK;YAACC,SAAS;YAAcC,WAAWL;QAAa;IAAC;IAClEM,aAAa;QACXC,WAAW;QACXC,MAAM;QACNC,MAAM;IACR;IACAC,OAAO;AACT;AAEA,MAAMC,qBAAqBlB,GAAGmB,MAAM,CAAClB;AACrC,MAAMmB,cAAcpB,GAAGqB,OAAO,CAAC,IAAMrB,GAAGM,EAAE;AAC1C,MAAMgB,SAAS5B,aAAa;IAAC6B,MAAM;IAAWC,OAAO,EAAE;AAAA;AAEvDxB,GAAGK,IAAI,CAAC,uBAAuB;IAC7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Y0C,iBAAiB,CAAC,IAAIN,MAAM;QAExC,MAAM,EAACF,KAAK,EAAC,GAAG,MAAM9D,YAAYY,UAAU,EAAE,EAAE;YAACqC,OAAOjC;QAAY;QAEpEV,OAAOwD,OAAOC,cAAc,CAACC;QAC7B1D,OAAOwD,OAAOV,SAASC,IAAI,CAAC;QAC5B/C,OAAOwD,OAAOI,OAAOC,MAAMd,IAAI,CAAC;IAClC;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
1
|
+
import { getProjectCliClient, SanityCommand, subdebug } from '@sanity/cli-core';
|
|
2
2
|
import { chalk } from '@sanity/cli-core/ux';
|
|
3
3
|
import { GRAPHQL_API_VERSION, listGraphQLEndpoints } from '../../services/graphql.js';
|
|
4
4
|
import { NO_PROJECT_ID } from '../../util/errorMessages.js';
|
|
@@ -33,7 +33,7 @@ export class List extends SanityCommand {
|
|
|
33
33
|
this.log("This project doesn't have any GraphQL endpoints deployed.");
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
const client = await
|
|
36
|
+
const client = await getProjectCliClient({
|
|
37
37
|
apiVersion: GRAPHQL_API_VERSION,
|
|
38
38
|
projectId
|
|
39
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/graphql/list.ts"],"sourcesContent":["import {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {chalk} from '@sanity/cli-core/ux'\n\nimport {\n GRAPHQL_API_VERSION,\n type GraphQLEndpoint,\n listGraphQLEndpoints,\n} from '../../services/graphql.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\n\nconst listGraphQLDebug = subdebug('graphql:list')\n\nexport class List extends SanityCommand<typeof List> {\n static override description = 'List all GraphQL endpoints deployed for this project'\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List GraphQL endpoints for the current project',\n },\n ]\n\n public async run(): Promise<void> {\n await this.parse(List)\n\n const projectId = await this.getProjectId()\n if (!projectId) {\n this.error(NO_PROJECT_ID, {exit: 1})\n }\n\n let endpoints: GraphQLEndpoint[] | undefined\n try {\n endpoints = await listGraphQLEndpoints(projectId)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n\n listGraphQLDebug(`Error fetching GraphQL endpoints for project ${projectId}`, error)\n this.error(`GraphQL endpoints list retrieval failed:\\n${message}`, {exit: 1})\n }\n\n if (!endpoints || endpoints.length === 0) {\n this.log(\"This project doesn't have any GraphQL endpoints deployed.\")\n return\n }\n\n const client = await
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/graphql/list.ts"],"sourcesContent":["import {getProjectCliClient, SanityCommand, subdebug} from '@sanity/cli-core'\nimport {chalk} from '@sanity/cli-core/ux'\n\nimport {\n GRAPHQL_API_VERSION,\n type GraphQLEndpoint,\n listGraphQLEndpoints,\n} from '../../services/graphql.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\n\nconst listGraphQLDebug = subdebug('graphql:list')\n\nexport class List extends SanityCommand<typeof List> {\n static override description = 'List all GraphQL endpoints deployed for this project'\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'List GraphQL endpoints for the current project',\n },\n ]\n\n public async run(): Promise<void> {\n await this.parse(List)\n\n const projectId = await this.getProjectId()\n if (!projectId) {\n this.error(NO_PROJECT_ID, {exit: 1})\n }\n\n let endpoints: GraphQLEndpoint[] | undefined\n try {\n endpoints = await listGraphQLEndpoints(projectId)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n\n listGraphQLDebug(`Error fetching GraphQL endpoints for project ${projectId}`, error)\n this.error(`GraphQL endpoints list retrieval failed:\\n${message}`, {exit: 1})\n }\n\n if (!endpoints || endpoints.length === 0) {\n this.log(\"This project doesn't have any GraphQL endpoints deployed.\")\n return\n }\n\n const client = await getProjectCliClient({\n apiVersion: GRAPHQL_API_VERSION,\n projectId,\n })\n\n this.log('Here are the GraphQL endpoints deployed for this project:')\n for (const [index, endpoint] of endpoints.entries()) {\n const {dataset, tag} = endpoint\n const url = client.getUrl(`/graphql/${dataset}/${tag}`)\n\n this.log(`${index + 1}. ${chalk.bold('Dataset:')} ${dataset}`)\n this.log(` ${chalk.bold('Tag:')} ${tag}`)\n this.log(` ${chalk.bold('Generation:')} ${endpoint.generation}`)\n this.log(` ${chalk.bold('Playground:')} ${endpoint.playgroundEnabled}`)\n this.log(` ${chalk.bold('URL:')} ${url}\\n`)\n }\n }\n}\n"],"names":["getProjectCliClient","SanityCommand","subdebug","chalk","GRAPHQL_API_VERSION","listGraphQLEndpoints","NO_PROJECT_ID","listGraphQLDebug","List","description","examples","command","run","parse","projectId","getProjectId","error","exit","endpoints","message","Error","String","length","log","client","apiVersion","index","endpoint","entries","dataset","tag","url","getUrl","bold","generation","playgroundEnabled"],"mappings":"AAAA,SAAQA,mBAAmB,EAAEC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC7E,SAAQC,KAAK,QAAO,sBAAqB;AAEzC,SACEC,mBAAmB,EAEnBC,oBAAoB,QACf,4BAA2B;AAClC,SAAQC,aAAa,QAAO,8BAA6B;AAEzD,MAAMC,mBAAmBL,SAAS;AAElC,OAAO,MAAMM,aAAaP;IACxB,OAAgBQ,cAAc,uDAAsD;IACpF,OAAgBC,WAAW;QACzB;YACEC,SAAS;YACTF,aAAa;QACf;KACD,CAAA;IAED,MAAaG,MAAqB;QAChC,MAAM,IAAI,CAACC,KAAK,CAACL;QAEjB,MAAMM,YAAY,MAAM,IAAI,CAACC,YAAY;QACzC,IAAI,CAACD,WAAW;YACd,IAAI,CAACE,KAAK,CAACV,eAAe;gBAACW,MAAM;YAAC;QACpC;QAEA,IAAIC;QACJ,IAAI;YACFA,YAAY,MAAMb,qBAAqBS;QACzC,EAAE,OAAOE,OAAO;YACd,MAAMG,UAAUH,iBAAiBI,QAAQJ,MAAMG,OAAO,GAAGE,OAAOL;YAEhET,iBAAiB,CAAC,6CAA6C,EAAEO,WAAW,EAAEE;YAC9E,IAAI,CAACA,KAAK,CAAC,CAAC,0CAA0C,EAAEG,SAAS,EAAE;gBAACF,MAAM;YAAC;QAC7E;QAEA,IAAI,CAACC,aAAaA,UAAUI,MAAM,KAAK,GAAG;YACxC,IAAI,CAACC,GAAG,CAAC;YACT;QACF;QAEA,MAAMC,SAAS,MAAMxB,oBAAoB;YACvCyB,YAAYrB;YACZU;QACF;QAEA,IAAI,CAACS,GAAG,CAAC;QACT,KAAK,MAAM,CAACG,OAAOC,SAAS,IAAIT,UAAUU,OAAO,GAAI;YACnD,MAAM,EAACC,OAAO,EAAEC,GAAG,EAAC,GAAGH;YACvB,MAAMI,MAAMP,OAAOQ,MAAM,CAAC,CAAC,SAAS,EAAEH,QAAQ,CAAC,EAAEC,KAAK;YAEtD,IAAI,CAACP,GAAG,CAAC,GAAGG,QAAQ,EAAE,GAAG,EAAEvB,MAAM8B,IAAI,CAAC,YAAY,KAAK,EAAEJ,SAAS;YAClE,IAAI,CAACN,GAAG,CAAC,CAAC,IAAI,EAAEpB,MAAM8B,IAAI,CAAC,QAAQ,SAAS,EAAEH,KAAK;YACnD,IAAI,CAACP,GAAG,CAAC,CAAC,IAAI,EAAEpB,MAAM8B,IAAI,CAAC,eAAe,EAAE,EAAEN,SAASO,UAAU,EAAE;YACnE,IAAI,CAACX,GAAG,CAAC,CAAC,IAAI,EAAEpB,MAAM8B,IAAI,CAAC,eAAe,EAAE,EAAEN,SAASQ,iBAAiB,EAAE;YAC1E,IAAI,CAACZ,GAAG,CAAC,CAAC,IAAI,EAAEpB,MAAM8B,IAAI,CAAC,QAAQ,EAAE,EAAEF,IAAI,EAAE,CAAC;QAChD;IACF;AACF"}
|
|
@@ -2,7 +2,7 @@ import { Flags } from '@oclif/core';
|
|
|
2
2
|
import { SanityCommand, subdebug } from '@sanity/cli-core';
|
|
3
3
|
import { confirm } from '@sanity/cli-core/ux';
|
|
4
4
|
import { getGraphQLAPIs } from '../../actions/graphql/getGraphQLAPIs.js';
|
|
5
|
-
import {
|
|
5
|
+
import { deleteGraphQLAPI } from '../../services/graphql.js';
|
|
6
6
|
import { NO_PROJECT_ID } from '../../util/errorMessages.js';
|
|
7
7
|
const undeployGraphqlDebug = subdebug('graphql:undeploy');
|
|
8
8
|
export class Undeploy extends SanityCommand {
|
|
@@ -123,16 +123,11 @@ export class Undeploy extends SanityCommand {
|
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
// Delete the GraphQL API
|
|
127
126
|
try {
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
await deleteGraphQLAPI({
|
|
128
|
+
dataset,
|
|
130
129
|
projectId,
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
await client.request({
|
|
134
|
-
method: 'DELETE',
|
|
135
|
-
uri: `/apis/graphql/${dataset}/${tag}`
|
|
130
|
+
tag
|
|
136
131
|
});
|
|
137
132
|
this.log('GraphQL API deleted');
|
|
138
133
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/graphql/undeploy.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm} from '@sanity/cli-core/ux'\n\nimport {getGraphQLAPIs} from '../../actions/graphql/getGraphQLAPIs.js'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/graphql/undeploy.ts"],"sourcesContent":["import {Flags} from '@oclif/core'\nimport {SanityCommand, subdebug} from '@sanity/cli-core'\nimport {confirm} from '@sanity/cli-core/ux'\n\nimport {getGraphQLAPIs} from '../../actions/graphql/getGraphQLAPIs.js'\nimport {deleteGraphQLAPI} from '../../services/graphql.js'\nimport {NO_PROJECT_ID} from '../../util/errorMessages.js'\n\nconst undeployGraphqlDebug = subdebug('graphql:undeploy')\n\nexport class Undeploy extends SanityCommand<typeof Undeploy> {\n static override description = 'Remove a deployed GraphQL API'\n\n static override examples = [\n {\n command: '<%= config.bin %> <%= command.id %>',\n description: 'Undeploy GraphQL API for current project and dataset',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --api ios',\n description: 'Undeploy API with ID \"ios\"',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --dataset staging',\n description: 'Undeploy GraphQL API for staging dataset',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --dataset staging --tag next',\n description: 'Undeploy GraphQL API for staging dataset with \"next\" tag',\n },\n {\n command: '<%= config.bin %> <%= command.id %> --force',\n description: 'Undeploy GraphQL API without confirmation prompt',\n },\n ]\n\n static override flags = {\n api: Flags.string({\n description: 'Undeploy API with this ID (project, dataset and tag flags take precedence)',\n required: false,\n }),\n dataset: Flags.string({\n description: 'Dataset to undeploy GraphQL API from',\n required: false,\n }),\n force: Flags.boolean({\n description: 'Skip confirmation prompt',\n required: false,\n }),\n project: Flags.string({\n description: 'Project ID to delete GraphQL API for',\n required: false,\n }),\n tag: Flags.string({\n default: 'default',\n description: 'Tag to undeploy GraphQL API from',\n required: false,\n }),\n }\n\n public async run(): Promise<void> {\n const {flags} = await this.parse(Undeploy)\n const {api: apiFlag, dataset: datasetFlag, force, project: projectFlag, tag: tagFlag} = flags\n\n let projectId = projectFlag\n let dataset = datasetFlag\n let tag = tagFlag\n\n // If specifying --api, use it for the flags not provided\n if (apiFlag) {\n const workDir = process.cwd()\n const apiDefs = await getGraphQLAPIs(workDir)\n const apiDef = apiDefs.find((def) => def.id === apiFlag)\n\n if (!apiDef) {\n this.error(`GraphQL API \"${apiFlag}\" not found`, {exit: 1})\n }\n\n if (projectId && projectId !== apiDef.projectId) {\n this.warn(`Both --api and --project specified, using --project ${projectId}`)\n } else {\n projectId = apiDef.projectId\n }\n\n if (dataset && dataset !== apiDef.dataset) {\n this.warn(`Both --api and --dataset specified, using --dataset ${dataset}`)\n } else {\n dataset = apiDef.dataset\n }\n\n if (tag && tag !== 'default' && apiDef.tag && tag !== apiDef.tag) {\n this.warn(`Both --api and --tag specified, using --tag ${tag}`)\n } else {\n tag = apiDef.tag || 'default'\n }\n }\n\n // Get projectId from config if not specified\n if (!projectId) {\n projectId = await this.getProjectId()\n if (!projectId) {\n this.error(NO_PROJECT_ID, {exit: 1})\n }\n }\n\n // Get dataset from CLI config if not specified\n if (!dataset) {\n const cliConfig = await this.getCliConfig()\n dataset = cliConfig.api?.dataset\n }\n\n if (!dataset) {\n this.error(\n 'Dataset is required. Specify it with --dataset or configure it in your project.',\n {\n exit: 1,\n },\n )\n }\n\n // Confirm deletion unless --force is used\n if (!force) {\n const confirmMessage =\n tag === 'default'\n ? `Are you absolutely sure you want to delete the current GraphQL API connected to the \"${dataset}\" dataset in project ${projectId}?`\n : `Are you absolutely sure you want to delete the GraphQL API connected to the \"${dataset}\" dataset in project ${projectId}, tagged \"${tag}\"?`\n\n try {\n const confirmed = await confirm({\n default: false,\n message: confirmMessage,\n })\n\n if (!confirmed) {\n this.log('Operation cancelled')\n return\n }\n } catch (error) {\n const err = error instanceof Error ? error : new Error(`${error}`)\n undeployGraphqlDebug('User cancelled', err)\n this.error('Operation cancelled', {exit: 1})\n }\n }\n\n try {\n await deleteGraphQLAPI({\n dataset,\n projectId,\n tag,\n })\n\n this.log('GraphQL API deleted')\n } catch (error) {\n const err = error instanceof Error ? error : new Error(`${error}`)\n undeployGraphqlDebug(`Error deleting GraphQL API for ${dataset}/${tag}`, err)\n this.error(`GraphQL API deletion failed:\\n${err.message}`, {exit: 1})\n }\n }\n}\n"],"names":["Flags","SanityCommand","subdebug","confirm","getGraphQLAPIs","deleteGraphQLAPI","NO_PROJECT_ID","undeployGraphqlDebug","Undeploy","description","examples","command","flags","api","string","required","dataset","force","boolean","project","tag","default","run","parse","apiFlag","datasetFlag","projectFlag","tagFlag","projectId","workDir","process","cwd","apiDefs","apiDef","find","def","id","error","exit","warn","getProjectId","cliConfig","getCliConfig","confirmMessage","confirmed","message","log","err","Error"],"mappings":"AAAA,SAAQA,KAAK,QAAO,cAAa;AACjC,SAAQC,aAAa,EAAEC,QAAQ,QAAO,mBAAkB;AAC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AAU,UAAU,EAAER,IAAI,EAAE,CAAC;YAElJ,IAAI;gBACF,MAAMwB,YAAY,MAAMzC,QAAQ;oBAC9BkB,SAAS;oBACTwB,SAASF;gBACX;gBAEA,IAAI,CAACC,WAAW;oBACd,IAAI,CAACE,GAAG,CAAC;oBACT;gBACF;YACF,EAAE,OAAOT,OAAO;gBACd,MAAMU,MAAMV,iBAAiBW,QAAQX,QAAQ,IAAIW,MAAM,GAAGX,OAAO;gBACjE9B,qBAAqB,kBAAkBwC;gBACvC,IAAI,CAACV,KAAK,CAAC,uBAAuB;oBAACC,MAAM;gBAAC;YAC5C;QACF;QAEA,IAAI;YACF,MAAMjC,iBAAiB;gBACrBW;gBACAY;gBACAR;YACF;YAEA,IAAI,CAAC0B,GAAG,CAAC;QACX,EAAE,OAAOT,OAAO;YACd,MAAMU,MAAMV,iBAAiBW,QAAQX,QAAQ,IAAIW,MAAM,GAAGX,OAAO;YACjE9B,qBAAqB,CAAC,+BAA+B,EAAES,QAAQ,CAAC,EAAEI,KAAK,EAAE2B;YACzE,IAAI,CAACV,KAAK,CAAC,CAAC,8BAA8B,EAAEU,IAAIF,OAAO,EAAE,EAAE;gBAACP,MAAM;YAAC;QACrE;IACF;AACF"}
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import { runCommand } from '@oclif/test';
|
|
2
|
-
import { getCliConfig } from '@sanity/cli-core';
|
|
3
2
|
import { mockApi, testCommand } from '@sanity/cli-test';
|
|
4
3
|
import nock from 'nock';
|
|
5
4
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
6
5
|
import { HOOK_API_VERSION } from '../../../actions/hook/constants.js';
|
|
7
6
|
import { NO_PROJECT_ID } from '../../../util/errorMessages.js';
|
|
8
7
|
import { AttemptHookCommand } from '../attempt.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
};
|
|
26
|
-
});
|
|
8
|
+
const testProjectId = 'test-project';
|
|
9
|
+
const defaultMocks = {
|
|
10
|
+
cliConfig: {
|
|
11
|
+
api: {
|
|
12
|
+
projectId: testProjectId
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
projectRoot: {
|
|
16
|
+
directory: '/test/path',
|
|
17
|
+
path: '/test/path/sanity.config.ts',
|
|
18
|
+
type: 'studio'
|
|
19
|
+
},
|
|
20
|
+
token: 'test-token'
|
|
21
|
+
};
|
|
27
22
|
describe('#attempt', ()=>{
|
|
28
23
|
afterEach(()=>{
|
|
29
24
|
vi.clearAllMocks();
|
|
@@ -78,7 +73,9 @@ describe('#attempt', ()=>{
|
|
|
78
73
|
}).reply(200, mockAttempt);
|
|
79
74
|
const { stdout } = await testCommand(AttemptHookCommand, [
|
|
80
75
|
'attempt123'
|
|
81
|
-
]
|
|
76
|
+
], {
|
|
77
|
+
mocks: defaultMocks
|
|
78
|
+
});
|
|
82
79
|
expect(stdout).toContain('Date: 2023-01-01T12:00:00Z');
|
|
83
80
|
expect(stdout).toContain('Status: Delivered');
|
|
84
81
|
expect(stdout).toContain('Status code: 200');
|
|
@@ -106,7 +103,9 @@ describe('#attempt', ()=>{
|
|
|
106
103
|
}).reply(200, mockAttempt);
|
|
107
104
|
const { stdout } = await testCommand(AttemptHookCommand, [
|
|
108
105
|
'attempt123'
|
|
109
|
-
]
|
|
106
|
+
], {
|
|
107
|
+
mocks: defaultMocks
|
|
108
|
+
});
|
|
110
109
|
expect(stdout).toContain('Date: 2023-01-01T12:00:00Z');
|
|
111
110
|
expect(stdout).toContain('Status: Failed');
|
|
112
111
|
expect(stdout).toContain('Status code: 404');
|
|
@@ -135,7 +134,9 @@ describe('#attempt', ()=>{
|
|
|
135
134
|
}).reply(200, mockAttempt);
|
|
136
135
|
const { stdout } = await testCommand(AttemptHookCommand, [
|
|
137
136
|
'attempt123'
|
|
138
|
-
]
|
|
137
|
+
], {
|
|
138
|
+
mocks: defaultMocks
|
|
139
|
+
});
|
|
139
140
|
expect(stdout).toContain('Date: 2023-01-01T12:00:00Z');
|
|
140
141
|
expect(stdout).toContain('Status: Failed');
|
|
141
142
|
expect(stdout).toContain('Status code: 0');
|
|
@@ -163,7 +164,9 @@ describe('#attempt', ()=>{
|
|
|
163
164
|
}).reply(200, mockAttempt);
|
|
164
165
|
const { stdout } = await testCommand(AttemptHookCommand, [
|
|
165
166
|
'attempt123'
|
|
166
|
-
]
|
|
167
|
+
], {
|
|
168
|
+
mocks: defaultMocks
|
|
169
|
+
});
|
|
167
170
|
expect(stdout).toContain('Date: 2023-01-01T12:00:00Z');
|
|
168
171
|
expect(stdout).toContain('Status: Failed');
|
|
169
172
|
expect(stdout).toContain('Status code: 0');
|
|
@@ -191,7 +194,9 @@ describe('#attempt', ()=>{
|
|
|
191
194
|
}).reply(200, mockAttempt);
|
|
192
195
|
const { stdout } = await testCommand(AttemptHookCommand, [
|
|
193
196
|
'attempt123'
|
|
194
|
-
]
|
|
197
|
+
], {
|
|
198
|
+
mocks: defaultMocks
|
|
199
|
+
});
|
|
195
200
|
expect(stdout).toContain('Date: 2023-01-01T12:00:00Z');
|
|
196
201
|
expect(stdout).toContain('Status: In progress');
|
|
197
202
|
expect(stdout).toContain('Status code: 0');
|
|
@@ -219,7 +224,9 @@ describe('#attempt', ()=>{
|
|
|
219
224
|
}).reply(200, mockAttempt);
|
|
220
225
|
const { stdout } = await testCommand(AttemptHookCommand, [
|
|
221
226
|
'attempt123'
|
|
222
|
-
]
|
|
227
|
+
], {
|
|
228
|
+
mocks: defaultMocks
|
|
229
|
+
});
|
|
223
230
|
expect(stdout).toContain('Date: 2023-01-01T12:00:00Z');
|
|
224
231
|
expect(stdout).toContain('Status: Delivered');
|
|
225
232
|
expect(stdout).toContain('Status code: 204');
|
|
@@ -234,24 +241,32 @@ describe('#attempt', ()=>{
|
|
|
234
241
|
});
|
|
235
242
|
const { error } = await testCommand(AttemptHookCommand, [
|
|
236
243
|
'attempt123'
|
|
237
|
-
]
|
|
244
|
+
], {
|
|
245
|
+
mocks: defaultMocks
|
|
246
|
+
});
|
|
238
247
|
expect(error).toBeInstanceOf(Error);
|
|
239
248
|
expect(error?.message).toContain('Hook attempt retrieval failed');
|
|
240
249
|
});
|
|
241
250
|
test('requires attempt ID argument', async ()=>{
|
|
242
|
-
const { error } = await testCommand(AttemptHookCommand, []
|
|
251
|
+
const { error } = await testCommand(AttemptHookCommand, [], {
|
|
252
|
+
mocks: defaultMocks
|
|
253
|
+
});
|
|
243
254
|
expect(error).toBeInstanceOf(Error);
|
|
244
255
|
expect(error?.message).toContain('Missing 1 required arg');
|
|
245
256
|
});
|
|
246
257
|
test('throws error when no project ID is found', async ()=>{
|
|
247
|
-
vi.mocked(getCliConfig).mockResolvedValueOnce({
|
|
248
|
-
api: {
|
|
249
|
-
projectId: undefined
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
258
|
const { error } = await testCommand(AttemptHookCommand, [
|
|
253
259
|
'attempt123'
|
|
254
|
-
]
|
|
260
|
+
], {
|
|
261
|
+
mocks: {
|
|
262
|
+
...defaultMocks,
|
|
263
|
+
cliConfig: {
|
|
264
|
+
api: {
|
|
265
|
+
projectId: undefined
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
255
270
|
expect(error).toBeInstanceOf(Error);
|
|
256
271
|
expect(error?.message).toEqual(NO_PROJECT_ID);
|
|
257
272
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/commands/hook/__tests__/attempt.test.ts"],"sourcesContent":["import {runCommand} from '@oclif/test'\nimport {getCliConfig} from '@sanity/cli-core'\nimport {mockApi, testCommand} from '@sanity/cli-test'\nimport nock from 'nock'\nimport {afterEach, describe, expect, test, vi} from 'vitest'\n\nimport {HOOK_API_VERSION} from '../../../actions/hook/constants.js'\nimport {type DeliveryAttempt} from '../../../actions/hook/types.js'\nimport {NO_PROJECT_ID} from '../../../util/errorMessages.js'\nimport {AttemptHookCommand} from '../attempt.js'\n\nvi.mock('../../../../../cli-core/src/config/findProjectRoot.js', async () => {\n return {\n findProjectRoot: vi.fn().mockResolvedValue({\n directory: '/test/path',\n root: '/test/path',\n type: 'studio',\n }),\n }\n})\n\nvi.mock('../../../../../cli-core/src/config/cli/getCliConfig.js', async () => {\n return {\n getCliConfig: vi.fn().mockResolvedValue({\n api: {\n projectId: 'test-project',\n },\n }),\n }\n})\n\ndescribe('#attempt', () => {\n afterEach(() => {\n vi.clearAllMocks()\n const pending = nock.pendingMocks()\n nock.cleanAll()\n expect(pending, 'pending mocks').toEqual([])\n })\n\n test('--help works', async () => {\n const {stdout} = await runCommand(['hook attempt', '--help'])\n\n expect(stdout).toContain('Print details of a given webhook delivery attempt')\n expect(stdout).toMatchInlineSnapshot(`\n \"Print details of a given webhook delivery attempt\n\n USAGE\n $ sanity hook attempt ATTEMPTID\n\n ARGUMENTS\n ATTEMPTID The delivery attempt ID to get details for\n\n DESCRIPTION\n Print details of a given webhook delivery attempt\n\n EXAMPLES\n Print details of webhook delivery attempt with ID abc123\n\n $ sanity hook attempt abc123\n\n \"\n `)\n })\n\n test('displays successful delivery attempt details', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: 1500,\n failureReason: '',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: false,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: 'Success response body',\n resultCode: 200,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Delivered')\n expect(stdout).toContain('Status code: 200')\n expect(stdout).toContain('Response body:')\n expect(stdout).toContain('Success response body')\n })\n\n test('displays failed delivery attempt with HTTP error', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: 500,\n failureReason: 'http',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: true,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: 'Error response body',\n resultCode: 404,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Failed')\n expect(stdout).toContain('Status code: 404')\n expect(stdout).toContain('Failure: HTTP 404')\n expect(stdout).toContain('Response body:')\n expect(stdout).toContain('Error response body')\n })\n\n test('displays failed delivery attempt with network error', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: null,\n failureReason: 'network',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: true,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 0,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Failed')\n expect(stdout).toContain('Status code: 0')\n expect(stdout).toContain('Failure: Network error')\n expect(stdout).not.toContain('Response body:')\n })\n\n test('displays failed delivery attempt with timeout', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: null,\n failureReason: 'timeout',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: true,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 0,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Failed')\n expect(stdout).toContain('Status code: 0')\n expect(stdout).toContain('Failure: Request timed out')\n expect(stdout).not.toContain('Response body:')\n })\n\n test('displays in-progress delivery attempt', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: null,\n failureReason: '',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: true,\n isFailure: false,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 0,\n updatedAt: null,\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: In progress')\n expect(stdout).toContain('Status code: 0')\n expect(stdout).not.toContain('Failure:')\n expect(stdout).not.toContain('Response body:')\n })\n\n test('handles empty response body', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: 1000,\n failureReason: '',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: false,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 204,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Delivered')\n expect(stdout).toContain('Status code: 204')\n expect(stdout).toContain('Response body: <empty>')\n })\n\n test('displays error when API request fails', async () => {\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(404, {message: 'Attempt not found'})\n\n const {error} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('Hook attempt retrieval failed')\n })\n\n test('requires attempt ID argument', async () => {\n const {error} = await testCommand(AttemptHookCommand, [])\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('Missing 1 required arg')\n })\n\n test('throws error when no project ID is found', async () => {\n vi.mocked(getCliConfig).mockResolvedValueOnce({\n api: {\n projectId: undefined,\n },\n })\n\n const {error} = await testCommand(AttemptHookCommand, ['attempt123'])\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toEqual(NO_PROJECT_ID)\n })\n})\n"],"names":["runCommand","getCliConfig","mockApi","testCommand","nock","afterEach","describe","expect","test","vi","HOOK_API_VERSION","NO_PROJECT_ID","AttemptHookCommand","mock","findProjectRoot","fn","mockResolvedValue","directory","root","type","api","projectId","clearAllMocks","pending","pendingMocks","cleanAll","toEqual","stdout","toContain","toMatchInlineSnapshot","mockAttempt","createdAt","duration","failureReason","hookId","id","inProgress","isFailure","messageId","resultBody","resultCode","updatedAt","apiVersion","uri","reply","not","message","error","toBeInstanceOf","Error","mocked","mockResolvedValueOnce","undefined"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAa;AACtC,SAAQC,YAAY,QAAO,mBAAkB;AAC7C,SAAQC,OAAO,EAAEC,WAAW,QAAO,mBAAkB;AACrD,OAAOC,UAAU,OAAM;AACvB,SAAQC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAE5D,SAAQC,gBAA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YAAY;YACZC,WAAW;QACb;QAEAvC,QAAQ;YACNwC,YAAYhC;YACZiC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAKd;QAEd,MAAM,EAACH,MAAM,EAAC,GAAG,MAAMxB,YAAYS,oBAAoB;YAAC;SAAa;QAErEL,OAAOoB,QAAQC,SAAS,CAAC;QACzBrB,OAAOoB,QAAQC,SAAS,CAAC;QACzBrB,OAAOoB,QAAQC,SAAS,CAAC;QACzBrB,OAAOoB,QAAQC,SAAS,CAAC;IAC3B;IAEApB,KAAK,yCAAyC;QAC5CN,QAAQ;YACNwC,YAAYhC;YACZiC,KAAK;QACP,GAAGC,KAAK,CAAC,KAAK;YAACE,SAAS;QAAmB;QAE3C,MAAM,EAACC,KAAK,EAAC,GAAG,MAAM5C,YAAYS,oBAAoB;YAAC;SAAa;QAEpEL,OAAOwC,OAAOC,cAAc,CAACC;QAC7B1C,OAAOwC,OAAOD,SAASlB,SAAS,CAAC;IACnC;IAEApB,KAAK,gCAAgC;QACnC,MAAM,EAACuC,KAAK,EAAC,GAAG,MAAM5C,YAAYS,oBAAoB,EAAE;QAExDL,OAAOwC,OAAOC,cAAc,CAACC;QAC7B1C,OAAOwC,OAAOD,SAASlB,SAAS,CAAC;IACnC;IAEApB,KAAK,4CAA4C;QAC/CC,GAAGyC,MAAM,CAACjD,cAAckD,qBAAqB,CAAC;YAC5C/B,KAAK;gBACHC,WAAW+B;YACb;QACF;QAEA,MAAM,EAACL,KAAK,EAAC,GAAG,MAAM5C,YAAYS,oBAAoB;YAAC;SAAa;QAEpEL,OAAOwC,OAAOC,cAAc,CAACC;QAC7B1C,OAAOwC,OAAOD,SAASpB,OAAO,CAACf;IACjC;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/hook/__tests__/attempt.test.ts"],"sourcesContent":["import {runCommand} from '@oclif/test'\nimport {mockApi, testCommand} from '@sanity/cli-test'\nimport nock from 'nock'\nimport {afterEach, describe, expect, test, vi} from 'vitest'\n\nimport {HOOK_API_VERSION} from '../../../actions/hook/constants.js'\nimport {type DeliveryAttempt} from '../../../actions/hook/types.js'\nimport {NO_PROJECT_ID} from '../../../util/errorMessages.js'\nimport {AttemptHookCommand} from '../attempt.js'\n\nconst testProjectId = 'test-project'\n\nconst defaultMocks = {\n cliConfig: {api: {projectId: testProjectId}},\n projectRoot: {\n directory: '/test/path',\n path: '/test/path/sanity.config.ts',\n type: 'studio' as const,\n },\n token: 'test-token',\n}\n\ndescribe('#attempt', () => {\n afterEach(() => {\n vi.clearAllMocks()\n const pending = nock.pendingMocks()\n nock.cleanAll()\n expect(pending, 'pending mocks').toEqual([])\n })\n\n test('--help works', async () => {\n const {stdout} = await runCommand(['hook attempt', '--help'])\n\n expect(stdout).toContain('Print details of a given webhook delivery attempt')\n expect(stdout).toMatchInlineSnapshot(`\n \"Print details of a given webhook delivery attempt\n\n USAGE\n $ sanity hook attempt ATTEMPTID\n\n ARGUMENTS\n ATTEMPTID The delivery attempt ID to get details for\n\n DESCRIPTION\n Print details of a given webhook delivery attempt\n\n EXAMPLES\n Print details of webhook delivery attempt with ID abc123\n\n $ sanity hook attempt abc123\n\n \"\n `)\n })\n\n test('displays successful delivery attempt details', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: 1500,\n failureReason: '',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: false,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: 'Success response body',\n resultCode: 200,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Delivered')\n expect(stdout).toContain('Status code: 200')\n expect(stdout).toContain('Response body:')\n expect(stdout).toContain('Success response body')\n })\n\n test('displays failed delivery attempt with HTTP error', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: 500,\n failureReason: 'http',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: true,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: 'Error response body',\n resultCode: 404,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Failed')\n expect(stdout).toContain('Status code: 404')\n expect(stdout).toContain('Failure: HTTP 404')\n expect(stdout).toContain('Response body:')\n expect(stdout).toContain('Error response body')\n })\n\n test('displays failed delivery attempt with network error', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: null,\n failureReason: 'network',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: true,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 0,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Failed')\n expect(stdout).toContain('Status code: 0')\n expect(stdout).toContain('Failure: Network error')\n expect(stdout).not.toContain('Response body:')\n })\n\n test('displays failed delivery attempt with timeout', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: null,\n failureReason: 'timeout',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: true,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 0,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Failed')\n expect(stdout).toContain('Status code: 0')\n expect(stdout).toContain('Failure: Request timed out')\n expect(stdout).not.toContain('Response body:')\n })\n\n test('displays in-progress delivery attempt', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: null,\n failureReason: '',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: true,\n isFailure: false,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 0,\n updatedAt: null,\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: In progress')\n expect(stdout).toContain('Status code: 0')\n expect(stdout).not.toContain('Failure:')\n expect(stdout).not.toContain('Response body:')\n })\n\n test('handles empty response body', async () => {\n const mockAttempt: DeliveryAttempt = {\n createdAt: '2023-01-01T12:00:00Z',\n duration: 1000,\n failureReason: '',\n hookId: 'hook123',\n id: 'attempt123',\n inProgress: false,\n isFailure: false,\n messageId: 'msg123',\n projectId: 'proj123',\n resultBody: '',\n resultCode: 204,\n updatedAt: '2023-01-01T12:00:01Z',\n }\n\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(200, mockAttempt)\n\n const {stdout} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(stdout).toContain('Date: 2023-01-01T12:00:00Z')\n expect(stdout).toContain('Status: Delivered')\n expect(stdout).toContain('Status code: 204')\n expect(stdout).toContain('Response body: <empty>')\n })\n\n test('displays error when API request fails', async () => {\n mockApi({\n apiVersion: HOOK_API_VERSION,\n uri: '/hooks/projects/test-project/attempts/attempt123',\n }).reply(404, {message: 'Attempt not found'})\n\n const {error} = await testCommand(AttemptHookCommand, ['attempt123'], {mocks: defaultMocks})\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('Hook attempt retrieval failed')\n })\n\n test('requires attempt ID argument', async () => {\n const {error} = await testCommand(AttemptHookCommand, [], {mocks: defaultMocks})\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toContain('Missing 1 required arg')\n })\n\n test('throws error when no project ID is found', async () => {\n const {error} = await testCommand(AttemptHookCommand, ['attempt123'], {\n mocks: {\n ...defaultMocks,\n cliConfig: {api: {projectId: undefined}},\n },\n })\n\n expect(error).toBeInstanceOf(Error)\n expect(error?.message).toEqual(NO_PROJECT_ID)\n })\n})\n"],"names":["runCommand","mockApi","testCommand","nock","afterEach","describe","expect","test","vi","HOOK_API_VERSION","NO_PROJECT_ID","AttemptHookCommand","testProjectId","defaultMocks","cliConfig","api","projectId","projectRoot","directory","path","type","token","clearAllMocks","pending","pendingMocks","cleanAll","toEqual","stdout","toContain","toMatchInlineSnapshot","mockAttempt","createdAt","duration","failureReason","hookId","id","inProgress","isFailure","messageId","resultBody","resultCode","updatedAt","apiVersion","uri","reply","mocks","not","message","error","toBeInstanceOf","Error","undefined"],"mappings":"AAAA,SAAQA,UAAU,QAAO,cAAa;AACtC,SAAQC,OAAO,EAAEC,WAAW,QAAO,mBAAkB;AACrD,OAAOC,UAAU,OAAM;AACvB,SAAQC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAO,SAAQ;AAE5D,SAAQC,gBAAgB,QAAO,qCAAoC;A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|
|
3
|
-
import
|
|
4
|
-
import nock from 'nock';
|
|
2
|
+
import { testCommand } from '@sanity/cli-test';
|
|
3
|
+
import open from 'open';
|
|
5
4
|
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
6
|
-
import { HOOK_API_VERSION } from '../../../actions/hook/constants.js';
|
|
7
5
|
import { NO_PROJECT_ID } from '../../../util/errorMessages.js';
|
|
8
6
|
import { CreateHookCommand } from '../create.js';
|
|
9
7
|
vi.mock('open', ()=>({
|
|
10
8
|
default: vi.fn().mockResolvedValue(undefined)
|
|
11
9
|
}));
|
|
12
|
-
|
|
10
|
+
const testProjectId = 'test-project';
|
|
11
|
+
const defaultMocks = {
|
|
12
|
+
cliConfig: {
|
|
13
|
+
api: {
|
|
14
|
+
projectId: testProjectId
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
projectRoot: {
|
|
18
|
+
directory: '/test/path',
|
|
19
|
+
path: '/test/path/sanity.config.ts',
|
|
20
|
+
type: 'studio'
|
|
21
|
+
},
|
|
22
|
+
token: 'test-token'
|
|
23
|
+
};
|
|
24
|
+
const mockGetById = vi.hoisted(()=>vi.fn());
|
|
25
|
+
vi.mock('@sanity/cli-core', async ()=>{
|
|
26
|
+
const actual = await vi.importActual('@sanity/cli-core');
|
|
13
27
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
vi.mock('../../../../../cli-core/src/config/cli/getCliConfig.js', async ()=>{
|
|
22
|
-
return {
|
|
23
|
-
getCliConfig: vi.fn().mockResolvedValue({
|
|
24
|
-
api: {
|
|
25
|
-
projectId: 'test-project'
|
|
28
|
+
...actual,
|
|
29
|
+
getProjectCliClient: vi.fn().mockResolvedValue({
|
|
30
|
+
projects: {
|
|
31
|
+
getById: mockGetById
|
|
26
32
|
}
|
|
27
33
|
})
|
|
28
34
|
};
|
|
@@ -30,9 +36,6 @@ vi.mock('../../../../../cli-core/src/config/cli/getCliConfig.js', async ()=>{
|
|
|
30
36
|
describe('#hook:create', ()=>{
|
|
31
37
|
afterEach(()=>{
|
|
32
38
|
vi.clearAllMocks();
|
|
33
|
-
const pending = nock.pendingMocks();
|
|
34
|
-
nock.cleanAll();
|
|
35
|
-
expect(pending, 'pending mocks').toEqual([]);
|
|
36
39
|
});
|
|
37
40
|
test('--help works', async ()=>{
|
|
38
41
|
const { stdout } = await runCommand([
|
|
@@ -57,62 +60,57 @@ describe('#hook:create', ()=>{
|
|
|
57
60
|
`);
|
|
58
61
|
});
|
|
59
62
|
test('opens webhook creation URL for project with organization', async ()=>{
|
|
60
|
-
|
|
61
|
-
mockApi({
|
|
62
|
-
apiVersion: HOOK_API_VERSION,
|
|
63
|
-
uri: '/projects/test-project'
|
|
64
|
-
}).reply(200, {
|
|
63
|
+
mockGetById.mockResolvedValueOnce({
|
|
65
64
|
id: 'test-project',
|
|
66
65
|
organizationId: 'test-org'
|
|
67
66
|
});
|
|
68
|
-
const { stdout } = await testCommand(CreateHookCommand
|
|
69
|
-
|
|
67
|
+
const { stdout } = await testCommand(CreateHookCommand, [], {
|
|
68
|
+
mocks: defaultMocks
|
|
69
|
+
});
|
|
70
|
+
expect(open).toHaveBeenCalledWith('https://www.sanity.io/organizations/test-org/project/test-project/api/webhooks/new');
|
|
70
71
|
expect(stdout).toContain('Opening https://www.sanity.io/organizations/test-org/project/test-project/api/webhooks/new');
|
|
71
72
|
});
|
|
72
73
|
test('opens webhook creation URL for project without organization (personal)', async ()=>{
|
|
73
|
-
|
|
74
|
-
mockApi({
|
|
75
|
-
apiVersion: HOOK_API_VERSION,
|
|
76
|
-
uri: '/projects/test-project'
|
|
77
|
-
}).reply(200, {
|
|
74
|
+
mockGetById.mockResolvedValueOnce({
|
|
78
75
|
id: 'test-project'
|
|
79
76
|
});
|
|
80
|
-
const { stdout } = await testCommand(CreateHookCommand
|
|
81
|
-
|
|
77
|
+
const { stdout } = await testCommand(CreateHookCommand, [], {
|
|
78
|
+
mocks: defaultMocks
|
|
79
|
+
});
|
|
80
|
+
expect(open).toHaveBeenCalledWith('https://www.sanity.io/organizations/personal/project/test-project/api/webhooks/new');
|
|
82
81
|
expect(stdout).toContain('Opening https://www.sanity.io/organizations/personal/project/test-project/api/webhooks/new');
|
|
83
82
|
});
|
|
84
83
|
test('displays an error if the project fetch fails', async ()=>{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}).reply(500, {
|
|
89
|
-
message: 'Internal Server Error'
|
|
84
|
+
mockGetById.mockRejectedValueOnce(new Error('Internal Server Error'));
|
|
85
|
+
const { error } = await testCommand(CreateHookCommand, [], {
|
|
86
|
+
mocks: defaultMocks
|
|
90
87
|
});
|
|
91
|
-
const { error } = await testCommand(CreateHookCommand);
|
|
92
88
|
expect(error).toBeInstanceOf(Error);
|
|
93
89
|
expect(error?.message).toContain('Failed to fetch project information');
|
|
94
90
|
});
|
|
95
91
|
test('throws error when no project ID is found', async ()=>{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
const { error } = await testCommand(CreateHookCommand, [], {
|
|
93
|
+
mocks: {
|
|
94
|
+
...defaultMocks,
|
|
95
|
+
cliConfig: {
|
|
96
|
+
api: {
|
|
97
|
+
projectId: undefined
|
|
98
|
+
}
|
|
99
|
+
}
|
|
99
100
|
}
|
|
100
101
|
});
|
|
101
|
-
const { error } = await testCommand(CreateHookCommand);
|
|
102
102
|
expect(error).toBeInstanceOf(Error);
|
|
103
103
|
expect(error?.message).toEqual(NO_PROJECT_ID);
|
|
104
104
|
});
|
|
105
105
|
test('handles open failure gracefully', async ()=>{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
mockApi({
|
|
109
|
-
apiVersion: HOOK_API_VERSION,
|
|
110
|
-
uri: '/projects/test-project'
|
|
111
|
-
}).reply(200, {
|
|
106
|
+
vi.mocked(open).mockRejectedValueOnce(new Error('Failed to open browser'));
|
|
107
|
+
mockGetById.mockResolvedValueOnce({
|
|
112
108
|
id: 'test-project',
|
|
113
109
|
organizationId: 'test-org'
|
|
114
110
|
});
|
|
115
|
-
const { error } = await testCommand(CreateHookCommand
|
|
111
|
+
const { error } = await testCommand(CreateHookCommand, [], {
|
|
112
|
+
mocks: defaultMocks
|
|
113
|
+
});
|
|
116
114
|
expect(error).toBeInstanceOf(Error);
|
|
117
115
|
expect(error?.message).toContain('Failed to open browser');
|
|
118
116
|
});
|