@sanity/cli 6.0.0-alpha.5 → 6.0.0-alpha.6

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.
Files changed (461) hide show
  1. package/dist/actions/dataset/create.d.ts +49 -0
  2. package/dist/actions/dataset/create.js +48 -0
  3. package/dist/actions/dataset/create.js.map +1 -0
  4. package/dist/actions/dataset/determineDatasetAclMode.d.ts +37 -0
  5. package/dist/actions/dataset/determineDatasetAclMode.js +36 -0
  6. package/dist/actions/dataset/determineDatasetAclMode.js.map +1 -0
  7. package/dist/actions/debug/gatherDebugInfo.js +15 -21
  8. package/dist/actions/debug/gatherDebugInfo.js.map +1 -1
  9. package/dist/actions/debug/types.d.ts +0 -2
  10. package/dist/actions/debug/types.js.map +1 -1
  11. package/dist/actions/deploy/deployApp.js +13 -0
  12. package/dist/actions/deploy/deployApp.js.map +1 -1
  13. package/dist/actions/init/remoteTemplate.js +1 -1
  14. package/dist/actions/init/remoteTemplate.js.map +1 -1
  15. package/dist/actions/manifest/extractAppManifest.d.ts +20 -0
  16. package/dist/actions/manifest/extractAppManifest.js +51 -0
  17. package/dist/actions/manifest/extractAppManifest.js.map +1 -0
  18. package/dist/actions/manifest/extractManifest.js +1 -1
  19. package/dist/actions/manifest/extractManifest.js.map +1 -1
  20. package/dist/actions/manifest/types.d.ts +6 -1
  21. package/dist/actions/manifest/types.js.map +1 -1
  22. package/dist/actions/media/importAspects.js +2 -1
  23. package/dist/actions/media/importAspects.js.map +1 -1
  24. package/dist/actions/schema/utils/uniqByProjectIdDataset.d.ts +1 -1
  25. package/dist/commands/dataset/create.d.ts +0 -2
  26. package/dist/commands/dataset/create.js +8 -54
  27. package/dist/commands/dataset/create.js.map +1 -1
  28. package/dist/commands/debug.js +5 -9
  29. package/dist/commands/debug.js.map +1 -1
  30. package/dist/commands/init.d.ts +6 -1
  31. package/dist/commands/init.js +358 -20
  32. package/dist/commands/init.js.map +1 -1
  33. package/dist/commands/manifest/extract.js +7 -8
  34. package/dist/commands/manifest/extract.js.map +1 -1
  35. package/dist/config/createCliConfig.d.ts +9 -0
  36. package/dist/prompts/init/promptForTypescript.d.ts +2 -0
  37. package/dist/prompts/init/promptForTypescript.js +15 -0
  38. package/dist/prompts/init/promptForTypescript.js.map +1 -0
  39. package/dist/prompts/promptForDatasetAclMode.d.ts +9 -0
  40. package/dist/prompts/promptForDatasetAclMode.js +27 -0
  41. package/dist/prompts/promptForDatasetAclMode.js.map +1 -0
  42. package/dist/prompts/promptForDatasetName.d.ts +1 -1
  43. package/dist/prompts/promptForDatasetName.js +4 -1
  44. package/dist/prompts/promptForDatasetName.js.map +1 -1
  45. package/dist/services/organizations.d.ts +3 -1
  46. package/dist/services/organizations.js +2 -1
  47. package/dist/services/organizations.js.map +1 -1
  48. package/dist/services/user.d.ts +5 -0
  49. package/dist/services/user.js +12 -1
  50. package/dist/services/user.js.map +1 -1
  51. package/dist/services/userApplications.d.ts +3 -1
  52. package/dist/services/userApplications.js +5 -1
  53. package/dist/services/userApplications.js.map +1 -1
  54. package/oclif.manifest.json +113 -113
  55. package/package.json +16 -12
  56. package/templates/app-quickstart/src/App.css +20 -0
  57. package/templates/app-quickstart/src/App.tsx +25 -0
  58. package/templates/app-quickstart/src/ExampleComponent.css +90 -0
  59. package/templates/app-quickstart/src/ExampleComponent.tsx +37 -0
  60. package/templates/app-sanity-ui/src/App.tsx +34 -0
  61. package/templates/app-sanity-ui/src/ExampleComponent.tsx +34 -0
  62. package/templates/app-sanity-ui/src/SanityUI.tsx +23 -0
  63. package/templates/blog/README.md +11 -0
  64. package/templates/blog/schemaTypes/author.js +50 -0
  65. package/templates/blog/schemaTypes/blockContent.js +67 -0
  66. package/templates/blog/schemaTypes/category.js +19 -0
  67. package/templates/blog/schemaTypes/index.js +6 -0
  68. package/templates/blog/schemaTypes/post.js +65 -0
  69. package/templates/blog/static/.gitkeep +1 -0
  70. package/templates/clean/README.md +9 -0
  71. package/templates/clean/schemaTypes/index.js +1 -0
  72. package/templates/clean/static/.gitkeep +1 -0
  73. package/templates/ecommerce/README.md +11 -0
  74. package/templates/ecommerce/plugins/.gitkeep +1 -0
  75. package/templates/ecommerce/plugins/barcode-input/BarcodeInput.js +62 -0
  76. package/templates/ecommerce/plugins/barcode-input/index.js +9 -0
  77. package/templates/ecommerce/plugins/barcode-input/schemaType.js +60 -0
  78. package/templates/ecommerce/schemaTypes/blockContent.js +67 -0
  79. package/templates/ecommerce/schemaTypes/category.js +39 -0
  80. package/templates/ecommerce/schemaTypes/index.js +23 -0
  81. package/templates/ecommerce/schemaTypes/locale/localeBlockContent.js +19 -0
  82. package/templates/ecommerce/schemaTypes/locale/localeString.js +19 -0
  83. package/templates/ecommerce/schemaTypes/locale/localeText.js +19 -0
  84. package/templates/ecommerce/schemaTypes/locale/supportedLanguages.js +5 -0
  85. package/templates/ecommerce/schemaTypes/product.js +83 -0
  86. package/templates/ecommerce/schemaTypes/productVariant.js +52 -0
  87. package/templates/ecommerce/schemaTypes/vendor.js +39 -0
  88. package/templates/ecommerce/static/.gitkeep +1 -0
  89. package/templates/get-started/README.md +9 -0
  90. package/templates/get-started/plugins/.gitkeep +1 -0
  91. package/templates/get-started/plugins/sanity-plugin-tutorial/CustomDefaultLayout.tsx +16 -0
  92. package/templates/get-started/plugins/sanity-plugin-tutorial/GetStartedTutorial.tsx +104 -0
  93. package/templates/get-started/plugins/sanity-plugin-tutorial/index.ts +11 -0
  94. package/templates/get-started/schemaTypes/index.ts +1 -0
  95. package/templates/get-started/static/.gitkeep +1 -0
  96. package/templates/moviedb/README.md +10 -0
  97. package/templates/moviedb/schemaTypes/blockContent.js +67 -0
  98. package/templates/moviedb/schemaTypes/castMember.js +37 -0
  99. package/templates/moviedb/schemaTypes/crewMember.js +52 -0
  100. package/templates/moviedb/schemaTypes/index.js +22 -0
  101. package/templates/moviedb/schemaTypes/movie.js +85 -0
  102. package/templates/moviedb/schemaTypes/person.js +37 -0
  103. package/templates/moviedb/schemaTypes/plotSummaries.js +20 -0
  104. package/templates/moviedb/schemaTypes/plotSummary.js +24 -0
  105. package/templates/moviedb/schemaTypes/screening.js +81 -0
  106. package/templates/moviedb/static/.gitkeep +1 -0
  107. package/templates/quickstart/README.md +9 -0
  108. package/templates/quickstart/schemaTypes/index.js +1 -0
  109. package/templates/quickstart/static/.gitkeep +1 -0
  110. package/templates/shared/gitignore.txt +29 -0
  111. package/templates/shared/tsconfig.json +17 -0
  112. package/templates/shopify/README.md +85 -0
  113. package/templates/shopify/components/hotspots/ProductTooltip.tsx +38 -0
  114. package/templates/shopify/components/icons/Shopify.tsx +20 -0
  115. package/templates/shopify/components/inputs/CollectionHidden.tsx +23 -0
  116. package/templates/shopify/components/inputs/PlaceholderString.tsx +20 -0
  117. package/templates/shopify/components/inputs/ProductHidden.tsx +64 -0
  118. package/templates/shopify/components/inputs/ProductVariantHidden.tsx +24 -0
  119. package/templates/shopify/components/inputs/ProxyString.tsx +32 -0
  120. package/templates/shopify/components/media/ColorTheme.tsx +38 -0
  121. package/templates/shopify/components/media/ShopifyDocumentStatus.tsx +82 -0
  122. package/templates/shopify/components/studio/Navbar.tsx +29 -0
  123. package/templates/shopify/constants.ts +61 -0
  124. package/templates/shopify/docs/features.md +158 -0
  125. package/templates/shopify/plugins/customDocumentActions/index.ts +55 -0
  126. package/templates/shopify/plugins/customDocumentActions/shopifyDelete.tsx +144 -0
  127. package/templates/shopify/plugins/customDocumentActions/shopifyLink.ts +39 -0
  128. package/templates/shopify/plugins/customDocumentActions/types.ts +14 -0
  129. package/templates/shopify/schemaTypes/documents/collection.tsx +142 -0
  130. package/templates/shopify/schemaTypes/documents/colorTheme.tsx +44 -0
  131. package/templates/shopify/schemaTypes/documents/page.ts +70 -0
  132. package/templates/shopify/schemaTypes/documents/product.tsx +132 -0
  133. package/templates/shopify/schemaTypes/documents/productVariant.tsx +67 -0
  134. package/templates/shopify/schemaTypes/index.ts +108 -0
  135. package/templates/shopify/schemaTypes/objects/collection/collectionGroupType.ts +27 -0
  136. package/templates/shopify/schemaTypes/objects/collection/collectionLinksType.ts +16 -0
  137. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorObjectType.tsx +48 -0
  138. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionColorType.tsx +50 -0
  139. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeObjectType.ts +40 -0
  140. package/templates/shopify/schemaTypes/objects/customProductOption/customProductOptionSizeType.ts +49 -0
  141. package/templates/shopify/schemaTypes/objects/global/footerType.ts +22 -0
  142. package/templates/shopify/schemaTypes/objects/global/menuLinksType.ts +21 -0
  143. package/templates/shopify/schemaTypes/objects/global/menuType.ts +17 -0
  144. package/templates/shopify/schemaTypes/objects/global/notFoundPageType.ts +37 -0
  145. package/templates/shopify/schemaTypes/objects/hotspot/imageWithProductHotspotsType.ts +48 -0
  146. package/templates/shopify/schemaTypes/objects/hotspot/productHotspotsType.tsx +17 -0
  147. package/templates/shopify/schemaTypes/objects/hotspot/spotType.tsx +60 -0
  148. package/templates/shopify/schemaTypes/objects/link/linkEmailType.tsx +34 -0
  149. package/templates/shopify/schemaTypes/objects/link/linkExternalType.tsx +37 -0
  150. package/templates/shopify/schemaTypes/objects/link/linkInternalType.tsx +33 -0
  151. package/templates/shopify/schemaTypes/objects/link/linkProductType.tsx +60 -0
  152. package/templates/shopify/schemaTypes/objects/module/accordionGroupType.ts +33 -0
  153. package/templates/shopify/schemaTypes/objects/module/accordionType.ts +28 -0
  154. package/templates/shopify/schemaTypes/objects/module/callToActionType.tsx +85 -0
  155. package/templates/shopify/schemaTypes/objects/module/calloutType.ts +38 -0
  156. package/templates/shopify/schemaTypes/objects/module/collectionReferenceType.tsx +47 -0
  157. package/templates/shopify/schemaTypes/objects/module/gridItemType.ts +41 -0
  158. package/templates/shopify/schemaTypes/objects/module/gridType.ts +28 -0
  159. package/templates/shopify/schemaTypes/objects/module/heroType.tsx +40 -0
  160. package/templates/shopify/schemaTypes/objects/module/imageCallToActionType.tsx +19 -0
  161. package/templates/shopify/schemaTypes/objects/module/imageFeatureType.ts +80 -0
  162. package/templates/shopify/schemaTypes/objects/module/imageFeaturesType.tsx +51 -0
  163. package/templates/shopify/schemaTypes/objects/module/instagramType.ts +35 -0
  164. package/templates/shopify/schemaTypes/objects/module/productFeaturesType.tsx +50 -0
  165. package/templates/shopify/schemaTypes/objects/module/productReferenceType.tsx +42 -0
  166. package/templates/shopify/schemaTypes/objects/seoType.ts +31 -0
  167. package/templates/shopify/schemaTypes/objects/shopify/collectionRuleType.tsx +37 -0
  168. package/templates/shopify/schemaTypes/objects/shopify/inventoryType.ts +25 -0
  169. package/templates/shopify/schemaTypes/objects/shopify/optionType.tsx +31 -0
  170. package/templates/shopify/schemaTypes/objects/shopify/placeholderStringType.ts +11 -0
  171. package/templates/shopify/schemaTypes/objects/shopify/priceRangeType.ts +20 -0
  172. package/templates/shopify/schemaTypes/objects/shopify/productWithVariantType.tsx +142 -0
  173. package/templates/shopify/schemaTypes/objects/shopify/proxyStringType.ts +12 -0
  174. package/templates/shopify/schemaTypes/objects/shopify/shopType.ts +15 -0
  175. package/templates/shopify/schemaTypes/objects/shopify/shopifyCollectionType.ts +84 -0
  176. package/templates/shopify/schemaTypes/objects/shopify/shopifyProductType.ts +131 -0
  177. package/templates/shopify/schemaTypes/objects/shopify/shopifyProductVariantType.ts +121 -0
  178. package/templates/shopify/schemaTypes/portableText/portableTextSimpleType.tsx +45 -0
  179. package/templates/shopify/schemaTypes/portableText/portableTextType.tsx +52 -0
  180. package/templates/shopify/schemaTypes/singletons/homeType.ts +49 -0
  181. package/templates/shopify/schemaTypes/singletons/settingsType.ts +96 -0
  182. package/templates/shopify/static/.gitkeep +1 -0
  183. package/templates/shopify/structure/collectionStructure.ts +9 -0
  184. package/templates/shopify/structure/colorThemeStructure.ts +9 -0
  185. package/templates/shopify/structure/homeStructure.ts +9 -0
  186. package/templates/shopify/structure/index.ts +57 -0
  187. package/templates/shopify/structure/pageStructure.ts +11 -0
  188. package/templates/shopify/structure/productStructure.ts +51 -0
  189. package/templates/shopify/structure/settingStructure.ts +9 -0
  190. package/templates/shopify/utils/blocksToText.ts +20 -0
  191. package/templates/shopify/utils/defineStructure.ts +11 -0
  192. package/templates/shopify/utils/getPriceRange.ts +24 -0
  193. package/templates/shopify/utils/shopifyUrls.ts +22 -0
  194. package/templates/shopify/utils/validateSlug.ts +18 -0
  195. package/templates/shopify-online-storefront/README.md +54 -0
  196. package/templates/shopify-online-storefront/components/icons/Shopify.tsx +22 -0
  197. package/templates/shopify-online-storefront/components/inputs/CollectionHidden.tsx +23 -0
  198. package/templates/shopify-online-storefront/components/inputs/PlaceholderString.tsx +25 -0
  199. package/templates/shopify-online-storefront/components/inputs/ProductHidden.tsx +66 -0
  200. package/templates/shopify-online-storefront/components/inputs/ProductVariantHidden.tsx +25 -0
  201. package/templates/shopify-online-storefront/components/inputs/ProxyString.tsx +38 -0
  202. package/templates/shopify-online-storefront/components/media/ShopifyDocumentStatus.tsx +83 -0
  203. package/templates/shopify-online-storefront/constants.ts +18 -0
  204. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/index.ts +45 -0
  205. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyDelete.tsx +144 -0
  206. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/shopifyLink.ts +39 -0
  207. package/templates/shopify-online-storefront/plugins/shopifyDocumentActions/types.ts +14 -0
  208. package/templates/shopify-online-storefront/schemaTypes/blocks/blockContent.ts +32 -0
  209. package/templates/shopify-online-storefront/schemaTypes/documents/collection.tsx +83 -0
  210. package/templates/shopify-online-storefront/schemaTypes/documents/product.tsx +102 -0
  211. package/templates/shopify-online-storefront/schemaTypes/documents/productVariant.tsx +82 -0
  212. package/templates/shopify-online-storefront/schemaTypes/index.ts +43 -0
  213. package/templates/shopify-online-storefront/schemaTypes/objects/accordion.ts +31 -0
  214. package/templates/shopify-online-storefront/schemaTypes/objects/accordionGroup.ts +35 -0
  215. package/templates/shopify-online-storefront/schemaTypes/objects/callout.ts +40 -0
  216. package/templates/shopify-online-storefront/schemaTypes/objects/inventory.ts +30 -0
  217. package/templates/shopify-online-storefront/schemaTypes/objects/option.ts +30 -0
  218. package/templates/shopify-online-storefront/schemaTypes/objects/priceRange.ts +22 -0
  219. package/templates/shopify-online-storefront/schemaTypes/objects/proxyString.ts +11 -0
  220. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollection.ts +109 -0
  221. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyCollectionRule.tsx +45 -0
  222. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProduct.ts +165 -0
  223. package/templates/shopify-online-storefront/schemaTypes/objects/shopifyProductVariant.ts +151 -0
  224. package/templates/shopify-online-storefront/structure/collectionStructure.ts +9 -0
  225. package/templates/shopify-online-storefront/structure/index.ts +37 -0
  226. package/templates/shopify-online-storefront/structure/productStructure.ts +35 -0
  227. package/templates/shopify-online-storefront/utils/defineStructure.ts +11 -0
  228. package/templates/shopify-online-storefront/utils/getPriceRange.ts +24 -0
  229. package/templates/shopify-online-storefront/utils/shopifyUrls.ts +22 -0
  230. package/dist/actions/build/__tests__/buildApp.test.js +0 -367
  231. package/dist/actions/build/__tests__/buildApp.test.js.map +0 -1
  232. package/dist/actions/build/__tests__/buildStudio.test.js +0 -561
  233. package/dist/actions/build/__tests__/buildStudio.test.js.map +0 -1
  234. package/dist/actions/build/__tests__/checkRequiredDependencies.test.js +0 -233
  235. package/dist/actions/build/__tests__/checkRequiredDependencies.test.js.map +0 -1
  236. package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js +0 -414
  237. package/dist/actions/build/__tests__/checkStudioDependencyVersions.test.js.map +0 -1
  238. package/dist/actions/build/__tests__/determineBasePath.test.js +0 -24
  239. package/dist/actions/build/__tests__/determineBasePath.test.js.map +0 -1
  240. package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js +0 -109
  241. package/dist/actions/build/__tests__/getAutoUpdatesImportMap.test.js.map +0 -1
  242. package/dist/actions/build/__tests__/getViteConfig.test.js +0 -493
  243. package/dist/actions/build/__tests__/getViteConfig.test.js.map +0 -1
  244. package/dist/actions/build/__tests__/renderDocument.test.js +0 -278
  245. package/dist/actions/build/__tests__/renderDocument.test.js.map +0 -1
  246. package/dist/actions/build/__tests__/shouldAutoUpdate.test.js +0 -153
  247. package/dist/actions/build/__tests__/shouldAutoUpdate.test.js.map +0 -1
  248. package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js +0 -657
  249. package/dist/actions/build/renderDocumentWorker/__tests__/renderDocumentWorker.test.js.map +0 -1
  250. package/dist/actions/dataset/__tests__/validateDatasetName.test.js +0 -182
  251. package/dist/actions/dataset/__tests__/validateDatasetName.test.js.map +0 -1
  252. package/dist/actions/deploy/__tests__/checkDir.test.js +0 -120
  253. package/dist/actions/deploy/__tests__/checkDir.test.js.map +0 -1
  254. package/dist/actions/docs/__tests__/normalizeDocsPath.test.js +0 -16
  255. package/dist/actions/docs/__tests__/normalizeDocsPath.test.js.map +0 -1
  256. package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js +0 -124
  257. package/dist/actions/documents/validation/reporters/prettyReporter/__tests__/formatDocumentValidation.test.js.map +0 -1
  258. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js +0 -274
  259. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js.map +0 -1
  260. package/dist/actions/media/__tests__/importMedia.test.js +0 -182
  261. package/dist/actions/media/__tests__/importMedia.test.js.map +0 -1
  262. package/dist/actions/schema/__tests__/formatSchemaValidation.test.js +0 -174
  263. package/dist/actions/schema/__tests__/formatSchemaValidation.test.js.map +0 -1
  264. package/dist/actions/schema/__tests__/validateAction.test.js +0 -281
  265. package/dist/actions/schema/__tests__/validateAction.test.js.map +0 -1
  266. package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js +0 -27
  267. package/dist/actions/telemetry/__tests__/fetchTelemetryConsent.test.js.map +0 -1
  268. package/dist/actions/users/__tests__/validateEmail.test.js +0 -16
  269. package/dist/actions/users/__tests__/validateEmail.test.js.map +0 -1
  270. package/dist/commands/__tests__/blueprints.test.js +0 -54
  271. package/dist/commands/__tests__/blueprints.test.js.map +0 -1
  272. package/dist/commands/__tests__/build.test.js +0 -132
  273. package/dist/commands/__tests__/build.test.js.map +0 -1
  274. package/dist/commands/__tests__/codemod.test.js +0 -271
  275. package/dist/commands/__tests__/codemod.test.js.map +0 -1
  276. package/dist/commands/__tests__/debug.test.js +0 -590
  277. package/dist/commands/__tests__/debug.test.js.map +0 -1
  278. package/dist/commands/__tests__/deploy.test.js +0 -1945
  279. package/dist/commands/__tests__/deploy.test.js.map +0 -1
  280. package/dist/commands/__tests__/dev.test.js +0 -453
  281. package/dist/commands/__tests__/dev.test.js.map +0 -1
  282. package/dist/commands/__tests__/exec.test.js +0 -207
  283. package/dist/commands/__tests__/exec.test.js.map +0 -1
  284. package/dist/commands/__tests__/init/init.authentication.test.js +0 -73
  285. package/dist/commands/__tests__/init/init.authentication.test.js.map +0 -1
  286. package/dist/commands/__tests__/init/init.create-new-project.test.js +0 -195
  287. package/dist/commands/__tests__/init/init.create-new-project.test.js.map +0 -1
  288. package/dist/commands/__tests__/init/init.plan.test.js +0 -279
  289. package/dist/commands/__tests__/init/init.plan.test.js.map +0 -1
  290. package/dist/commands/__tests__/init/init.setup.test.js +0 -335
  291. package/dist/commands/__tests__/init/init.setup.test.js.map +0 -1
  292. package/dist/commands/__tests__/install.test.js +0 -282
  293. package/dist/commands/__tests__/install.test.js.map +0 -1
  294. package/dist/commands/__tests__/learn.test.js +0 -29
  295. package/dist/commands/__tests__/learn.test.js.map +0 -1
  296. package/dist/commands/__tests__/logout.test.js +0 -91
  297. package/dist/commands/__tests__/logout.test.js.map +0 -1
  298. package/dist/commands/__tests__/manage.test.js +0 -110
  299. package/dist/commands/__tests__/manage.test.js.map +0 -1
  300. package/dist/commands/__tests__/migration.test.js +0 -119
  301. package/dist/commands/__tests__/migration.test.js.map +0 -1
  302. package/dist/commands/__tests__/preview.test.js +0 -261
  303. package/dist/commands/__tests__/preview.test.js.map +0 -1
  304. package/dist/commands/__tests__/start.test.js +0 -253
  305. package/dist/commands/__tests__/start.test.js.map +0 -1
  306. package/dist/commands/__tests__/undeploy.test.js +0 -382
  307. package/dist/commands/__tests__/undeploy.test.js.map +0 -1
  308. package/dist/commands/__tests__/versions.test.js +0 -142
  309. package/dist/commands/__tests__/versions.test.js.map +0 -1
  310. package/dist/commands/backup/__tests__/disable.test.js +0 -204
  311. package/dist/commands/backup/__tests__/disable.test.js.map +0 -1
  312. package/dist/commands/backup/__tests__/download.test.js +0 -768
  313. package/dist/commands/backup/__tests__/download.test.js.map +0 -1
  314. package/dist/commands/backup/__tests__/enable.test.js +0 -286
  315. package/dist/commands/backup/__tests__/enable.test.js.map +0 -1
  316. package/dist/commands/backup/__tests__/list.test.js +0 -330
  317. package/dist/commands/backup/__tests__/list.test.js.map +0 -1
  318. package/dist/commands/cors/__tests__/add.test.js +0 -376
  319. package/dist/commands/cors/__tests__/add.test.js.map +0 -1
  320. package/dist/commands/cors/__tests__/delete.test.js +0 -308
  321. package/dist/commands/cors/__tests__/delete.test.js.map +0 -1
  322. package/dist/commands/cors/__tests__/list.test.js +0 -241
  323. package/dist/commands/cors/__tests__/list.test.js.map +0 -1
  324. package/dist/commands/dataset/__tests__/copy.test.js +0 -628
  325. package/dist/commands/dataset/__tests__/copy.test.js.map +0 -1
  326. package/dist/commands/dataset/__tests__/create.test.js +0 -342
  327. package/dist/commands/dataset/__tests__/create.test.js.map +0 -1
  328. package/dist/commands/dataset/__tests__/delete.test.js +0 -231
  329. package/dist/commands/dataset/__tests__/delete.test.js.map +0 -1
  330. package/dist/commands/dataset/__tests__/export.test.js +0 -601
  331. package/dist/commands/dataset/__tests__/export.test.js.map +0 -1
  332. package/dist/commands/dataset/__tests__/import.test.js +0 -53
  333. package/dist/commands/dataset/__tests__/import.test.js.map +0 -1
  334. package/dist/commands/dataset/__tests__/list.test.js +0 -216
  335. package/dist/commands/dataset/__tests__/list.test.js.map +0 -1
  336. package/dist/commands/dataset/alias/__tests__/create.test.js +0 -339
  337. package/dist/commands/dataset/alias/__tests__/create.test.js.map +0 -1
  338. package/dist/commands/dataset/alias/__tests__/delete.test.js +0 -247
  339. package/dist/commands/dataset/alias/__tests__/delete.test.js.map +0 -1
  340. package/dist/commands/dataset/alias/__tests__/link.test.js +0 -376
  341. package/dist/commands/dataset/alias/__tests__/link.test.js.map +0 -1
  342. package/dist/commands/dataset/alias/__tests__/unlink.test.js +0 -313
  343. package/dist/commands/dataset/alias/__tests__/unlink.test.js.map +0 -1
  344. package/dist/commands/dataset/visibility/__tests__/get.test.js +0 -128
  345. package/dist/commands/dataset/visibility/__tests__/get.test.js.map +0 -1
  346. package/dist/commands/dataset/visibility/__tests__/set.test.js +0 -198
  347. package/dist/commands/dataset/visibility/__tests__/set.test.js.map +0 -1
  348. package/dist/commands/docs/__tests__/browse.test.js +0 -29
  349. package/dist/commands/docs/__tests__/browse.test.js.map +0 -1
  350. package/dist/commands/docs/__tests__/read.test.js +0 -78
  351. package/dist/commands/docs/__tests__/read.test.js.map +0 -1
  352. package/dist/commands/docs/__tests__/search.test.js +0 -255
  353. package/dist/commands/docs/__tests__/search.test.js.map +0 -1
  354. package/dist/commands/documents/__tests__/create.test.js +0 -1030
  355. package/dist/commands/documents/__tests__/create.test.js.map +0 -1
  356. package/dist/commands/documents/__tests__/delete.test.js +0 -300
  357. package/dist/commands/documents/__tests__/delete.test.js.map +0 -1
  358. package/dist/commands/documents/__tests__/get.test.js +0 -182
  359. package/dist/commands/documents/__tests__/get.test.js.map +0 -1
  360. package/dist/commands/documents/__tests__/query.test.js +0 -300
  361. package/dist/commands/documents/__tests__/query.test.js.map +0 -1
  362. package/dist/commands/documents/__tests__/validate.test.js +0 -249
  363. package/dist/commands/documents/__tests__/validate.test.js.map +0 -1
  364. package/dist/commands/graphql/__tests__/list.test.js +0 -240
  365. package/dist/commands/graphql/__tests__/list.test.js.map +0 -1
  366. package/dist/commands/graphql/__tests__/undeploy.test.js +0 -410
  367. package/dist/commands/graphql/__tests__/undeploy.test.js.map +0 -1
  368. package/dist/commands/hook/__tests__/attempt.test.js +0 -275
  369. package/dist/commands/hook/__tests__/attempt.test.js.map +0 -1
  370. package/dist/commands/hook/__tests__/create.test.js +0 -119
  371. package/dist/commands/hook/__tests__/create.test.js.map +0 -1
  372. package/dist/commands/hook/__tests__/delete.test.js +0 -233
  373. package/dist/commands/hook/__tests__/delete.test.js.map +0 -1
  374. package/dist/commands/hook/__tests__/list.test.js +0 -145
  375. package/dist/commands/hook/__tests__/list.test.js.map +0 -1
  376. package/dist/commands/hook/__tests__/logs.test.js +0 -798
  377. package/dist/commands/hook/__tests__/logs.test.js.map +0 -1
  378. package/dist/commands/manifest/__tests__/extract.test.js +0 -132
  379. package/dist/commands/manifest/__tests__/extract.test.js.map +0 -1
  380. package/dist/commands/mcp/__tests__/configure.test.js +0 -397
  381. package/dist/commands/mcp/__tests__/configure.test.js.map +0 -1
  382. package/dist/commands/media/__tests__/create-aspect.test.js +0 -173
  383. package/dist/commands/media/__tests__/create-aspect.test.js.map +0 -1
  384. package/dist/commands/media/__tests__/delete-aspect.test.js +0 -342
  385. package/dist/commands/media/__tests__/delete-aspect.test.js.map +0 -1
  386. package/dist/commands/media/__tests__/deploy-aspect.test.js +0 -619
  387. package/dist/commands/media/__tests__/deploy-aspect.test.js.map +0 -1
  388. package/dist/commands/media/__tests__/export.test.js +0 -697
  389. package/dist/commands/media/__tests__/export.test.js.map +0 -1
  390. package/dist/commands/media/__tests__/import.test.js +0 -347
  391. package/dist/commands/media/__tests__/import.test.js.map +0 -1
  392. package/dist/commands/openapi/__tests__/get.test.js +0 -149
  393. package/dist/commands/openapi/__tests__/get.test.js.map +0 -1
  394. package/dist/commands/openapi/__tests__/list.test.js +0 -113
  395. package/dist/commands/openapi/__tests__/list.test.js.map +0 -1
  396. package/dist/commands/projects/__tests__/list.test.js +0 -154
  397. package/dist/commands/projects/__tests__/list.test.js.map +0 -1
  398. package/dist/commands/schema/__tests__/delete.test.js +0 -454
  399. package/dist/commands/schema/__tests__/delete.test.js.map +0 -1
  400. package/dist/commands/schema/__tests__/deploy.test.js +0 -348
  401. package/dist/commands/schema/__tests__/deploy.test.js.map +0 -1
  402. package/dist/commands/schema/__tests__/extract.test.js +0 -121
  403. package/dist/commands/schema/__tests__/extract.test.js.map +0 -1
  404. package/dist/commands/schema/__tests__/list.test.js +0 -399
  405. package/dist/commands/schema/__tests__/list.test.js.map +0 -1
  406. package/dist/commands/schema/__tests__/validate.test.js +0 -121
  407. package/dist/commands/schema/__tests__/validate.test.js.map +0 -1
  408. package/dist/commands/telemetry/__tests__/disable.test.js +0 -147
  409. package/dist/commands/telemetry/__tests__/disable.test.js.map +0 -1
  410. package/dist/commands/telemetry/__tests__/enable.test.js +0 -133
  411. package/dist/commands/telemetry/__tests__/enable.test.js.map +0 -1
  412. package/dist/commands/telemetry/__tests__/status.test.js +0 -155
  413. package/dist/commands/telemetry/__tests__/status.test.js.map +0 -1
  414. package/dist/commands/tokens/__tests__/add.test.js +0 -435
  415. package/dist/commands/tokens/__tests__/add.test.js.map +0 -1
  416. package/dist/commands/tokens/__tests__/delete.test.js +0 -405
  417. package/dist/commands/tokens/__tests__/delete.test.js.map +0 -1
  418. package/dist/commands/tokens/__tests__/list.test.js +0 -395
  419. package/dist/commands/tokens/__tests__/list.test.js.map +0 -1
  420. package/dist/commands/users/__tests__/invite.test.js +0 -362
  421. package/dist/commands/users/__tests__/invite.test.js.map +0 -1
  422. package/dist/commands/users/__tests__/list.test.js +0 -407
  423. package/dist/commands/users/__tests__/list.test.js.map +0 -1
  424. package/dist/hooks/prerun/__tests__/setupTelemetry.test.js +0 -77
  425. package/dist/hooks/prerun/__tests__/setupTelemetry.test.js.map +0 -1
  426. package/dist/services/__tests__/datasetAliases.test.js +0 -131
  427. package/dist/services/__tests__/datasetAliases.test.js.map +0 -1
  428. package/dist/services/__tests__/datasets.test.js +0 -436
  429. package/dist/services/__tests__/datasets.test.js.map +0 -1
  430. package/dist/services/__tests__/graphql.test.js +0 -43
  431. package/dist/services/__tests__/graphql.test.js.map +0 -1
  432. package/dist/services/__tests__/mediaLibraries.test.js +0 -88
  433. package/dist/services/__tests__/mediaLibraries.test.js.map +0 -1
  434. package/dist/services/__tests__/projects.test.js +0 -41
  435. package/dist/services/__tests__/projects.test.js.map +0 -1
  436. package/dist/services/__tests__/userApplications.test.js +0 -113
  437. package/dist/services/__tests__/userApplications.test.js.map +0 -1
  438. package/dist/util/__tests__/appId.test.js +0 -31
  439. package/dist/util/__tests__/appId.test.js.map +0 -1
  440. package/dist/util/__tests__/cliClient.test.js +0 -184
  441. package/dist/util/__tests__/cliClient.test.js.map +0 -1
  442. package/dist/util/__tests__/compareDependencyVersions.test.js +0 -426
  443. package/dist/util/__tests__/compareDependencyVersions.test.js.map +0 -1
  444. package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js +0 -74
  445. package/dist/util/__tests__/extractDocumentsFromNdjsonOrTarball.test.js.map +0 -1
  446. package/dist/util/__tests__/findNdjsonEntry.test.js +0 -54
  447. package/dist/util/__tests__/findNdjsonEntry.test.js.map +0 -1
  448. package/dist/util/__tests__/getCliVersion.test.js +0 -28
  449. package/dist/util/__tests__/getCliVersion.test.js.map +0 -1
  450. package/dist/util/__tests__/getLocalPackageVersion.test.js +0 -84
  451. package/dist/util/__tests__/getLocalPackageVersion.test.js.map +0 -1
  452. package/dist/util/__tests__/getWorkspace.test.js +0 -37
  453. package/dist/util/__tests__/getWorkspace.test.js.map +0 -1
  454. package/dist/util/__tests__/readPackageJson.test.js +0 -69
  455. package/dist/util/__tests__/readPackageJson.test.js.map +0 -1
  456. package/dist/util/__tests__/warnAboutMissingAppId.test.js +0 -28
  457. package/dist/util/__tests__/warnAboutMissingAppId.test.js.map +0 -1
  458. package/dist/util/packageManager/__tests__/installPackages.test.js +0 -388
  459. package/dist/util/packageManager/__tests__/installPackages.test.js.map +0 -1
  460. package/dist/util/validation/ __tests__/validateDocuments.test.js +0 -274
  461. package/dist/util/validation/ __tests__/validateDocuments.test.js.map +0 -1
@@ -1,1945 +0,0 @@
1
- import { runCommand } from '@oclif/test';
2
- import { confirm, input, select } from '@sanity/cli-core/ux';
3
- import { mockApi, testCommand } from '@sanity/cli-test';
4
- import nock from 'nock';
5
- import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
6
- import { testExample } from '~test/helpers/testExample.js';
7
- import { buildApp } from '../../actions/build/buildApp.js';
8
- import { buildStudio } from '../../actions/build/buildStudio.js';
9
- import { checkDir } from '../../actions/deploy/checkDir.js';
10
- import { USER_APPLICATIONS_API_VERSION } from '../../services/userApplications.js';
11
- import { dirIsEmptyOrNonExistent } from '../../util/dirIsEmptyOrNonExistent.js';
12
- import { readModuleVersion } from '../../util/readModuleVersion.js';
13
- import { DeployCommand } from '../deploy.js';
14
- vi.mock('../../util/readModuleVersion.js', ()=>({
15
- readModuleVersion: vi.fn()
16
- }));
17
- vi.mock('../../actions/build/buildApp.js', ()=>({
18
- buildApp: vi.fn()
19
- }));
20
- vi.mock('../../actions/build/buildStudio.js', ()=>({
21
- buildStudio: vi.fn()
22
- }));
23
- vi.mock('../../actions/deploy/checkDir.js', ()=>({
24
- checkDir: vi.fn()
25
- }));
26
- vi.mock('@sanity/cli-core/ux', async ()=>{
27
- const actual = await vi.importActual('@sanity/cli-core/ux');
28
- return {
29
- ...actual,
30
- confirm: vi.fn(),
31
- input: vi.fn(),
32
- select: vi.fn()
33
- };
34
- });
35
- vi.mock('../../util/dirIsEmptyOrNonExistent.js', ()=>({
36
- dirIsEmptyOrNonExistent: vi.fn(()=>true)
37
- }));
38
- vi.mock('tar-fs', ()=>({
39
- pack: vi.fn(()=>{
40
- return {
41
- pipe: vi.fn()
42
- };
43
- })
44
- }));
45
- const mockSelect = vi.mocked(select);
46
- const mockConfirm = vi.mocked(confirm);
47
- const mockInput = vi.mocked(input);
48
- const mockCheckDir = vi.mocked(checkDir);
49
- const mockDirIsEmptyOrNonExistent = vi.mocked(dirIsEmptyOrNonExistent);
50
- const mockReadModuleVersion = vi.mocked(readModuleVersion);
51
- const mockBuildStudio = vi.mocked(buildStudio);
52
- const mockBuildApp = vi.mocked(buildApp);
53
- const appId = 'app-id';
54
- const organizationId = 'org-id';
55
- const defaultMocks = {
56
- cliConfig: {
57
- app: {
58
- organizationId
59
- },
60
- deployment: {
61
- appId
62
- }
63
- }
64
- };
65
- describe('#deploy', ()=>{
66
- beforeEach(async ()=>{
67
- // Set up default mocks
68
- mockReadModuleVersion.mockImplementation(async (sourceDir, moduleName)=>{
69
- if (moduleName === 'sanity') return '3.0.0' // for studio deployments
70
- ;
71
- if (moduleName === '@sanity/sdk-react') return '1.0.0' // for app deployments
72
- ;
73
- return '1.0.0';
74
- });
75
- mockCheckDir.mockResolvedValue();
76
- });
77
- afterEach(()=>{
78
- vi.clearAllMocks();
79
- const pending = nock.pendingMocks();
80
- nock.cleanAll();
81
- expect(pending, 'pending mocks').toEqual([]);
82
- });
83
- test('help text is correct', async ()=>{
84
- const { stdout } = await runCommand('deploy --help');
85
- expect(stdout).toMatchInlineSnapshot(`
86
- "Builds and deploys Sanity Studio or application to Sanity hosting
87
-
88
- USAGE
89
- $ sanity deploy [SOURCEDIR] [--auto-updates] [--build] [--minify]
90
- [--schema-required] [--source-maps] [--verbose] [-y]
91
-
92
- ARGUMENTS
93
- [SOURCEDIR] Source directory
94
-
95
- FLAGS
96
- -y, --yes Unattended mode, answers "yes" to any "yes/no" prompt
97
- and otherwise uses defaults
98
- --[no-]auto-updates Automatically update the studio to the latest version
99
- --[no-]build Don't build the studio prior to deploy, instead
100
- deploying the version currently in \`dist/\`
101
- --[no-]minify Skip minifying built JavaScript (speeds up build,
102
- increases size of bundle)
103
- --schema-required Fail-fast deployment if schema store fails
104
- --source-maps Enable source maps for built bundles (increases size
105
- of bundle)
106
- --verbose Enable verbose logging
107
-
108
- DESCRIPTION
109
- Builds and deploys Sanity Studio or application to Sanity hosting
110
-
111
- EXAMPLES
112
- Build the studio
113
-
114
- $ sanity deploy
115
-
116
- Deploys non-minified build with source maps
117
-
118
- $ sanity deploy --no-minify --source-maps
119
-
120
- Fail fast on schema store fails - for when other services rely on the stored
121
- schema
122
-
123
- $ sanity deploy --schema-required
124
-
125
- "
126
- `);
127
- });
128
- test('shows an error for invalid flags', async ()=>{
129
- const { error } = await testCommand(DeployCommand, [
130
- '--invalid'
131
- ]);
132
- expect(error?.message).toContain('Nonexistent flag: --invalid');
133
- });
134
- test("should prompt to confirm deleting source directory if it's not empty", async ()=>{
135
- const cwd = await testExample('basic-app');
136
- process.cwd = ()=>cwd;
137
- mockConfirm.mockResolvedValue(true);
138
- mockDirIsEmptyOrNonExistent.mockResolvedValue(false);
139
- mockApi({
140
- apiVersion: USER_APPLICATIONS_API_VERSION,
141
- query: {
142
- appType: 'coreApp'
143
- },
144
- uri: `/user-applications/${appId}`
145
- }).reply(200, {
146
- appHost: 'existing-host',
147
- createdAt: '2024-01-01T00:00:00Z',
148
- id: appId,
149
- organizationId: 'org-id',
150
- projectId: null,
151
- title: 'Existing App',
152
- type: 'coreApp',
153
- updatedAt: '2024-01-01T00:00:00Z',
154
- urlType: 'internal'
155
- });
156
- mockApi({
157
- apiVersion: USER_APPLICATIONS_API_VERSION,
158
- method: 'post',
159
- query: {
160
- appType: 'coreApp'
161
- },
162
- uri: `/user-applications/${appId}/deployments`
163
- }).reply(200, {
164
- id: 'deployment-id'
165
- });
166
- const { error } = await testCommand(DeployCommand, [
167
- 'build'
168
- ], {
169
- config: {
170
- root: cwd
171
- },
172
- mocks: defaultMocks
173
- });
174
- expect(error).toBeUndefined();
175
- expect(mockConfirm).toHaveBeenCalledWith({
176
- default: false,
177
- message: '"./build" is not empty, do you want to proceed?'
178
- });
179
- });
180
- test("should cancel the deployment if the user doesn't want to proceed", async ()=>{
181
- const cwd = await testExample('basic-app');
182
- process.cwd = ()=>cwd;
183
- mockConfirm.mockResolvedValue(false);
184
- const { error } = await testCommand(DeployCommand, [
185
- 'build'
186
- ], {
187
- config: {
188
- root: cwd
189
- },
190
- mocks: defaultMocks
191
- });
192
- expect(error?.message).toContain('Cancelled.');
193
- expect(error?.oclif?.exit).toBe(1);
194
- });
195
- describe('app', ()=>{
196
- test('should re-deploy app if it already exists', async ()=>{
197
- const cwd = await testExample('basic-app');
198
- process.cwd = ()=>cwd;
199
- mockApi({
200
- apiVersion: USER_APPLICATIONS_API_VERSION,
201
- query: {
202
- appType: 'coreApp'
203
- },
204
- uri: `/user-applications/${appId}`
205
- }).reply(200, {
206
- appHost: 'existing-host',
207
- createdAt: '2024-01-01T00:00:00Z',
208
- id: appId,
209
- organizationId: 'org-id',
210
- projectId: null,
211
- title: 'Existing App',
212
- type: 'coreApp',
213
- updatedAt: '2024-01-01T00:00:00Z',
214
- urlType: 'internal'
215
- });
216
- mockApi({
217
- apiVersion: USER_APPLICATIONS_API_VERSION,
218
- method: 'post',
219
- query: {
220
- appType: 'coreApp'
221
- },
222
- uri: `/user-applications/${appId}/deployments`
223
- }).reply(200, {
224
- id: 'deployment-id'
225
- });
226
- const { error, stderr, stdout } = await testCommand(DeployCommand, [], {
227
- config: {
228
- root: cwd
229
- },
230
- mocks: defaultMocks
231
- });
232
- expect(error).toBeUndefined();
233
- expect(stderr).toContain('Checking application info');
234
- expect(stderr).toContain('Verifying local content');
235
- expect(stderr).toContain('Deploying...');
236
- expect(stdout).toContain('Success! Application deployed');
237
- });
238
- test('should handle missing @sanity/sdk-react version', async ()=>{
239
- const cwd = await testExample('basic-app');
240
- process.cwd = ()=>cwd;
241
- mockReadModuleVersion.mockResolvedValue(null);
242
- const { error } = await testCommand(DeployCommand, [], {
243
- config: {
244
- root: cwd
245
- },
246
- mocks: defaultMocks
247
- });
248
- expect(error?.message).toContain('Failed to find installed @sanity/sdk-react version');
249
- });
250
- test('should create new user application if none exists', async ()=>{
251
- const cwd = await testExample('basic-app');
252
- process.cwd = ()=>cwd;
253
- const newAppId = 'new-app-id';
254
- const deploymentId = 'deployment-id';
255
- mockInput.mockResolvedValue('Test App');
256
- mockApi({
257
- apiVersion: USER_APPLICATIONS_API_VERSION,
258
- query: {
259
- appType: 'coreApp',
260
- organizationId
261
- },
262
- uri: `/user-applications`
263
- }).reply(200, []);
264
- mockApi({
265
- apiVersion: USER_APPLICATIONS_API_VERSION,
266
- method: 'post',
267
- query: {
268
- appType: 'coreApp',
269
- organizationId
270
- },
271
- uri: `/user-applications`
272
- }).reply(200, {
273
- appHost: 'generated-host',
274
- createdAt: '2024-01-01T00:00:00Z',
275
- id: newAppId,
276
- organizationId,
277
- projectId: null,
278
- title: 'Test App',
279
- type: 'coreApp',
280
- updatedAt: '2024-01-01T00:00:00Z',
281
- urlType: 'internal'
282
- });
283
- mockApi({
284
- apiVersion: USER_APPLICATIONS_API_VERSION,
285
- method: 'post',
286
- query: {
287
- appType: 'coreApp'
288
- },
289
- uri: `/user-applications/${newAppId}/deployments`
290
- }).reply(200, {
291
- id: deploymentId
292
- });
293
- const { error, stdout } = await testCommand(DeployCommand, [], {
294
- config: {
295
- root: cwd
296
- },
297
- mocks: {
298
- cliConfig: {
299
- app: {
300
- organizationId
301
- }
302
- }
303
- }
304
- });
305
- expect(error).toBeUndefined();
306
- expect(stdout).toContain('Success! Application deployed');
307
- expect(stdout).toContain(`Add the deployment.appId to your sanity.cli.js or sanity.cli.ts file:`);
308
- expect(stdout).toContain(`deployment: {
309
- appId: '${newAppId}',`);
310
- expect(mockInput).toHaveBeenCalledWith({
311
- message: 'Enter a title for your application:',
312
- validate: expect.any(Function)
313
- });
314
- });
315
- test('should skip build when --no-build flag is used', async ()=>{
316
- const cwd = await testExample('basic-app');
317
- process.cwd = ()=>cwd;
318
- const existingAppId = 'existing-app-id';
319
- const deploymentId = 'deployment-id';
320
- mockApi({
321
- apiVersion: USER_APPLICATIONS_API_VERSION,
322
- query: {
323
- appType: 'coreApp'
324
- },
325
- uri: `/user-applications/${existingAppId}`
326
- }).reply(200, {
327
- appHost: 'existing-host',
328
- createdAt: '2024-01-01T00:00:00Z',
329
- id: existingAppId,
330
- organizationId,
331
- projectId: null,
332
- title: 'Existing App',
333
- type: 'coreApp',
334
- updatedAt: '2024-01-01T00:00:00Z',
335
- urlType: 'internal'
336
- });
337
- mockApi({
338
- apiVersion: USER_APPLICATIONS_API_VERSION,
339
- method: 'post',
340
- query: {
341
- appType: 'coreApp'
342
- },
343
- uri: `/user-applications/${existingAppId}/deployments`
344
- }).reply(200, {
345
- id: deploymentId
346
- });
347
- const { error, stdout } = await testCommand(DeployCommand, [
348
- '--no-build'
349
- ], {
350
- config: {
351
- root: cwd
352
- },
353
- mocks: {
354
- cliConfig: {
355
- ...defaultMocks.cliConfig,
356
- deployment: {
357
- appId: existingAppId
358
- }
359
- }
360
- }
361
- });
362
- expect(error).toBeUndefined();
363
- expect(stdout).toContain('Success! Application deployed');
364
- expect(mockBuildApp).not.toHaveBeenCalled();
365
- });
366
- test('should handle directory check errors', async ()=>{
367
- const cwd = await testExample('basic-app');
368
- process.cwd = ()=>cwd;
369
- const existingAppId = 'existing-app-id';
370
- mockCheckDir.mockRejectedValue(new Error('Directory check failed'));
371
- mockApi({
372
- apiVersion: USER_APPLICATIONS_API_VERSION,
373
- query: {
374
- appType: 'coreApp'
375
- },
376
- uri: `/user-applications/${existingAppId}`
377
- }).reply(200, {
378
- appHost: 'existing-host',
379
- createdAt: '2024-01-01T00:00:00Z',
380
- id: existingAppId,
381
- organizationId,
382
- projectId: null,
383
- title: 'Existing App',
384
- type: 'coreApp',
385
- updatedAt: '2024-01-01T00:00:00Z',
386
- urlType: 'internal'
387
- });
388
- const { error } = await testCommand(DeployCommand, [
389
- '--no-build'
390
- ], {
391
- config: {
392
- root: cwd
393
- },
394
- mocks: {
395
- cliConfig: {
396
- ...defaultMocks.cliConfig,
397
- deployment: {
398
- appId: existingAppId
399
- }
400
- }
401
- }
402
- });
403
- expect(error?.message).toContain('Error checking directory');
404
- expect(error?.oclif?.exit).toBe(1);
405
- });
406
- test("should error when fetching user applications if user doesn't have org access", async ()=>{
407
- const cwd = await testExample('basic-app');
408
- process.cwd = ()=>cwd;
409
- const anotherAppId = 'some-app-id';
410
- const anotherOrganizationId = 'org-without-access';
411
- // Simulate API returning 403 Forbidden for the given org
412
- mockApi({
413
- apiVersion: USER_APPLICATIONS_API_VERSION,
414
- query: {
415
- appType: 'coreApp'
416
- },
417
- uri: `/user-applications/${anotherAppId}`
418
- }).reply(403, {
419
- error: 'Forbidden'
420
- });
421
- const { error } = await testCommand(DeployCommand, [
422
- '--no-build'
423
- ], {
424
- config: {
425
- root: cwd
426
- },
427
- mocks: {
428
- cliConfig: {
429
- app: {
430
- organizationId: anotherOrganizationId
431
- },
432
- deployment: {
433
- appId: anotherAppId
434
- }
435
- }
436
- }
437
- });
438
- expect(error?.message).toContain(`You don’t have permission to view applications for the configured organization ID ("${anotherOrganizationId}")`);
439
- expect(error?.oclif?.exit).toBe(1);
440
- });
441
- test('should handle user-applications endpoint errors', async ()=>{
442
- const cwd = await testExample('basic-app');
443
- process.cwd = ()=>cwd;
444
- const existingAppId = 'existing-app-id';
445
- mockApi({
446
- apiVersion: USER_APPLICATIONS_API_VERSION,
447
- query: {
448
- appType: 'coreApp'
449
- },
450
- uri: `/user-applications/${existingAppId}`
451
- }).reply(500, {
452
- error: 'Internal server error'
453
- });
454
- const { error } = await testCommand(DeployCommand, [
455
- '--no-build'
456
- ], {
457
- config: {
458
- root: cwd
459
- },
460
- mocks: {
461
- cliConfig: {
462
- ...defaultMocks.cliConfig,
463
- deployment: {
464
- appId: existingAppId
465
- }
466
- }
467
- }
468
- });
469
- expect(error?.message).toContain('Error deploying application');
470
- expect(error?.oclif?.exit).toBe(1);
471
- });
472
- test('should handle deployment API errors', async ()=>{
473
- const cwd = await testExample('basic-app');
474
- process.cwd = ()=>cwd;
475
- const existingAppId = 'existing-app-id';
476
- mockApi({
477
- apiVersion: USER_APPLICATIONS_API_VERSION,
478
- query: {
479
- appType: 'coreApp'
480
- },
481
- uri: `/user-applications/${existingAppId}`
482
- }).reply(200, {
483
- appHost: 'existing-host',
484
- createdAt: '2024-01-01T00:00:00Z',
485
- id: existingAppId,
486
- organizationId,
487
- projectId: null,
488
- title: 'Existing App',
489
- type: 'coreApp',
490
- updatedAt: '2024-01-01T00:00:00Z',
491
- urlType: 'internal'
492
- });
493
- mockApi({
494
- apiVersion: USER_APPLICATIONS_API_VERSION,
495
- method: 'post',
496
- query: {
497
- appType: 'coreApp'
498
- },
499
- uri: `/user-applications/${existingAppId}/deployments`
500
- }).reply(500, {
501
- error: 'Internal server error'
502
- });
503
- const { error } = await testCommand(DeployCommand, [
504
- '--no-build'
505
- ], {
506
- config: {
507
- root: cwd
508
- },
509
- mocks: {
510
- cliConfig: {
511
- ...defaultMocks.cliConfig,
512
- deployment: {
513
- appId: existingAppId
514
- }
515
- }
516
- }
517
- });
518
- expect(error?.message).toContain('Error deploying application');
519
- expect(error?.oclif?.exit).toBe(1);
520
- });
521
- test('should show an error if deployment.appId is configured but the application does not exist', async ()=>{
522
- const cwd = await testExample('basic-app');
523
- process.cwd = ()=>cwd;
524
- const nonExistentAppId = 'non-existent-app-id';
525
- // Simulate API returning no user application for the given app.id
526
- mockApi({
527
- apiVersion: USER_APPLICATIONS_API_VERSION,
528
- query: {
529
- appType: 'coreApp'
530
- },
531
- uri: `/user-applications/${nonExistentAppId}`
532
- }).reply(404, {
533
- error: 'Not found'
534
- });
535
- const { error } = await testCommand(DeployCommand, [
536
- '--no-build'
537
- ], {
538
- config: {
539
- root: cwd
540
- },
541
- mocks: {
542
- cliConfig: {
543
- ...defaultMocks.cliConfig,
544
- deployment: {
545
- appId: nonExistentAppId
546
- }
547
- }
548
- }
549
- });
550
- expect(error?.message).toContain('The `appId` provided in your configuration’s `deployment` object cannot be found in your organization');
551
- expect(error?.oclif?.exit).toBe(1);
552
- });
553
- test('should show an error if deployment.appId and app.id (deprecated) are both in use', async ()=>{
554
- const cwd = await testExample('basic-app');
555
- process.cwd = ()=>cwd;
556
- const { error } = await testCommand(DeployCommand, [
557
- '--no-build'
558
- ], {
559
- config: {
560
- root: cwd
561
- },
562
- mocks: {
563
- cliConfig: {
564
- ...defaultMocks.cliConfig,
565
- app: {
566
- id: appId,
567
- organizationId
568
- }
569
- }
570
- }
571
- });
572
- expect(error?.message).toContain('Found both app.id (deprecated) and deployment.appId in your application configuration.\n\nPlease remove app.id from your sanity.cli.js or sanity.cli.ts file.');
573
- expect(error?.oclif?.exit).toBe(1);
574
- });
575
- test('should show a warning if app.id (deprecated) is used', async ()=>{
576
- const cwd = await testExample('basic-app');
577
- process.cwd = ()=>cwd;
578
- const { stderr } = await testCommand(DeployCommand, [
579
- '--no-build'
580
- ], {
581
- config: {
582
- root: cwd
583
- },
584
- mocks: {
585
- cliConfig: {
586
- app: {
587
- id: appId,
588
- organizationId
589
- }
590
- }
591
- }
592
- });
593
- expect(stderr).toContain('The `app.id` config has moved to `deployment.appId`.');
594
- });
595
- test('should handle app creation with retry when host is taken', async ()=>{
596
- const cwd = await testExample('basic-app');
597
- process.cwd = ()=>cwd;
598
- const newAppId = 'new-app-id';
599
- const deploymentId = 'deployment-id';
600
- mockInput.mockResolvedValue('Test App');
601
- mockApi({
602
- apiVersion: USER_APPLICATIONS_API_VERSION,
603
- query: {
604
- appType: 'coreApp',
605
- organizationId
606
- },
607
- uri: `/user-applications`
608
- }).reply(200, []);
609
- mockApi({
610
- apiVersion: USER_APPLICATIONS_API_VERSION,
611
- method: 'post',
612
- query: {
613
- appType: 'coreApp',
614
- organizationId
615
- },
616
- uri: `/user-applications`
617
- }).once().reply(409, {
618
- message: 'App host already taken',
619
- statusCode: 409
620
- });
621
- mockApi({
622
- apiVersion: USER_APPLICATIONS_API_VERSION,
623
- method: 'post',
624
- query: {
625
- appType: 'coreApp',
626
- organizationId
627
- },
628
- uri: `/user-applications`
629
- }).once().reply(200, {
630
- appHost: 'generated-host-2',
631
- createdAt: '2024-01-01T00:00:00Z',
632
- id: newAppId,
633
- organizationId,
634
- projectId: null,
635
- title: 'Test App',
636
- type: 'coreApp',
637
- updatedAt: '2024-01-01T00:00:00Z',
638
- urlType: 'internal'
639
- });
640
- mockApi({
641
- apiVersion: USER_APPLICATIONS_API_VERSION,
642
- method: 'post',
643
- query: {
644
- appType: 'coreApp'
645
- },
646
- uri: `/user-applications/${newAppId}/deployments`
647
- }).reply(200, {
648
- id: deploymentId
649
- });
650
- const { error, stdout } = await testCommand(DeployCommand, [], {
651
- config: {
652
- root: cwd
653
- },
654
- mocks: {
655
- cliConfig: {
656
- app: {
657
- organizationId
658
- }
659
- }
660
- }
661
- });
662
- expect(error).toBeUndefined();
663
- expect(stdout).toContain('Success! Application deployed');
664
- });
665
- test('should handle app creation failure with non-retryable error', async ()=>{
666
- const cwd = await testExample('basic-app');
667
- process.cwd = ()=>cwd;
668
- mockInput.mockResolvedValue('Test App');
669
- mockApi({
670
- apiVersion: USER_APPLICATIONS_API_VERSION,
671
- query: {
672
- appType: 'coreApp',
673
- organizationId
674
- },
675
- uri: `/user-applications`
676
- }).reply(200, []);
677
- mockApi({
678
- apiVersion: USER_APPLICATIONS_API_VERSION,
679
- method: 'post',
680
- query: {
681
- appType: 'coreApp',
682
- organizationId
683
- },
684
- uri: `/user-applications`
685
- }).reply(500, {
686
- message: 'Internal server error',
687
- statusCode: 500
688
- });
689
- const { error } = await testCommand(DeployCommand, [], {
690
- config: {
691
- root: cwd
692
- },
693
- mocks: {
694
- cliConfig: {
695
- app: {
696
- organizationId
697
- }
698
- }
699
- }
700
- });
701
- expect(error?.message).toContain('Error deploying application');
702
- });
703
- test('should handle findUserApplicationForApp API errors', async ()=>{
704
- const cwd = await testExample('basic-app');
705
- process.cwd = ()=>cwd;
706
- const existingAppId = 'existing-app-id';
707
- mockApi({
708
- apiVersion: USER_APPLICATIONS_API_VERSION,
709
- query: {
710
- appType: 'coreApp'
711
- },
712
- uri: `/user-applications/${existingAppId}`
713
- }).reply(500, {
714
- error: 'Internal server error'
715
- });
716
- const { error } = await testCommand(DeployCommand, [
717
- '--no-build'
718
- ], {
719
- config: {
720
- root: cwd
721
- },
722
- mocks: {
723
- cliConfig: {
724
- ...defaultMocks.cliConfig,
725
- deployment: {
726
- appId: existingAppId
727
- }
728
- }
729
- }
730
- });
731
- expect(error?.message).toContain('Error deploying application');
732
- expect(error?.oclif?.exit).toBe(1);
733
- });
734
- test('should test input validation for app title', async ()=>{
735
- const cwd = await testExample('basic-app');
736
- process.cwd = ()=>cwd;
737
- const newAppId = 'new-app-id';
738
- const deploymentId = 'deployment-id';
739
- mockInput.mockResolvedValue('Valid App Title');
740
- mockApi({
741
- apiVersion: USER_APPLICATIONS_API_VERSION,
742
- query: {
743
- appType: 'coreApp',
744
- organizationId
745
- },
746
- uri: `/user-applications`
747
- }).reply(200, []);
748
- mockApi({
749
- apiVersion: USER_APPLICATIONS_API_VERSION,
750
- method: 'post',
751
- query: {
752
- appType: 'coreApp',
753
- organizationId
754
- },
755
- uri: `/user-applications`
756
- }).reply(200, {
757
- appHost: 'generated-host',
758
- createdAt: '2024-01-01T00:00:00Z',
759
- id: newAppId,
760
- organizationId,
761
- projectId: null,
762
- title: 'Valid App Title',
763
- type: 'coreApp',
764
- updatedAt: '2024-01-01T00:00:00Z',
765
- urlType: 'internal'
766
- });
767
- mockApi({
768
- apiVersion: USER_APPLICATIONS_API_VERSION,
769
- method: 'post',
770
- query: {
771
- appType: 'coreApp'
772
- },
773
- uri: `/user-applications/${newAppId}/deployments`
774
- }).reply(200, {
775
- id: deploymentId
776
- });
777
- const { error } = await testCommand(DeployCommand, [], {
778
- config: {
779
- root: cwd
780
- },
781
- mocks: {
782
- cliConfig: {
783
- app: {
784
- organizationId
785
- }
786
- }
787
- }
788
- });
789
- expect(error).toBeUndefined();
790
- expect(mockInput).toHaveBeenCalledWith({
791
- message: 'Enter a title for your application:',
792
- validate: expect.any(Function)
793
- });
794
- });
795
- test('should allow selecting from list of apps', async ()=>{
796
- const cwd = await testExample('basic-app');
797
- process.cwd = ()=>cwd;
798
- const existingAppId1 = 'existing-app-id-1';
799
- const existingAppId2 = 'existing-app-id-2';
800
- const deploymentId = 'deployment-id';
801
- mockApi({
802
- apiVersion: USER_APPLICATIONS_API_VERSION,
803
- query: {
804
- appType: 'coreApp',
805
- organizationId
806
- },
807
- uri: `/user-applications`
808
- }).reply(200, [
809
- {
810
- appHost: 'existing-host-1',
811
- createdAt: '2024-01-01T00:00:00Z',
812
- id: existingAppId1,
813
- organizationId,
814
- projectId: null,
815
- title: 'Existing App 1',
816
- type: 'coreApp',
817
- updatedAt: '2024-01-01T00:00:00Z',
818
- urlType: 'internal'
819
- },
820
- {
821
- appHost: 'existing-host-2',
822
- createdAt: '2024-01-01T00:00:00Z',
823
- id: existingAppId2,
824
- organizationId,
825
- projectId: null,
826
- title: 'Existing App 2',
827
- type: 'coreApp',
828
- updatedAt: '2024-01-01T00:00:00Z',
829
- urlType: 'internal'
830
- }
831
- ]);
832
- mockApi({
833
- apiVersion: USER_APPLICATIONS_API_VERSION,
834
- method: 'post',
835
- query: {
836
- appType: 'coreApp'
837
- },
838
- uri: `/user-applications/${existingAppId2}/deployments`
839
- }).reply(200, {
840
- id: deploymentId
841
- });
842
- mockSelect.mockResolvedValue('existing-host-2');
843
- const { error, stdout } = await testCommand(DeployCommand, [], {
844
- config: {
845
- root: cwd
846
- },
847
- mocks: {
848
- cliConfig: {
849
- app: {
850
- organizationId
851
- }
852
- }
853
- }
854
- });
855
- expect(error).toBeUndefined();
856
- expect(stdout).toContain('Success! Application deployed');
857
- expect(stdout).toContain(`Add the deployment.appId to your sanity.cli.js or sanity.cli.ts file:`);
858
- expect(stdout).toContain(`deployment: {
859
- appId: '${existingAppId2}',`);
860
- });
861
- test('should allow creating a new app by selecting from list of apps', async ()=>{
862
- const cwd = await testExample('basic-app');
863
- process.cwd = ()=>cwd;
864
- const existingAppId1 = 'existing-app-id-1';
865
- const existingAppId2 = 'existing-app-id-2';
866
- const newAppId = 'new-app-id';
867
- const deploymentId = 'deployment-id';
868
- mockApi({
869
- apiVersion: USER_APPLICATIONS_API_VERSION,
870
- query: {
871
- appType: 'coreApp',
872
- organizationId
873
- },
874
- uri: `/user-applications`
875
- }).reply(200, [
876
- {
877
- appHost: 'existing-host-1',
878
- createdAt: '2024-01-01T00:00:00Z',
879
- id: existingAppId1,
880
- organizationId,
881
- projectId: null,
882
- title: 'Existing App 1',
883
- type: 'coreApp',
884
- updatedAt: '2024-01-01T00:00:00Z',
885
- urlType: 'internal'
886
- },
887
- {
888
- appHost: 'existing-host-2',
889
- createdAt: '2024-01-01T00:00:00Z',
890
- id: existingAppId2,
891
- organizationId,
892
- projectId: null,
893
- title: 'Existing App 2',
894
- type: 'coreApp',
895
- updatedAt: '2024-01-01T00:00:00Z',
896
- urlType: 'internal'
897
- }
898
- ]);
899
- mockApi({
900
- apiVersion: USER_APPLICATIONS_API_VERSION,
901
- method: 'post',
902
- query: {
903
- appType: 'coreApp',
904
- organizationId
905
- },
906
- uri: `/user-applications`
907
- }).reply(200, {
908
- appHost: 'generated-host',
909
- createdAt: '2024-01-01T00:00:00Z',
910
- id: newAppId,
911
- organizationId,
912
- projectId: null,
913
- title: 'Test App',
914
- type: 'coreApp',
915
- updatedAt: '2024-01-01T00:00:00Z',
916
- urlType: 'internal'
917
- });
918
- mockApi({
919
- apiVersion: USER_APPLICATIONS_API_VERSION,
920
- method: 'post',
921
- query: {
922
- appType: 'coreApp'
923
- },
924
- uri: `/user-applications/${newAppId}/deployments`
925
- }).reply(200, {
926
- id: deploymentId
927
- });
928
- mockSelect.mockResolvedValue('NEW_APP');
929
- const { error, stdout } = await testCommand(DeployCommand, [], {
930
- config: {
931
- root: cwd
932
- },
933
- mocks: {
934
- cliConfig: {
935
- app: {
936
- organizationId
937
- }
938
- }
939
- }
940
- });
941
- expect(error).toBeUndefined();
942
- expect(stdout).toContain('Success! Application deployed');
943
- expect(stdout).toContain(`Add the deployment.appId to your sanity.cli.js or sanity.cli.ts file:`);
944
- expect(stdout).toContain(`deployment: {
945
- appId: '${newAppId}',`);
946
- });
947
- test('should throw an error if organizationId is not set', async ()=>{
948
- const cwd = await testExample('basic-app');
949
- process.cwd = ()=>cwd;
950
- const { error } = await testCommand(DeployCommand, [], {
951
- config: {
952
- root: cwd
953
- },
954
- mocks: {
955
- cliConfig: {
956
- app: {
957
- organizationId: undefined
958
- }
959
- }
960
- }
961
- });
962
- expect(error?.message).toContain('sanity.cli.ts does not contain an organization identifier ("app.organizationId"), which is required for the Sanity CLI to communicate with the Sanity API');
963
- expect(error?.oclif?.exit).toBe(1);
964
- });
965
- });
966
- describe('studio', ()=>{
967
- test('should handle missing sanity version', async ()=>{
968
- const cwd = await testExample('basic-studio');
969
- process.cwd = ()=>cwd;
970
- mockReadModuleVersion.mockResolvedValue(null);
971
- const { error } = await testCommand(DeployCommand, [], {
972
- config: {
973
- root: cwd
974
- },
975
- mocks: {
976
- cliConfig: {
977
- studioHost: 'existing-studio'
978
- }
979
- }
980
- });
981
- expect(error?.message).toContain('Failed to find installed sanity version');
982
- });
983
- test('should handle directory check errors', async ()=>{
984
- const cwd = await testExample('basic-app');
985
- process.cwd = ()=>cwd;
986
- const projectId = 'test-project-id';
987
- const studioHost = 'existing-studio';
988
- const studioAppId = 'studio-app-id';
989
- mockCheckDir.mockRejectedValue(new Error('Directory check failed'));
990
- mockApi({
991
- apiVersion: USER_APPLICATIONS_API_VERSION,
992
- query: {
993
- appHost: studioHost,
994
- appType: 'studio'
995
- },
996
- uri: `/projects/${projectId}/user-applications`
997
- }).reply(200, {
998
- appHost: studioHost,
999
- createdAt: '2024-01-01T00:00:00Z',
1000
- id: studioAppId,
1001
- projectId,
1002
- title: 'Existing Studio',
1003
- type: 'studio',
1004
- updatedAt: '2024-01-01T00:00:00Z',
1005
- urlType: 'internal'
1006
- });
1007
- const { error } = await testCommand(DeployCommand, [
1008
- '--no-build'
1009
- ], {
1010
- config: {
1011
- root: cwd
1012
- },
1013
- mocks: {
1014
- cliConfig: {
1015
- api: {
1016
- projectId
1017
- },
1018
- studioHost
1019
- }
1020
- }
1021
- });
1022
- expect(error?.message).toContain('Error checking directory');
1023
- });
1024
- test('should re-deploy studio if it already exists', async ()=>{
1025
- const cwd = await testExample('basic-studio');
1026
- process.cwd = ()=>cwd;
1027
- const projectId = 'test-project-id';
1028
- const studioHost = 'existing-studio';
1029
- const studioAppId = 'studio-app-id';
1030
- const deploymentId = 'deployment-id';
1031
- mockApi({
1032
- apiVersion: USER_APPLICATIONS_API_VERSION,
1033
- query: {
1034
- appHost: studioHost,
1035
- appType: 'studio'
1036
- },
1037
- uri: `/projects/${projectId}/user-applications`
1038
- }).reply(200, {
1039
- appHost: studioHost,
1040
- createdAt: '2024-01-01T00:00:00Z',
1041
- id: studioAppId,
1042
- projectId,
1043
- title: 'Existing Studio',
1044
- type: 'studio',
1045
- updatedAt: '2024-01-01T00:00:00Z',
1046
- urlType: 'internal'
1047
- });
1048
- mockApi({
1049
- apiVersion: USER_APPLICATIONS_API_VERSION,
1050
- method: 'post',
1051
- query: {
1052
- appType: 'studio'
1053
- },
1054
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1055
- }).reply(200, {
1056
- id: deploymentId
1057
- });
1058
- const { error, stderr, stdout } = await testCommand(DeployCommand, [], {
1059
- config: {
1060
- root: cwd
1061
- },
1062
- mocks: {
1063
- cliConfig: {
1064
- api: {
1065
- projectId
1066
- },
1067
- studioHost
1068
- }
1069
- }
1070
- });
1071
- expect(error).toBeUndefined();
1072
- expect(stderr).toContain('Checking project info');
1073
- expect(stderr).toContain('Verifying local content');
1074
- expect(stderr).toContain('Deploying to sanity.studio');
1075
- expect(stdout).toContain('Success! Studio deployed');
1076
- });
1077
- test('should create new studio hostname when studioHost is provided but does not exist', async ()=>{
1078
- const cwd = await testExample('basic-studio');
1079
- process.cwd = ()=>cwd;
1080
- mockApi({
1081
- apiVersion: USER_APPLICATIONS_API_VERSION,
1082
- query: {
1083
- appHost: 'new-studio-host',
1084
- appType: 'studio'
1085
- },
1086
- uri: `/projects/test-project-id/user-applications`
1087
- }).reply(404, {
1088
- message: 'Not found'
1089
- });
1090
- mockApi({
1091
- apiVersion: USER_APPLICATIONS_API_VERSION,
1092
- method: 'post',
1093
- query: {
1094
- appType: 'studio'
1095
- },
1096
- uri: `/projects/test-project-id/user-applications`
1097
- }).reply(200, {
1098
- appHost: 'new-studio-host',
1099
- createdAt: '2024-01-01T00:00:00Z',
1100
- id: 'new-studio-app-id',
1101
- projectId: 'test-project-id',
1102
- title: 'New Studio',
1103
- type: 'studio',
1104
- updatedAt: '2024-01-01T00:00:00Z',
1105
- urlType: 'internal'
1106
- });
1107
- mockApi({
1108
- apiVersion: USER_APPLICATIONS_API_VERSION,
1109
- method: 'post',
1110
- query: {
1111
- appType: 'studio'
1112
- },
1113
- uri: `/projects/test-project-id/user-applications/new-studio-app-id/deployments`
1114
- }).reply(200, {
1115
- id: 'deployment-id'
1116
- });
1117
- const { error, stdout } = await testCommand(DeployCommand, [], {
1118
- config: {
1119
- root: cwd
1120
- },
1121
- mocks: {
1122
- cliConfig: {
1123
- api: {
1124
- projectId: 'test-project-id'
1125
- },
1126
- studioHost: 'new-studio-host'
1127
- }
1128
- }
1129
- });
1130
- expect(error).toBeUndefined();
1131
- expect(stdout).toContain('Success! Studio deployed');
1132
- expect(stdout).toContain('Your project has not been assigned a studio hostname');
1133
- expect(stdout).toContain('Creating https://new-studio-host.sanity.studio');
1134
- });
1135
- test('should handle studio hostname creation failure when name is taken', async ()=>{
1136
- const cwd = await testExample('basic-studio');
1137
- process.cwd = ()=>cwd;
1138
- const projectId = 'test-project-id';
1139
- const studioHost = 'taken-studio-host';
1140
- mockApi({
1141
- apiVersion: USER_APPLICATIONS_API_VERSION,
1142
- query: {
1143
- appHost: studioHost,
1144
- appType: 'studio'
1145
- },
1146
- uri: `/projects/${projectId}/user-applications`
1147
- }).reply(404, {
1148
- message: 'Not found'
1149
- });
1150
- mockApi({
1151
- apiVersion: USER_APPLICATIONS_API_VERSION,
1152
- method: 'post',
1153
- query: {
1154
- appType: 'studio'
1155
- },
1156
- uri: `/projects/${projectId}/user-applications`
1157
- }).reply(409, {
1158
- message: 'Studio hostname already taken',
1159
- statusCode: 409
1160
- });
1161
- const { error } = await testCommand(DeployCommand, [], {
1162
- config: {
1163
- root: cwd
1164
- },
1165
- mocks: {
1166
- cliConfig: {
1167
- api: {
1168
- projectId
1169
- },
1170
- studioHost
1171
- }
1172
- }
1173
- });
1174
- expect(error?.message).toContain('Studio hostname already taken');
1175
- expect(error?.oclif?.exit).toBe(1);
1176
- });
1177
- test('should allow selecting from existing studio hostnames', async ()=>{
1178
- const cwd = await testExample('basic-studio');
1179
- process.cwd = ()=>cwd;
1180
- const projectId = 'test-project-id';
1181
- const studioOneId = 'studio-one-id';
1182
- const studioTwoId = 'studio-two-id';
1183
- const deploymentId = 'deployment-id';
1184
- mockApi({
1185
- apiVersion: USER_APPLICATIONS_API_VERSION,
1186
- query: {
1187
- appType: 'studio'
1188
- },
1189
- uri: `/projects/${projectId}/user-applications`
1190
- }).reply(200, [
1191
- {
1192
- appHost: 'studio-one',
1193
- createdAt: '2024-01-01T00:00:00Z',
1194
- id: studioOneId,
1195
- projectId,
1196
- title: 'Studio One',
1197
- type: 'studio',
1198
- updatedAt: '2024-01-01T00:00:00Z',
1199
- urlType: 'internal'
1200
- },
1201
- {
1202
- appHost: 'studio-two',
1203
- createdAt: '2024-01-01T00:00:00Z',
1204
- id: studioTwoId,
1205
- projectId,
1206
- title: 'Studio Two',
1207
- type: 'studio',
1208
- updatedAt: '2024-01-01T00:00:00Z',
1209
- urlType: 'internal'
1210
- }
1211
- ]);
1212
- mockApi({
1213
- apiVersion: USER_APPLICATIONS_API_VERSION,
1214
- method: 'post',
1215
- query: {
1216
- appType: 'studio'
1217
- },
1218
- uri: `/projects/${projectId}/user-applications/${studioTwoId}/deployments`
1219
- }).reply(200, {
1220
- id: deploymentId,
1221
- location: 'https://studio-two.sanity.studio'
1222
- });
1223
- mockSelect.mockResolvedValue('studio-two');
1224
- const { error, stdout } = await testCommand(DeployCommand, [], {
1225
- config: {
1226
- root: cwd
1227
- },
1228
- mocks: {
1229
- cliConfig: {
1230
- api: {
1231
- projectId
1232
- }
1233
- }
1234
- }
1235
- });
1236
- expect(error).toBeUndefined();
1237
- expect(stdout).toContain('Success! Studio deployed to https://studio-two.sanity.studio');
1238
- expect(mockSelect).toHaveBeenCalledWith({
1239
- choices: [
1240
- {
1241
- name: 'Create new studio hostname',
1242
- value: 'NEW_STUDIO'
1243
- },
1244
- expect.any(Object),
1245
- {
1246
- name: 'Studio One',
1247
- value: 'studio-one'
1248
- },
1249
- {
1250
- name: 'Studio Two',
1251
- value: 'studio-two'
1252
- }
1253
- ],
1254
- message: 'Select existing studio hostname, or create a new one'
1255
- });
1256
- });
1257
- test('should allow creating new studio hostname from selection menu', async ()=>{
1258
- const cwd = await testExample('basic-studio');
1259
- process.cwd = ()=>cwd;
1260
- const projectId = 'test-project-id';
1261
- const existingStudioId = 'existing-studio-id';
1262
- const newStudioFromMenuId = 'new-studio-from-menu-id';
1263
- const deploymentId = 'deployment-id';
1264
- mockApi({
1265
- apiVersion: USER_APPLICATIONS_API_VERSION,
1266
- query: {
1267
- appType: 'studio'
1268
- },
1269
- uri: `/projects/${projectId}/user-applications`
1270
- }).once().reply(200, [
1271
- {
1272
- appHost: 'existing-studio',
1273
- createdAt: '2024-01-01T00:00:00Z',
1274
- id: existingStudioId,
1275
- projectId,
1276
- title: 'Existing Studio',
1277
- type: 'studio',
1278
- updatedAt: '2024-01-01T00:00:00Z',
1279
- urlType: 'internal'
1280
- }
1281
- ]);
1282
- mockApi({
1283
- apiVersion: USER_APPLICATIONS_API_VERSION,
1284
- method: 'post',
1285
- query: {
1286
- appType: 'studio'
1287
- },
1288
- uri: `/projects/${projectId}/user-applications`
1289
- }).reply(200, {
1290
- appHost: 'new-studio-from-menu',
1291
- createdAt: '2024-01-01T00:00:00Z',
1292
- id: newStudioFromMenuId,
1293
- projectId,
1294
- title: 'New Studio From Menu',
1295
- type: 'studio',
1296
- updatedAt: '2024-01-01T00:00:00Z',
1297
- urlType: 'internal'
1298
- });
1299
- mockApi({
1300
- apiVersion: USER_APPLICATIONS_API_VERSION,
1301
- method: 'post',
1302
- query: {
1303
- appType: 'studio'
1304
- },
1305
- uri: `/projects/${projectId}/user-applications/${newStudioFromMenuId}/deployments`
1306
- }).reply(200, {
1307
- id: deploymentId
1308
- });
1309
- mockSelect.mockResolvedValue('NEW_STUDIO');
1310
- mockInput.mockImplementation(({ validate })=>{
1311
- const promise = (async ()=>{
1312
- if (validate) {
1313
- await validate('new-studio-from-menu');
1314
- }
1315
- return 'new-studio-from-menu';
1316
- })();
1317
- promise.cancel = ()=>{};
1318
- return promise;
1319
- });
1320
- const { error, stdout } = await testCommand(DeployCommand, [], {
1321
- config: {
1322
- root: cwd
1323
- },
1324
- mocks: {
1325
- cliConfig: {
1326
- api: {
1327
- projectId
1328
- }
1329
- }
1330
- }
1331
- });
1332
- expect(error).toBeUndefined();
1333
- expect(stdout).toContain('Success! Studio deployed');
1334
- expect(mockInput).toHaveBeenCalledWith({
1335
- message: 'Studio hostname (<value>.sanity.studio):',
1336
- validate: expect.any(Function)
1337
- });
1338
- });
1339
- test('should handle input validation with retry for studio hostname creation', async ()=>{
1340
- const cwd = await testExample('basic-studio');
1341
- process.cwd = ()=>cwd;
1342
- const projectId = 'test-project-id';
1343
- const validStudioId = 'valid-studio-id';
1344
- const deploymentId = 'deployment-id';
1345
- mockInput.mockImplementation(({ validate })=>{
1346
- const promise = (async ()=>{
1347
- if (validate) {
1348
- // First attempt with a name that will be taken (triggers 409)
1349
- let result = await validate('taken-name');
1350
- if (result !== true) {
1351
- // Name was taken, try again with a valid name (triggers 200)
1352
- result = await validate('valid-name');
1353
- }
1354
- }
1355
- return 'valid-name';
1356
- })();
1357
- promise.cancel = ()=>{};
1358
- return promise;
1359
- });
1360
- mockApi({
1361
- apiVersion: USER_APPLICATIONS_API_VERSION,
1362
- query: {
1363
- appType: 'studio'
1364
- },
1365
- uri: `/projects/${projectId}/user-applications`
1366
- }).reply(200, []);
1367
- // First API call fails (hostname taken)
1368
- mockApi({
1369
- apiVersion: USER_APPLICATIONS_API_VERSION,
1370
- method: 'post',
1371
- query: {
1372
- appType: 'studio'
1373
- },
1374
- uri: `/projects/${projectId}/user-applications`
1375
- }).once().reply(409, {
1376
- message: 'Studio hostname already taken',
1377
- statusCode: 409
1378
- });
1379
- // Second API call succeeds
1380
- mockApi({
1381
- apiVersion: USER_APPLICATIONS_API_VERSION,
1382
- method: 'post',
1383
- query: {
1384
- appType: 'studio'
1385
- },
1386
- uri: `/projects/${projectId}/user-applications`
1387
- }).once().reply(200, {
1388
- appHost: 'valid-name',
1389
- createdAt: '2024-01-01T00:00:00Z',
1390
- id: validStudioId,
1391
- projectId,
1392
- title: 'Valid Studio',
1393
- type: 'studio',
1394
- updatedAt: '2024-01-01T00:00:00Z',
1395
- urlType: 'internal'
1396
- });
1397
- mockApi({
1398
- apiVersion: USER_APPLICATIONS_API_VERSION,
1399
- method: 'post',
1400
- query: {
1401
- appType: 'studio'
1402
- },
1403
- uri: `/projects/${projectId}/user-applications/${validStudioId}/deployments`
1404
- }).reply(200, {
1405
- id: deploymentId
1406
- });
1407
- const { error, stdout } = await testCommand(DeployCommand, [], {
1408
- config: {
1409
- root: cwd
1410
- },
1411
- mocks: {
1412
- cliConfig: {
1413
- api: {
1414
- projectId
1415
- }
1416
- }
1417
- }
1418
- });
1419
- expect(error).toBeUndefined();
1420
- expect(stdout).toContain('Success! Studio deployed');
1421
- });
1422
- test('should handle input validation fails with unknown error', async ()=>{
1423
- const cwd = await testExample('basic-studio');
1424
- process.cwd = ()=>cwd;
1425
- const projectId = 'test-project-id';
1426
- mockInput.mockImplementation(({ validate })=>{
1427
- const promise = (async ()=>{
1428
- if (validate) {
1429
- // First attempt with a name that will be taken (triggers 409)
1430
- let result = await validate('taken-name');
1431
- if (result !== true) {
1432
- // Name was taken, try again with a valid name (triggers 200)
1433
- result = await validate('valid-name');
1434
- }
1435
- }
1436
- return 'valid-name';
1437
- })();
1438
- promise.cancel = ()=>{};
1439
- return promise;
1440
- });
1441
- mockApi({
1442
- apiVersion: USER_APPLICATIONS_API_VERSION,
1443
- query: {
1444
- appType: 'studio'
1445
- },
1446
- uri: `/projects/${projectId}/user-applications`
1447
- }).reply(200, []);
1448
- // First API call fails (hostname taken)
1449
- mockApi({
1450
- apiVersion: USER_APPLICATIONS_API_VERSION,
1451
- method: 'post',
1452
- query: {
1453
- appType: 'studio'
1454
- },
1455
- uri: `/projects/${projectId}/user-applications`
1456
- }).once().reply(500, {
1457
- message: 'Internal server error',
1458
- statusCode: 500
1459
- });
1460
- const { error } = await testCommand(DeployCommand, [], {
1461
- config: {
1462
- root: cwd
1463
- },
1464
- mocks: {
1465
- cliConfig: {
1466
- api: {
1467
- projectId
1468
- }
1469
- }
1470
- }
1471
- });
1472
- expect(error?.message).toContain('Error creating user application');
1473
- expect(error?.oclif?.exit).toBe(1);
1474
- });
1475
- test('should throw error when no projectId is configured', async ()=>{
1476
- const cwd = await testExample('basic-studio');
1477
- process.cwd = ()=>cwd;
1478
- const { error } = await testCommand(DeployCommand, [], {
1479
- config: {
1480
- root: cwd
1481
- },
1482
- mocks: {
1483
- cliConfig: {
1484
- api: {},
1485
- studioHost: 'some-studio'
1486
- }
1487
- }
1488
- });
1489
- expect(error?.message).toContain('sanity.cli.ts does not contain a project identifier ("api.projectId"), which is required for the Sanity CLI to communicate with the Sanity API');
1490
- expect(error?.oclif?.exit).toBe(1);
1491
- });
1492
- test('should log a warning if the deprecated auto-updates flag is used', async ()=>{
1493
- const cwd = await testExample('basic-studio');
1494
- process.cwd = ()=>cwd;
1495
- const projectId = 'test-project-id';
1496
- const studioHost = 'test-studio';
1497
- const { stderr } = await testCommand(DeployCommand, [
1498
- '--auto-updates'
1499
- ], {
1500
- config: {
1501
- root: cwd
1502
- },
1503
- mocks: {
1504
- cliConfig: {
1505
- api: {
1506
- projectId
1507
- },
1508
- studioHost
1509
- }
1510
- }
1511
- });
1512
- expect(stderr).toContain('Warning: The --auto-updates flag is deprecated');
1513
- });
1514
- test('should throw an error when both the current and deprecated autoUpdates config are used', async ()=>{
1515
- const cwd = await testExample('basic-studio');
1516
- process.cwd = ()=>cwd;
1517
- const { error } = await testCommand(DeployCommand, [], {
1518
- config: {
1519
- root: cwd
1520
- },
1521
- mocks: {
1522
- cliConfig: {
1523
- autoUpdates: true,
1524
- deployment: {
1525
- autoUpdates: true
1526
- }
1527
- }
1528
- }
1529
- });
1530
- expect(error?.message).toContain('Found both `autoUpdates` (deprecated) and `deployment.autoUpdates` in sanity.cli.');
1531
- expect(error?.oclif?.exit).toBe(1);
1532
- });
1533
- test('should handle general API errors when finding user application', async ()=>{
1534
- const cwd = await testExample('basic-studio');
1535
- process.cwd = ()=>cwd;
1536
- const projectId = 'test-project-id';
1537
- const studioHost = 'existing-studio';
1538
- mockApi({
1539
- apiVersion: USER_APPLICATIONS_API_VERSION,
1540
- query: {
1541
- appHost: studioHost,
1542
- appType: 'studio'
1543
- },
1544
- uri: `/projects/${projectId}/user-applications`
1545
- }).reply(500, {
1546
- error: 'Internal server error'
1547
- });
1548
- const { error } = await testCommand(DeployCommand, [], {
1549
- config: {
1550
- root: cwd
1551
- },
1552
- mocks: {
1553
- cliConfig: {
1554
- api: {
1555
- projectId
1556
- },
1557
- studioHost
1558
- }
1559
- }
1560
- });
1561
- expect(error?.message).toContain('Error finding user application');
1562
- expect(error?.oclif?.exit).toBe(1);
1563
- });
1564
- test('should handle deployment API errors for studio', async ()=>{
1565
- const cwd = await testExample('basic-studio');
1566
- process.cwd = ()=>cwd;
1567
- const projectId = 'test-project-id';
1568
- const studioHost = 'existing-studio';
1569
- const studioAppId = 'studio-app-id';
1570
- mockApi({
1571
- apiVersion: USER_APPLICATIONS_API_VERSION,
1572
- query: {
1573
- appHost: studioHost,
1574
- appType: 'studio'
1575
- },
1576
- uri: `/projects/${projectId}/user-applications`
1577
- }).reply(200, {
1578
- appHost: studioHost,
1579
- createdAt: '2024-01-01T00:00:00Z',
1580
- id: studioAppId,
1581
- projectId,
1582
- title: 'Existing Studio',
1583
- type: 'studio',
1584
- updatedAt: '2024-01-01T00:00:00Z',
1585
- urlType: 'internal'
1586
- });
1587
- mockApi({
1588
- apiVersion: USER_APPLICATIONS_API_VERSION,
1589
- method: 'post',
1590
- query: {
1591
- appType: 'studio'
1592
- },
1593
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1594
- }).reply(500, {
1595
- error: 'Internal server error'
1596
- });
1597
- const { error } = await testCommand(DeployCommand, [], {
1598
- config: {
1599
- root: cwd
1600
- },
1601
- mocks: {
1602
- cliConfig: {
1603
- api: {
1604
- projectId
1605
- },
1606
- studioHost
1607
- }
1608
- }
1609
- });
1610
- expect(error?.message).toContain('Error deploying studio');
1611
- expect(error?.oclif?.exit).toBe(1);
1612
- });
1613
- test('should handle fatal errors during studio hostname creation', async ()=>{
1614
- const cwd = await testExample('basic-studio');
1615
- process.cwd = ()=>cwd;
1616
- const projectId = 'test-project-id';
1617
- const studioHost = 'new-studio-host';
1618
- mockApi({
1619
- apiVersion: USER_APPLICATIONS_API_VERSION,
1620
- query: {
1621
- appHost: studioHost,
1622
- appType: 'studio'
1623
- },
1624
- uri: `/projects/${projectId}/user-applications`
1625
- }).reply(404, {
1626
- message: 'Not found'
1627
- });
1628
- mockApi({
1629
- apiVersion: USER_APPLICATIONS_API_VERSION,
1630
- method: 'post',
1631
- query: {
1632
- appType: 'studio'
1633
- },
1634
- uri: `/projects/${projectId}/user-applications`
1635
- }).reply(500, {
1636
- message: 'Internal server error',
1637
- statusCode: 500
1638
- });
1639
- const { error } = await testCommand(DeployCommand, [], {
1640
- config: {
1641
- root: cwd
1642
- },
1643
- mocks: {
1644
- cliConfig: {
1645
- api: {
1646
- projectId
1647
- },
1648
- studioHost
1649
- }
1650
- }
1651
- });
1652
- expect(error?.message).toContain('Error creating user application from config');
1653
- expect(error?.oclif?.exit).toBe(1);
1654
- });
1655
- test('should handle no existing studio applications scenario', async ()=>{
1656
- const cwd = await testExample('basic-studio');
1657
- process.cwd = ()=>cwd;
1658
- const projectId = 'test-project-id';
1659
- const newStudioId = 'new-studio-id';
1660
- const deploymentId = 'deployment-id';
1661
- mockInput.mockImplementation(({ validate })=>{
1662
- const promise = (async ()=>{
1663
- if (validate) {
1664
- await validate('new-studio-name');
1665
- }
1666
- return 'new-studio-name';
1667
- })();
1668
- promise.cancel = ()=>{};
1669
- return promise;
1670
- });
1671
- mockApi({
1672
- apiVersion: USER_APPLICATIONS_API_VERSION,
1673
- query: {
1674
- appType: 'studio'
1675
- },
1676
- uri: `/projects/${projectId}/user-applications`
1677
- }).reply(200, []);
1678
- mockApi({
1679
- apiVersion: USER_APPLICATIONS_API_VERSION,
1680
- method: 'post',
1681
- query: {
1682
- appType: 'studio'
1683
- },
1684
- uri: `/projects/${projectId}/user-applications`
1685
- }).reply(200, {
1686
- appHost: 'new-studio-name',
1687
- createdAt: '2024-01-01T00:00:00Z',
1688
- id: newStudioId,
1689
- projectId,
1690
- title: 'New Studio',
1691
- type: 'studio',
1692
- updatedAt: '2024-01-01T00:00:00Z',
1693
- urlType: 'internal'
1694
- });
1695
- mockApi({
1696
- apiVersion: USER_APPLICATIONS_API_VERSION,
1697
- method: 'post',
1698
- query: {
1699
- appType: 'studio'
1700
- },
1701
- uri: `/projects/${projectId}/user-applications/${newStudioId}/deployments`
1702
- }).reply(200, {
1703
- id: deploymentId
1704
- });
1705
- const { error, stdout } = await testCommand(DeployCommand, [], {
1706
- config: {
1707
- root: cwd
1708
- },
1709
- mocks: {
1710
- cliConfig: {
1711
- api: {
1712
- projectId
1713
- }
1714
- }
1715
- }
1716
- });
1717
- expect(error).toBeUndefined();
1718
- expect(stdout).toContain('Success! Studio deployed');
1719
- expect(mockInput).toHaveBeenCalledWith({
1720
- message: 'Studio hostname (<value>.sanity.studio):',
1721
- validate: expect.any(Function)
1722
- });
1723
- });
1724
- test('should skip build when --no-build flag is used for studio', async ()=>{
1725
- const cwd = await testExample('basic-studio');
1726
- process.cwd = ()=>cwd;
1727
- const projectId = 'test-project-id';
1728
- const studioHost = 'existing-studio';
1729
- const studioAppId = 'studio-app-id';
1730
- const deploymentId = 'deployment-id';
1731
- mockApi({
1732
- apiVersion: USER_APPLICATIONS_API_VERSION,
1733
- query: {
1734
- appHost: studioHost,
1735
- appType: 'studio'
1736
- },
1737
- uri: `/projects/${projectId}/user-applications`
1738
- }).reply(200, {
1739
- appHost: studioHost,
1740
- createdAt: '2024-01-01T00:00:00Z',
1741
- id: studioAppId,
1742
- projectId,
1743
- title: 'Existing Studio',
1744
- type: 'studio',
1745
- updatedAt: '2024-01-01T00:00:00Z',
1746
- urlType: 'internal'
1747
- });
1748
- mockApi({
1749
- apiVersion: USER_APPLICATIONS_API_VERSION,
1750
- method: 'post',
1751
- query: {
1752
- appType: 'studio'
1753
- },
1754
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1755
- }).reply(200, {
1756
- id: deploymentId
1757
- });
1758
- const { error, stdout } = await testCommand(DeployCommand, [
1759
- '--no-build'
1760
- ], {
1761
- config: {
1762
- root: cwd
1763
- },
1764
- mocks: {
1765
- cliConfig: {
1766
- api: {
1767
- projectId
1768
- },
1769
- studioHost
1770
- }
1771
- }
1772
- });
1773
- expect(error).toBeUndefined();
1774
- expect(stdout).toContain('Success! Studio deployed');
1775
- expect(mockBuildStudio).not.toHaveBeenCalled();
1776
- });
1777
- test('should deploy studio using deployment.appId', async ()=>{
1778
- const cwd = await testExample('basic-studio');
1779
- process.cwd = ()=>cwd;
1780
- const projectId = 'test-project-id';
1781
- const studioAppId = 'studio-app-id';
1782
- const appHost = 'my-studio';
1783
- const deploymentId = 'deployment-id';
1784
- mockApi({
1785
- apiVersion: USER_APPLICATIONS_API_VERSION,
1786
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1787
- }).reply(200, {
1788
- appHost,
1789
- createdAt: '2024-01-01T00:00:00Z',
1790
- id: studioAppId,
1791
- projectId,
1792
- title: 'My Studio',
1793
- type: 'studio',
1794
- updatedAt: '2024-01-01T00:00:00Z',
1795
- urlType: 'internal'
1796
- });
1797
- mockApi({
1798
- apiVersion: USER_APPLICATIONS_API_VERSION,
1799
- method: 'post',
1800
- query: {
1801
- appType: 'studio'
1802
- },
1803
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1804
- }).reply(200, {
1805
- id: deploymentId,
1806
- location: `https://${appHost}.sanity.studio`
1807
- });
1808
- const { error, stdout } = await testCommand(DeployCommand, [], {
1809
- config: {
1810
- root: cwd
1811
- },
1812
- mocks: {
1813
- cliConfig: {
1814
- api: {
1815
- projectId
1816
- },
1817
- deployment: {
1818
- appId: studioAppId
1819
- }
1820
- }
1821
- }
1822
- });
1823
- expect(error).toBeUndefined();
1824
- expect(stdout).toContain(`Success! Studio deployed to https://${appHost}.sanity.studio`);
1825
- });
1826
- test('should prioritize deployment.appId over studioHost when both are configured', async ()=>{
1827
- const cwd = await testExample('basic-studio');
1828
- process.cwd = ()=>cwd;
1829
- const projectId = 'test-project-id';
1830
- const studioAppId = 'studio-app-id';
1831
- const studioHost = 'my-studio-host';
1832
- const deploymentId = 'deployment-id';
1833
- // Should call by appId, NOT by appHost
1834
- mockApi({
1835
- apiVersion: USER_APPLICATIONS_API_VERSION,
1836
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1837
- }).reply(200, {
1838
- appHost: studioHost,
1839
- createdAt: '2024-01-01T00:00:00Z',
1840
- id: studioAppId,
1841
- projectId,
1842
- title: 'My Studio',
1843
- type: 'studio',
1844
- updatedAt: '2024-01-01T00:00:00Z',
1845
- urlType: 'internal'
1846
- });
1847
- mockApi({
1848
- apiVersion: USER_APPLICATIONS_API_VERSION,
1849
- method: 'post',
1850
- query: {
1851
- appType: 'studio'
1852
- },
1853
- uri: `/projects/${projectId}/user-applications/${studioAppId}/deployments`
1854
- }).reply(200, {
1855
- id: deploymentId,
1856
- location: `https://${studioHost}.sanity.studio`
1857
- });
1858
- const { error, stdout } = await testCommand(DeployCommand, [], {
1859
- config: {
1860
- root: cwd
1861
- },
1862
- mocks: {
1863
- cliConfig: {
1864
- api: {
1865
- projectId
1866
- },
1867
- deployment: {
1868
- appId: studioAppId
1869
- },
1870
- studioHost
1871
- }
1872
- }
1873
- });
1874
- expect(error).toBeUndefined();
1875
- expect(stdout).toContain(`Success! Studio deployed to https://${studioHost}.sanity.studio`);
1876
- });
1877
- test('should handle error when deployment.appId does not exist for the org', async ()=>{
1878
- const cwd = await testExample('basic-studio');
1879
- process.cwd = ()=>cwd;
1880
- const projectId = 'test-project-id';
1881
- const studioAppId = 'non-existent-app-id';
1882
- mockApi({
1883
- apiVersion: USER_APPLICATIONS_API_VERSION,
1884
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1885
- }).reply(404, {
1886
- message: 'Application not found'
1887
- });
1888
- const { error } = await testCommand(DeployCommand, [], {
1889
- config: {
1890
- root: cwd
1891
- },
1892
- mocks: {
1893
- cliConfig: {
1894
- api: {
1895
- projectId
1896
- },
1897
- deployment: {
1898
- appId: studioAppId
1899
- }
1900
- }
1901
- }
1902
- });
1903
- expect(error?.message).toContain('Error finding user application');
1904
- expect(error?.message).toContain(`Cannot find app with app ID ${studioAppId}`);
1905
- expect(error?.oclif?.exit).toBe(1);
1906
- });
1907
- test('should not fall back to studioHost when deployment.appId is configured but does not exist', async ()=>{
1908
- const cwd = await testExample('basic-studio');
1909
- process.cwd = ()=>cwd;
1910
- const projectId = 'test-project-id';
1911
- const studioAppId = 'non-existent-app-id';
1912
- const studioHost = 'valid-studio-host';
1913
- // appId lookup fails
1914
- mockApi({
1915
- apiVersion: USER_APPLICATIONS_API_VERSION,
1916
- uri: `/projects/${projectId}/user-applications/${studioAppId}`
1917
- }).reply(404, {
1918
- message: 'Application not found'
1919
- });
1920
- // Should NOT make a call to studioHost - if it does, this mock will remain unused
1921
- // and cause the test to fail due to pending mocks check
1922
- const { error } = await testCommand(DeployCommand, [], {
1923
- config: {
1924
- root: cwd
1925
- },
1926
- mocks: {
1927
- cliConfig: {
1928
- api: {
1929
- projectId
1930
- },
1931
- deployment: {
1932
- appId: studioAppId
1933
- },
1934
- studioHost
1935
- }
1936
- }
1937
- });
1938
- expect(error?.message).toContain('Error finding user application');
1939
- expect(error?.message).toContain(`Cannot find app with app ID ${studioAppId}`);
1940
- expect(error?.oclif?.exit).toBe(1);
1941
- });
1942
- });
1943
- });
1944
-
1945
- //# sourceMappingURL=deploy.test.js.map