@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.
Files changed (291) hide show
  1. package/dist/actions/dev/startStudioDevServer.js +3 -8
  2. package/dist/actions/dev/startStudioDevServer.js.map +1 -1
  3. package/dist/actions/dev/types.d.ts +1 -3
  4. package/dist/actions/dev/types.js.map +1 -1
  5. package/dist/actions/documents/validate.d.ts +0 -2
  6. package/dist/actions/documents/validate.js +21 -1
  7. package/dist/actions/documents/validate.js.map +1 -1
  8. package/dist/actions/exec/execScript.js +1 -1
  9. package/dist/actions/exec/execScript.js.map +1 -1
  10. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js +1 -1
  11. package/dist/actions/graphql/__tests__/getGraphQLAPIs.test.js.map +1 -1
  12. package/dist/actions/graphql/getGraphQLAPIs.js +1 -1
  13. package/dist/actions/graphql/getGraphQLAPIs.js.map +1 -1
  14. package/dist/actions/manifest/extractManifest.js +1 -4
  15. package/dist/actions/manifest/extractManifest.js.map +1 -1
  16. package/dist/actions/schema/deleteSchemaAction.d.ts +13 -5
  17. package/dist/actions/schema/deleteSchemaAction.js +12 -17
  18. package/dist/actions/schema/deleteSchemaAction.js.map +1 -1
  19. package/dist/actions/schema/deploySchemas.d.ts +15 -0
  20. package/dist/actions/schema/deploySchemas.js +98 -0
  21. package/dist/actions/schema/deploySchemas.js.map +1 -0
  22. package/dist/actions/schema/listSchemas.d.ts +12 -0
  23. package/dist/actions/schema/listSchemas.js +119 -0
  24. package/dist/actions/schema/listSchemas.js.map +1 -0
  25. package/dist/actions/schema/schemaStoreTypes.d.ts +0 -11
  26. package/dist/actions/schema/schemaStoreTypes.js.map +1 -1
  27. package/dist/actions/schema/utils/debug.d.ts +2 -0
  28. package/dist/actions/schema/utils/debug.js +5 -0
  29. package/dist/actions/schema/utils/debug.js.map +1 -0
  30. package/dist/actions/schema/utils/manifestExtractor.d.ts +3 -8
  31. package/dist/actions/schema/utils/manifestExtractor.js +12 -17
  32. package/dist/actions/schema/utils/manifestExtractor.js.map +1 -1
  33. package/dist/actions/schema/utils/manifestReader.d.ts +2 -9
  34. package/dist/actions/schema/utils/manifestReader.js +6 -12
  35. package/dist/actions/schema/utils/manifestReader.js.map +1 -1
  36. package/dist/actions/schema/utils/schemaStoreOutStrings.d.ts +0 -1
  37. package/dist/actions/schema/utils/schemaStoreOutStrings.js +1 -1
  38. package/dist/actions/schema/utils/schemaStoreOutStrings.js.map +1 -1
  39. package/dist/actions/schema/utils/schemaStoreValidation.d.ts +10 -62
  40. package/dist/actions/schema/utils/schemaStoreValidation.js +38 -125
  41. package/dist/actions/schema/utils/schemaStoreValidation.js.map +1 -1
  42. package/dist/actions/schema/utils/uniqByProjectIdDataset.d.ts +14 -0
  43. package/dist/actions/schema/utils/uniqByProjectIdDataset.js +9 -0
  44. package/dist/actions/schema/utils/uniqByProjectIdDataset.js.map +1 -0
  45. package/dist/actions/users/getMembersForProject.d.ts +1 -3
  46. package/dist/actions/users/getMembersForProject.js +6 -17
  47. package/dist/actions/users/getMembersForProject.js.map +1 -1
  48. package/dist/actions/users/types.d.ts +0 -11
  49. package/dist/actions/users/types.js.map +1 -1
  50. package/dist/commands/__tests__/debug.test.js +113 -220
  51. package/dist/commands/__tests__/debug.test.js.map +1 -1
  52. package/dist/commands/__tests__/deploy.test.js +325 -293
  53. package/dist/commands/__tests__/deploy.test.js.map +1 -1
  54. package/dist/commands/__tests__/dev.test.js +62 -19
  55. package/dist/commands/__tests__/dev.test.js.map +1 -1
  56. package/dist/commands/__tests__/init/init.authentication.test.js +40 -27
  57. package/dist/commands/__tests__/init/init.authentication.test.js.map +1 -1
  58. package/dist/commands/__tests__/init/init.create-new-project.test.js +84 -85
  59. package/dist/commands/__tests__/init/init.create-new-project.test.js.map +1 -1
  60. package/dist/commands/__tests__/init/init.plan.test.js +103 -44
  61. package/dist/commands/__tests__/init/init.plan.test.js.map +1 -1
  62. package/dist/commands/__tests__/init/init.setup.test.js +85 -29
  63. package/dist/commands/__tests__/init/init.setup.test.js.map +1 -1
  64. package/dist/commands/__tests__/install.test.js +46 -22
  65. package/dist/commands/__tests__/install.test.js.map +1 -1
  66. package/dist/commands/__tests__/logout.test.js +8 -5
  67. package/dist/commands/__tests__/logout.test.js.map +1 -1
  68. package/dist/commands/__tests__/manage.test.js +29 -24
  69. package/dist/commands/__tests__/manage.test.js.map +1 -1
  70. package/dist/commands/__tests__/versions.test.js +22 -14
  71. package/dist/commands/__tests__/versions.test.js.map +1 -1
  72. package/dist/commands/backup/__tests__/disable.test.js +72 -75
  73. package/dist/commands/backup/__tests__/disable.test.js.map +1 -1
  74. package/dist/commands/backup/__tests__/download.test.js +166 -77
  75. package/dist/commands/backup/__tests__/download.test.js.map +1 -1
  76. package/dist/commands/backup/__tests__/enable.test.js +109 -140
  77. package/dist/commands/backup/__tests__/enable.test.js.map +1 -1
  78. package/dist/commands/backup/__tests__/list.test.js +84 -75
  79. package/dist/commands/backup/__tests__/list.test.js.map +1 -1
  80. package/dist/commands/backup/disable.js +5 -11
  81. package/dist/commands/backup/disable.js.map +1 -1
  82. package/dist/commands/backup/enable.js +5 -11
  83. package/dist/commands/backup/enable.js.map +1 -1
  84. package/dist/commands/backup/list.js +7 -8
  85. package/dist/commands/backup/list.js.map +1 -1
  86. package/dist/commands/cors/__tests__/add.test.js +68 -38
  87. package/dist/commands/cors/__tests__/add.test.js.map +1 -1
  88. package/dist/commands/cors/__tests__/delete.test.js +52 -37
  89. package/dist/commands/cors/__tests__/delete.test.js.map +1 -1
  90. package/dist/commands/cors/__tests__/list.test.js +80 -57
  91. package/dist/commands/cors/__tests__/list.test.js.map +1 -1
  92. package/dist/commands/cors/add.js +5 -13
  93. package/dist/commands/cors/add.js.map +1 -1
  94. package/dist/commands/cors/delete.js +7 -15
  95. package/dist/commands/cors/delete.js.map +1 -1
  96. package/dist/commands/cors/list.js +2 -10
  97. package/dist/commands/cors/list.js.map +1 -1
  98. package/dist/commands/dataset/__tests__/copy.test.js +197 -89
  99. package/dist/commands/dataset/__tests__/copy.test.js.map +1 -1
  100. package/dist/commands/dataset/__tests__/create.test.js +147 -117
  101. package/dist/commands/dataset/__tests__/create.test.js.map +1 -1
  102. package/dist/commands/dataset/__tests__/delete.test.js +75 -68
  103. package/dist/commands/dataset/__tests__/delete.test.js.map +1 -1
  104. package/dist/commands/dataset/__tests__/export.test.js +123 -83
  105. package/dist/commands/dataset/__tests__/export.test.js.map +1 -1
  106. package/dist/commands/dataset/__tests__/list.test.js +107 -65
  107. package/dist/commands/dataset/__tests__/list.test.js.map +1 -1
  108. package/dist/commands/dataset/alias/__tests__/create.test.js +114 -74
  109. package/dist/commands/dataset/alias/__tests__/create.test.js.map +1 -1
  110. package/dist/commands/dataset/alias/__tests__/delete.test.js +40 -29
  111. package/dist/commands/dataset/alias/__tests__/delete.test.js.map +1 -1
  112. package/dist/commands/dataset/alias/__tests__/link.test.js +114 -74
  113. package/dist/commands/dataset/alias/__tests__/link.test.js.map +1 -1
  114. package/dist/commands/dataset/alias/__tests__/unlink.test.js +44 -29
  115. package/dist/commands/dataset/alias/__tests__/unlink.test.js.map +1 -1
  116. package/dist/commands/dataset/export.js +4 -4
  117. package/dist/commands/dataset/export.js.map +1 -1
  118. package/dist/commands/dataset/visibility/__tests__/get.test.js +48 -67
  119. package/dist/commands/dataset/visibility/__tests__/get.test.js.map +1 -1
  120. package/dist/commands/dataset/visibility/__tests__/set.test.js +76 -123
  121. package/dist/commands/dataset/visibility/__tests__/set.test.js.map +1 -1
  122. package/dist/commands/dev.js +0 -1
  123. package/dist/commands/dev.js.map +1 -1
  124. package/dist/commands/docs/__tests__/search.test.js +8 -7
  125. package/dist/commands/docs/__tests__/search.test.js.map +1 -1
  126. package/dist/commands/documents/__tests__/create.test.js +328 -265
  127. package/dist/commands/documents/__tests__/create.test.js.map +1 -1
  128. package/dist/commands/documents/__tests__/delete.test.js +119 -87
  129. package/dist/commands/documents/__tests__/delete.test.js.map +1 -1
  130. package/dist/commands/documents/__tests__/get.test.js +68 -95
  131. package/dist/commands/documents/__tests__/get.test.js.map +1 -1
  132. package/dist/commands/documents/__tests__/query.test.js +84 -189
  133. package/dist/commands/documents/__tests__/query.test.js.map +1 -1
  134. package/dist/commands/documents/__tests__/validate.test.js +52 -29
  135. package/dist/commands/documents/__tests__/validate.test.js.map +1 -1
  136. package/dist/commands/documents/create.d.ts +1 -0
  137. package/dist/commands/documents/create.js +10 -9
  138. package/dist/commands/documents/create.js.map +1 -1
  139. package/dist/commands/documents/delete.js +2 -3
  140. package/dist/commands/documents/delete.js.map +1 -1
  141. package/dist/commands/documents/get.js +2 -3
  142. package/dist/commands/documents/get.js.map +1 -1
  143. package/dist/commands/documents/query.js +2 -3
  144. package/dist/commands/documents/query.js.map +1 -1
  145. package/dist/commands/documents/validate.js +0 -20
  146. package/dist/commands/documents/validate.js.map +1 -1
  147. package/dist/commands/graphql/__tests__/list.test.js +57 -45
  148. package/dist/commands/graphql/__tests__/list.test.js.map +1 -1
  149. package/dist/commands/graphql/__tests__/undeploy.test.js +85 -59
  150. package/dist/commands/graphql/__tests__/undeploy.test.js.map +1 -1
  151. package/dist/commands/graphql/list.js +2 -2
  152. package/dist/commands/graphql/list.js.map +1 -1
  153. package/dist/commands/graphql/undeploy.js +4 -9
  154. package/dist/commands/graphql/undeploy.js.map +1 -1
  155. package/dist/commands/hook/__tests__/attempt.test.js +48 -33
  156. package/dist/commands/hook/__tests__/attempt.test.js.map +1 -1
  157. package/dist/commands/hook/__tests__/create.test.js +49 -51
  158. package/dist/commands/hook/__tests__/create.test.js.map +1 -1
  159. package/dist/commands/hook/__tests__/delete.test.js +43 -30
  160. package/dist/commands/hook/__tests__/delete.test.js.map +1 -1
  161. package/dist/commands/hook/__tests__/list.test.js +38 -31
  162. package/dist/commands/hook/__tests__/list.test.js.map +1 -1
  163. package/dist/commands/hook/__tests__/logs.test.js +68 -40
  164. package/dist/commands/hook/__tests__/logs.test.js.map +1 -1
  165. package/dist/commands/hook/create.js +2 -6
  166. package/dist/commands/hook/create.js.map +1 -1
  167. package/dist/commands/hook/delete.js +5 -17
  168. package/dist/commands/hook/delete.js.map +1 -1
  169. package/dist/commands/hook/list.js +2 -8
  170. package/dist/commands/hook/list.js.map +1 -1
  171. package/dist/commands/manifest/__tests__/extract.test.js +22 -13
  172. package/dist/commands/manifest/__tests__/extract.test.js.map +1 -1
  173. package/dist/commands/media/__tests__/create-aspect.test.js +41 -28
  174. package/dist/commands/media/__tests__/create-aspect.test.js.map +1 -1
  175. package/dist/commands/media/__tests__/delete-aspect.test.js +44 -35
  176. package/dist/commands/media/__tests__/delete-aspect.test.js.map +1 -1
  177. package/dist/commands/media/__tests__/deploy-aspect.test.js +67 -80
  178. package/dist/commands/media/__tests__/deploy-aspect.test.js.map +1 -1
  179. package/dist/commands/media/__tests__/export.test.js +365 -66
  180. package/dist/commands/media/__tests__/export.test.js.map +1 -1
  181. package/dist/commands/media/__tests__/import.test.js +171 -105
  182. package/dist/commands/media/__tests__/import.test.js.map +1 -1
  183. package/dist/commands/media/export.js +2 -2
  184. package/dist/commands/media/export.js.map +1 -1
  185. package/dist/commands/media/import.js +2 -2
  186. package/dist/commands/media/import.js.map +1 -1
  187. package/dist/commands/projects/__tests__/list.test.js +5 -4
  188. package/dist/commands/projects/__tests__/list.test.js.map +1 -1
  189. package/dist/commands/projects/list.js +2 -6
  190. package/dist/commands/projects/list.js.map +1 -1
  191. package/dist/commands/schema/__tests__/delete.test.js +396 -151
  192. package/dist/commands/schema/__tests__/delete.test.js.map +1 -1
  193. package/dist/commands/schema/__tests__/deploy.test.js +348 -0
  194. package/dist/commands/schema/__tests__/deploy.test.js.map +1 -0
  195. package/dist/commands/schema/__tests__/extract.test.js +19 -11
  196. package/dist/commands/schema/__tests__/extract.test.js.map +1 -1
  197. package/dist/commands/schema/__tests__/list.test.js +399 -0
  198. package/dist/commands/schema/__tests__/list.test.js.map +1 -0
  199. package/dist/commands/schema/__tests__/validate.test.js +27 -10
  200. package/dist/commands/schema/__tests__/validate.test.js.map +1 -1
  201. package/dist/commands/schema/delete.d.ts +1 -1
  202. package/dist/commands/schema/delete.js +20 -23
  203. package/dist/commands/schema/delete.js.map +1 -1
  204. package/dist/commands/schema/deploy.d.ts +16 -0
  205. package/dist/commands/schema/deploy.js +98 -0
  206. package/dist/commands/schema/deploy.js.map +1 -0
  207. package/dist/commands/schema/list.d.ts +15 -0
  208. package/dist/commands/schema/list.js +104 -0
  209. package/dist/commands/schema/list.js.map +1 -0
  210. package/dist/commands/telemetry/__tests__/disable.test.js +7 -5
  211. package/dist/commands/telemetry/__tests__/disable.test.js.map +1 -1
  212. package/dist/commands/telemetry/__tests__/enable.test.js +7 -5
  213. package/dist/commands/telemetry/__tests__/enable.test.js.map +1 -1
  214. package/dist/commands/telemetry/__tests__/status.test.js +7 -5
  215. package/dist/commands/telemetry/__tests__/status.test.js.map +1 -1
  216. package/dist/commands/tokens/__tests__/add.test.js +55 -40
  217. package/dist/commands/tokens/__tests__/add.test.js.map +1 -1
  218. package/dist/commands/tokens/__tests__/delete.test.js +72 -42
  219. package/dist/commands/tokens/__tests__/delete.test.js.map +1 -1
  220. package/dist/commands/tokens/__tests__/list.test.js +87 -60
  221. package/dist/commands/tokens/__tests__/list.test.js.map +1 -1
  222. package/dist/commands/tokens/add.js +3 -5
  223. package/dist/commands/tokens/add.js.map +1 -1
  224. package/dist/commands/users/__tests__/invite.test.js +100 -79
  225. package/dist/commands/users/__tests__/invite.test.js.map +1 -1
  226. package/dist/commands/users/__tests__/list.test.js +186 -180
  227. package/dist/commands/users/__tests__/list.test.js.map +1 -1
  228. package/dist/commands/users/invite.js +6 -17
  229. package/dist/commands/users/invite.js.map +1 -1
  230. package/dist/commands/users/list.js +4 -7
  231. package/dist/commands/users/list.js.map +1 -1
  232. package/dist/config/createCliConfig.d.ts +4 -4
  233. package/dist/services/backup.d.ts +8 -0
  234. package/dist/services/backup.js +19 -0
  235. package/dist/services/backup.js.map +1 -1
  236. package/dist/services/cors.d.ts +23 -0
  237. package/dist/services/cors.js +38 -0
  238. package/dist/services/cors.js.map +1 -0
  239. package/dist/services/graphql.d.ts +7 -0
  240. package/dist/services/graphql.js +11 -0
  241. package/dist/services/graphql.js.map +1 -1
  242. package/dist/services/hooks.d.ts +2 -0
  243. package/dist/services/hooks.js +19 -0
  244. package/dist/services/hooks.js.map +1 -1
  245. package/dist/services/organizations.d.ts +1 -1
  246. package/dist/services/organizations.js +1 -1
  247. package/dist/services/organizations.js.map +1 -1
  248. package/dist/services/projects.d.ts +11 -0
  249. package/dist/services/projects.js +41 -0
  250. package/dist/services/projects.js.map +1 -1
  251. package/dist/services/schemas.d.ts +4 -0
  252. package/dist/services/schemas.js +40 -0
  253. package/dist/services/schemas.js.map +1 -0
  254. package/dist/services/user.d.ts +8 -0
  255. package/dist/services/user.js +15 -2
  256. package/dist/services/user.js.map +1 -1
  257. package/dist/util/__tests__/getCliVersion.test.js +2 -2
  258. package/dist/util/__tests__/getCliVersion.test.js.map +1 -1
  259. package/dist/util/errorMessages.d.ts +1 -0
  260. package/dist/util/errorMessages.js +1 -0
  261. package/dist/util/errorMessages.js.map +1 -1
  262. package/dist/util/getCliVersion.js +1 -1
  263. package/dist/util/getCliVersion.js.map +1 -1
  264. package/dist/util/readPackageJson.d.ts +1 -15
  265. package/dist/util/readPackageJson.js +1 -1
  266. package/dist/util/readPackageJson.js.map +1 -1
  267. package/dist/util/uniqBy.d.ts +1 -0
  268. package/dist/util/uniqBy.js +14 -0
  269. package/dist/util/uniqBy.js.map +1 -0
  270. package/oclif.manifest.json +172 -27
  271. package/package.json +27 -28
  272. package/dist/actions/cors/constants.d.ts +0 -1
  273. package/dist/actions/cors/constants.js +0 -3
  274. package/dist/actions/cors/constants.js.map +0 -1
  275. package/dist/actions/cors/types.d.ts +0 -9
  276. package/dist/actions/cors/types.js +0 -3
  277. package/dist/actions/cors/types.js.map +0 -1
  278. package/dist/actions/schema/__tests__/deleteSchemaAction.test.js +0 -294
  279. package/dist/actions/schema/__tests__/deleteSchemaAction.test.js.map +0 -1
  280. package/dist/actions/schema/schemaStoreConstants.d.ts +0 -1
  281. package/dist/actions/schema/schemaStoreConstants.js +0 -4
  282. package/dist/actions/schema/schemaStoreConstants.js.map +0 -1
  283. package/dist/actions/schema/utils/schemaActionHelpers.d.ts +0 -1
  284. package/dist/actions/schema/utils/schemaActionHelpers.js +0 -5
  285. package/dist/actions/schema/utils/schemaActionHelpers.js.map +0 -1
  286. package/dist/actions/schema/utils/schemaApiClient.d.ts +0 -6
  287. package/dist/actions/schema/utils/schemaApiClient.js +0 -17
  288. package/dist/actions/schema/utils/schemaApiClient.js.map +0 -1
  289. package/dist/actions/users/apiVersion.d.ts +0 -6
  290. package/dist/actions/users/apiVersion.js +0 -7
  291. package/dist/actions/users/apiVersion.js.map +0 -1
@@ -1,5 +1,4 @@
1
1
  import { runCommand } from '@oclif/test';
2
- import { getCliConfig } from '@sanity/cli-core';
3
2
  import { confirm, input, select } from '@sanity/cli-core/ux';
4
3
  import { mockApi, testCommand } from '@sanity/cli-test';
5
4
  import nock from 'nock';
@@ -12,9 +11,6 @@ import { USER_APPLICATIONS_API_VERSION } from '../../services/userApplications.j
12
11
  import { dirIsEmptyOrNonExistent } from '../../util/dirIsEmptyOrNonExistent.js';
13
12
  import { readModuleVersion } from '../../util/readModuleVersion.js';
14
13
  import { DeployCommand } from '../deploy.js';
15
- vi.mock('../../../../cli-core/src/config/cli/getCliConfig.js', ()=>({
16
- getCliConfig: vi.fn()
17
- }));
18
14
  vi.mock('../../util/readModuleVersion.js', ()=>({
19
15
  readModuleVersion: vi.fn()
20
16
  }));
@@ -46,7 +42,6 @@ vi.mock('tar-fs', ()=>({
46
42
  };
47
43
  })
48
44
  }));
49
- const mockGetCliConfig = vi.mocked(getCliConfig);
50
45
  const mockSelect = vi.mocked(select);
51
46
  const mockConfirm = vi.mocked(confirm);
52
47
  const mockInput = vi.mocked(input);
@@ -55,6 +50,18 @@ const mockDirIsEmptyOrNonExistent = vi.mocked(dirIsEmptyOrNonExistent);
55
50
  const mockReadModuleVersion = vi.mocked(readModuleVersion);
56
51
  const mockBuildStudio = vi.mocked(buildStudio);
57
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
+ };
58
65
  describe('#deploy', ()=>{
59
66
  beforeEach(async ()=>{
60
67
  // Set up default mocks
@@ -129,15 +136,6 @@ describe('#deploy', ()=>{
129
136
  process.cwd = ()=>cwd;
130
137
  mockConfirm.mockResolvedValue(true);
131
138
  mockDirIsEmptyOrNonExistent.mockResolvedValue(false);
132
- const appId = 'app-id';
133
- mockGetCliConfig.mockResolvedValue({
134
- app: {
135
- organizationId: 'org-id'
136
- },
137
- deployment: {
138
- appId
139
- }
140
- });
141
139
  mockApi({
142
140
  apiVersion: USER_APPLICATIONS_API_VERSION,
143
141
  query: {
@@ -170,7 +168,8 @@ describe('#deploy', ()=>{
170
168
  ], {
171
169
  config: {
172
170
  root: cwd
173
- }
171
+ },
172
+ mocks: defaultMocks
174
173
  });
175
174
  expect(error).toBeUndefined();
176
175
  expect(mockConfirm).toHaveBeenCalledWith({
@@ -182,21 +181,13 @@ describe('#deploy', ()=>{
182
181
  const cwd = await testExample('basic-app');
183
182
  process.cwd = ()=>cwd;
184
183
  mockConfirm.mockResolvedValue(false);
185
- const appId = 'app-id';
186
- mockGetCliConfig.mockResolvedValue({
187
- app: {
188
- organizationId: 'org-id'
189
- },
190
- deployment: {
191
- appId
192
- }
193
- });
194
184
  const { error } = await testCommand(DeployCommand, [
195
185
  'build'
196
186
  ], {
197
187
  config: {
198
188
  root: cwd
199
- }
189
+ },
190
+ mocks: defaultMocks
200
191
  });
201
192
  expect(error?.message).toContain('Cancelled.');
202
193
  expect(error?.oclif?.exit).toBe(1);
@@ -205,15 +196,6 @@ describe('#deploy', ()=>{
205
196
  test('should re-deploy app if it already exists', async ()=>{
206
197
  const cwd = await testExample('basic-app');
207
198
  process.cwd = ()=>cwd;
208
- const appId = 'app-id';
209
- mockGetCliConfig.mockResolvedValue({
210
- app: {
211
- organizationId: 'org-id'
212
- },
213
- deployment: {
214
- appId
215
- }
216
- });
217
199
  mockApi({
218
200
  apiVersion: USER_APPLICATIONS_API_VERSION,
219
201
  query: {
@@ -244,7 +226,8 @@ describe('#deploy', ()=>{
244
226
  const { error, stderr, stdout } = await testCommand(DeployCommand, [], {
245
227
  config: {
246
228
  root: cwd
247
- }
229
+ },
230
+ mocks: defaultMocks
248
231
  });
249
232
  expect(error).toBeUndefined();
250
233
  expect(stderr).toContain('Checking application info');
@@ -255,36 +238,21 @@ describe('#deploy', ()=>{
255
238
  test('should handle missing @sanity/sdk-react version', async ()=>{
256
239
  const cwd = await testExample('basic-app');
257
240
  process.cwd = ()=>cwd;
258
- const appId = 'app-id';
259
- const organizationId = 'org-id';
260
241
  mockReadModuleVersion.mockResolvedValue(null);
261
- mockGetCliConfig.mockResolvedValue({
262
- app: {
263
- organizationId
264
- },
265
- deployment: {
266
- appId
267
- }
268
- });
269
242
  const { error } = await testCommand(DeployCommand, [], {
270
243
  config: {
271
244
  root: cwd
272
- }
245
+ },
246
+ mocks: defaultMocks
273
247
  });
274
248
  expect(error?.message).toContain('Failed to find installed @sanity/sdk-react version');
275
249
  });
276
250
  test('should create new user application if none exists', async ()=>{
277
251
  const cwd = await testExample('basic-app');
278
252
  process.cwd = ()=>cwd;
279
- const organizationId = 'org-id';
280
253
  const newAppId = 'new-app-id';
281
254
  const deploymentId = 'deployment-id';
282
255
  mockInput.mockResolvedValue('Test App');
283
- mockGetCliConfig.mockResolvedValue({
284
- app: {
285
- organizationId
286
- }
287
- });
288
256
  mockApi({
289
257
  apiVersion: USER_APPLICATIONS_API_VERSION,
290
258
  query: {
@@ -325,6 +293,13 @@ describe('#deploy', ()=>{
325
293
  const { error, stdout } = await testCommand(DeployCommand, [], {
326
294
  config: {
327
295
  root: cwd
296
+ },
297
+ mocks: {
298
+ cliConfig: {
299
+ app: {
300
+ organizationId
301
+ }
302
+ }
328
303
  }
329
304
  });
330
305
  expect(error).toBeUndefined();
@@ -341,16 +316,7 @@ describe('#deploy', ()=>{
341
316
  const cwd = await testExample('basic-app');
342
317
  process.cwd = ()=>cwd;
343
318
  const existingAppId = 'existing-app-id';
344
- const organizationId = 'org-id';
345
319
  const deploymentId = 'deployment-id';
346
- mockGetCliConfig.mockResolvedValue({
347
- app: {
348
- organizationId
349
- },
350
- deployment: {
351
- appId: existingAppId
352
- }
353
- });
354
320
  mockApi({
355
321
  apiVersion: USER_APPLICATIONS_API_VERSION,
356
322
  query: {
@@ -383,6 +349,14 @@ describe('#deploy', ()=>{
383
349
  ], {
384
350
  config: {
385
351
  root: cwd
352
+ },
353
+ mocks: {
354
+ cliConfig: {
355
+ ...defaultMocks.cliConfig,
356
+ deployment: {
357
+ appId: existingAppId
358
+ }
359
+ }
386
360
  }
387
361
  });
388
362
  expect(error).toBeUndefined();
@@ -393,16 +367,7 @@ describe('#deploy', ()=>{
393
367
  const cwd = await testExample('basic-app');
394
368
  process.cwd = ()=>cwd;
395
369
  const existingAppId = 'existing-app-id';
396
- const organizationId = 'org-id';
397
370
  mockCheckDir.mockRejectedValue(new Error('Directory check failed'));
398
- mockGetCliConfig.mockResolvedValue({
399
- app: {
400
- organizationId
401
- },
402
- deployment: {
403
- appId: existingAppId
404
- }
405
- });
406
371
  mockApi({
407
372
  apiVersion: USER_APPLICATIONS_API_VERSION,
408
373
  query: {
@@ -425,30 +390,31 @@ describe('#deploy', ()=>{
425
390
  ], {
426
391
  config: {
427
392
  root: cwd
393
+ },
394
+ mocks: {
395
+ cliConfig: {
396
+ ...defaultMocks.cliConfig,
397
+ deployment: {
398
+ appId: existingAppId
399
+ }
400
+ }
428
401
  }
429
402
  });
430
403
  expect(error?.message).toContain('Error checking directory');
404
+ expect(error?.oclif?.exit).toBe(1);
431
405
  });
432
- test('should error when fetching user applications if user doesnt have org access', async ()=>{
406
+ test("should error when fetching user applications if user doesn't have org access", async ()=>{
433
407
  const cwd = await testExample('basic-app');
434
408
  process.cwd = ()=>cwd;
435
- const appId = 'some-app-id';
436
- const organizationId = 'org-without-access';
437
- mockGetCliConfig.mockResolvedValue({
438
- app: {
439
- organizationId
440
- },
441
- deployment: {
442
- appId
443
- }
444
- });
409
+ const anotherAppId = 'some-app-id';
410
+ const anotherOrganizationId = 'org-without-access';
445
411
  // Simulate API returning 403 Forbidden for the given org
446
412
  mockApi({
447
413
  apiVersion: USER_APPLICATIONS_API_VERSION,
448
414
  query: {
449
415
  appType: 'coreApp'
450
416
  },
451
- uri: `/user-applications/${appId}`
417
+ uri: `/user-applications/${anotherAppId}`
452
418
  }).reply(403, {
453
419
  error: 'Forbidden'
454
420
  });
@@ -457,23 +423,25 @@ describe('#deploy', ()=>{
457
423
  ], {
458
424
  config: {
459
425
  root: cwd
426
+ },
427
+ mocks: {
428
+ cliConfig: {
429
+ app: {
430
+ organizationId: anotherOrganizationId
431
+ },
432
+ deployment: {
433
+ appId: anotherAppId
434
+ }
435
+ }
460
436
  }
461
437
  });
462
- expect(error?.message).toContain(`You don’t have permission to view applications for the configured organization ID ("${organizationId}")`);
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);
463
440
  });
464
441
  test('should handle user-applications endpoint errors', async ()=>{
465
442
  const cwd = await testExample('basic-app');
466
443
  process.cwd = ()=>cwd;
467
444
  const existingAppId = 'existing-app-id';
468
- const organizationId = 'org-id';
469
- mockGetCliConfig.mockResolvedValue({
470
- app: {
471
- organizationId
472
- },
473
- deployment: {
474
- appId: existingAppId
475
- }
476
- });
477
445
  mockApi({
478
446
  apiVersion: USER_APPLICATIONS_API_VERSION,
479
447
  query: {
@@ -488,23 +456,23 @@ describe('#deploy', ()=>{
488
456
  ], {
489
457
  config: {
490
458
  root: cwd
459
+ },
460
+ mocks: {
461
+ cliConfig: {
462
+ ...defaultMocks.cliConfig,
463
+ deployment: {
464
+ appId: existingAppId
465
+ }
466
+ }
491
467
  }
492
468
  });
493
469
  expect(error?.message).toContain('Error deploying application');
470
+ expect(error?.oclif?.exit).toBe(1);
494
471
  });
495
472
  test('should handle deployment API errors', async ()=>{
496
473
  const cwd = await testExample('basic-app');
497
474
  process.cwd = ()=>cwd;
498
475
  const existingAppId = 'existing-app-id';
499
- const organizationId = 'org-id';
500
- mockGetCliConfig.mockResolvedValue({
501
- app: {
502
- organizationId
503
- },
504
- deployment: {
505
- appId: existingAppId
506
- }
507
- });
508
476
  mockApi({
509
477
  apiVersion: USER_APPLICATIONS_API_VERSION,
510
478
  query: {
@@ -537,23 +505,23 @@ describe('#deploy', ()=>{
537
505
  ], {
538
506
  config: {
539
507
  root: cwd
508
+ },
509
+ mocks: {
510
+ cliConfig: {
511
+ ...defaultMocks.cliConfig,
512
+ deployment: {
513
+ appId: existingAppId
514
+ }
515
+ }
540
516
  }
541
517
  });
542
518
  expect(error?.message).toContain('Error deploying application');
519
+ expect(error?.oclif?.exit).toBe(1);
543
520
  });
544
521
  test('should show an error if deployment.appId is configured but the application does not exist', async ()=>{
545
522
  const cwd = await testExample('basic-app');
546
523
  process.cwd = ()=>cwd;
547
524
  const nonExistentAppId = 'non-existent-app-id';
548
- const organizationId = 'org-id';
549
- mockGetCliConfig.mockResolvedValue({
550
- app: {
551
- organizationId
552
- },
553
- deployment: {
554
- appId: nonExistentAppId
555
- }
556
- });
557
525
  // Simulate API returning no user application for the given app.id
558
526
  mockApi({
559
527
  apiVersion: USER_APPLICATIONS_API_VERSION,
@@ -569,49 +537,57 @@ describe('#deploy', ()=>{
569
537
  ], {
570
538
  config: {
571
539
  root: cwd
540
+ },
541
+ mocks: {
542
+ cliConfig: {
543
+ ...defaultMocks.cliConfig,
544
+ deployment: {
545
+ appId: nonExistentAppId
546
+ }
547
+ }
572
548
  }
573
549
  });
574
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);
575
552
  });
576
553
  test('should show an error if deployment.appId and app.id (deprecated) are both in use', async ()=>{
577
554
  const cwd = await testExample('basic-app');
578
555
  process.cwd = ()=>cwd;
579
- const appId = 'app-id';
580
- const organizationId = 'org-id';
581
- mockGetCliConfig.mockResolvedValue({
582
- app: {
583
- id: appId,
584
- organizationId
585
- },
586
- deployment: {
587
- appId: appId
588
- }
589
- });
590
556
  const { error } = await testCommand(DeployCommand, [
591
557
  '--no-build'
592
558
  ], {
593
559
  config: {
594
560
  root: cwd
561
+ },
562
+ mocks: {
563
+ cliConfig: {
564
+ ...defaultMocks.cliConfig,
565
+ app: {
566
+ id: appId,
567
+ organizationId
568
+ }
569
+ }
595
570
  }
596
571
  });
597
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);
598
574
  });
599
575
  test('should show a warning if app.id (deprecated) is used', async ()=>{
600
576
  const cwd = await testExample('basic-app');
601
577
  process.cwd = ()=>cwd;
602
- const appId = 'app-id';
603
- const organizationId = 'org-id';
604
- mockGetCliConfig.mockResolvedValue({
605
- app: {
606
- id: appId,
607
- organizationId
608
- }
609
- });
610
578
  const { stderr } = await testCommand(DeployCommand, [
611
579
  '--no-build'
612
580
  ], {
613
581
  config: {
614
582
  root: cwd
583
+ },
584
+ mocks: {
585
+ cliConfig: {
586
+ app: {
587
+ id: appId,
588
+ organizationId
589
+ }
590
+ }
615
591
  }
616
592
  });
617
593
  expect(stderr).toContain('The `app.id` config has moved to `deployment.appId`.');
@@ -619,15 +595,9 @@ describe('#deploy', ()=>{
619
595
  test('should handle app creation with retry when host is taken', async ()=>{
620
596
  const cwd = await testExample('basic-app');
621
597
  process.cwd = ()=>cwd;
622
- const organizationId = 'org-id';
623
598
  const newAppId = 'new-app-id';
624
599
  const deploymentId = 'deployment-id';
625
600
  mockInput.mockResolvedValue('Test App');
626
- mockGetCliConfig.mockResolvedValue({
627
- app: {
628
- organizationId
629
- }
630
- });
631
601
  mockApi({
632
602
  apiVersion: USER_APPLICATIONS_API_VERSION,
633
603
  query: {
@@ -680,6 +650,13 @@ describe('#deploy', ()=>{
680
650
  const { error, stdout } = await testCommand(DeployCommand, [], {
681
651
  config: {
682
652
  root: cwd
653
+ },
654
+ mocks: {
655
+ cliConfig: {
656
+ app: {
657
+ organizationId
658
+ }
659
+ }
683
660
  }
684
661
  });
685
662
  expect(error).toBeUndefined();
@@ -688,13 +665,7 @@ describe('#deploy', ()=>{
688
665
  test('should handle app creation failure with non-retryable error', async ()=>{
689
666
  const cwd = await testExample('basic-app');
690
667
  process.cwd = ()=>cwd;
691
- const organizationId = 'org-id';
692
668
  mockInput.mockResolvedValue('Test App');
693
- mockGetCliConfig.mockResolvedValue({
694
- app: {
695
- organizationId
696
- }
697
- });
698
669
  mockApi({
699
670
  apiVersion: USER_APPLICATIONS_API_VERSION,
700
671
  query: {
@@ -718,6 +689,13 @@ describe('#deploy', ()=>{
718
689
  const { error } = await testCommand(DeployCommand, [], {
719
690
  config: {
720
691
  root: cwd
692
+ },
693
+ mocks: {
694
+ cliConfig: {
695
+ app: {
696
+ organizationId
697
+ }
698
+ }
721
699
  }
722
700
  });
723
701
  expect(error?.message).toContain('Error deploying application');
@@ -726,15 +704,6 @@ describe('#deploy', ()=>{
726
704
  const cwd = await testExample('basic-app');
727
705
  process.cwd = ()=>cwd;
728
706
  const existingAppId = 'existing-app-id';
729
- const organizationId = 'org-id';
730
- mockGetCliConfig.mockResolvedValue({
731
- app: {
732
- organizationId
733
- },
734
- deployment: {
735
- appId: existingAppId
736
- }
737
- });
738
707
  mockApi({
739
708
  apiVersion: USER_APPLICATIONS_API_VERSION,
740
709
  query: {
@@ -749,6 +718,14 @@ describe('#deploy', ()=>{
749
718
  ], {
750
719
  config: {
751
720
  root: cwd
721
+ },
722
+ mocks: {
723
+ cliConfig: {
724
+ ...defaultMocks.cliConfig,
725
+ deployment: {
726
+ appId: existingAppId
727
+ }
728
+ }
752
729
  }
753
730
  });
754
731
  expect(error?.message).toContain('Error deploying application');
@@ -757,15 +734,9 @@ describe('#deploy', ()=>{
757
734
  test('should test input validation for app title', async ()=>{
758
735
  const cwd = await testExample('basic-app');
759
736
  process.cwd = ()=>cwd;
760
- const organizationId = 'org-id';
761
737
  const newAppId = 'new-app-id';
762
738
  const deploymentId = 'deployment-id';
763
739
  mockInput.mockResolvedValue('Valid App Title');
764
- mockGetCliConfig.mockResolvedValue({
765
- app: {
766
- organizationId
767
- }
768
- });
769
740
  mockApi({
770
741
  apiVersion: USER_APPLICATIONS_API_VERSION,
771
742
  query: {
@@ -806,6 +777,13 @@ describe('#deploy', ()=>{
806
777
  const { error } = await testCommand(DeployCommand, [], {
807
778
  config: {
808
779
  root: cwd
780
+ },
781
+ mocks: {
782
+ cliConfig: {
783
+ app: {
784
+ organizationId
785
+ }
786
+ }
809
787
  }
810
788
  });
811
789
  expect(error).toBeUndefined();
@@ -817,15 +795,9 @@ describe('#deploy', ()=>{
817
795
  test('should allow selecting from list of apps', async ()=>{
818
796
  const cwd = await testExample('basic-app');
819
797
  process.cwd = ()=>cwd;
820
- const organizationId = 'org-id';
821
798
  const existingAppId1 = 'existing-app-id-1';
822
799
  const existingAppId2 = 'existing-app-id-2';
823
800
  const deploymentId = 'deployment-id';
824
- mockGetCliConfig.mockResolvedValue({
825
- app: {
826
- organizationId
827
- }
828
- });
829
801
  mockApi({
830
802
  apiVersion: USER_APPLICATIONS_API_VERSION,
831
803
  query: {
@@ -871,6 +843,13 @@ describe('#deploy', ()=>{
871
843
  const { error, stdout } = await testCommand(DeployCommand, [], {
872
844
  config: {
873
845
  root: cwd
846
+ },
847
+ mocks: {
848
+ cliConfig: {
849
+ app: {
850
+ organizationId
851
+ }
852
+ }
874
853
  }
875
854
  });
876
855
  expect(error).toBeUndefined();
@@ -882,16 +861,10 @@ describe('#deploy', ()=>{
882
861
  test('should allow creating a new app by selecting from list of apps', async ()=>{
883
862
  const cwd = await testExample('basic-app');
884
863
  process.cwd = ()=>cwd;
885
- const organizationId = 'org-id';
886
864
  const existingAppId1 = 'existing-app-id-1';
887
865
  const existingAppId2 = 'existing-app-id-2';
888
866
  const newAppId = 'new-app-id';
889
867
  const deploymentId = 'deployment-id';
890
- mockGetCliConfig.mockResolvedValue({
891
- app: {
892
- organizationId
893
- }
894
- });
895
868
  mockApi({
896
869
  apiVersion: USER_APPLICATIONS_API_VERSION,
897
870
  query: {
@@ -956,6 +929,13 @@ describe('#deploy', ()=>{
956
929
  const { error, stdout } = await testCommand(DeployCommand, [], {
957
930
  config: {
958
931
  root: cwd
932
+ },
933
+ mocks: {
934
+ cliConfig: {
935
+ app: {
936
+ organizationId
937
+ }
938
+ }
959
939
  }
960
940
  });
961
941
  expect(error).toBeUndefined();
@@ -967,14 +947,16 @@ describe('#deploy', ()=>{
967
947
  test('should throw an error if organizationId is not set', async ()=>{
968
948
  const cwd = await testExample('basic-app');
969
949
  process.cwd = ()=>cwd;
970
- mockGetCliConfig.mockResolvedValue({
971
- app: {
972
- organizationId: undefined
973
- }
974
- });
975
950
  const { error } = await testCommand(DeployCommand, [], {
976
951
  config: {
977
952
  root: cwd
953
+ },
954
+ mocks: {
955
+ cliConfig: {
956
+ app: {
957
+ organizationId: undefined
958
+ }
959
+ }
978
960
  }
979
961
  });
980
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');
@@ -986,12 +968,14 @@ describe('#deploy', ()=>{
986
968
  const cwd = await testExample('basic-studio');
987
969
  process.cwd = ()=>cwd;
988
970
  mockReadModuleVersion.mockResolvedValue(null);
989
- mockGetCliConfig.mockResolvedValue({
990
- studioHost: 'existing-studio'
991
- });
992
971
  const { error } = await testCommand(DeployCommand, [], {
993
972
  config: {
994
973
  root: cwd
974
+ },
975
+ mocks: {
976
+ cliConfig: {
977
+ studioHost: 'existing-studio'
978
+ }
995
979
  }
996
980
  });
997
981
  expect(error?.message).toContain('Failed to find installed sanity version');
@@ -1003,12 +987,6 @@ describe('#deploy', ()=>{
1003
987
  const studioHost = 'existing-studio';
1004
988
  const studioAppId = 'studio-app-id';
1005
989
  mockCheckDir.mockRejectedValue(new Error('Directory check failed'));
1006
- mockGetCliConfig.mockResolvedValue({
1007
- api: {
1008
- projectId
1009
- },
1010
- studioHost
1011
- });
1012
990
  mockApi({
1013
991
  apiVersion: USER_APPLICATIONS_API_VERSION,
1014
992
  query: {
@@ -1031,6 +1009,14 @@ describe('#deploy', ()=>{
1031
1009
  ], {
1032
1010
  config: {
1033
1011
  root: cwd
1012
+ },
1013
+ mocks: {
1014
+ cliConfig: {
1015
+ api: {
1016
+ projectId
1017
+ },
1018
+ studioHost
1019
+ }
1034
1020
  }
1035
1021
  });
1036
1022
  expect(error?.message).toContain('Error checking directory');
@@ -1042,12 +1028,6 @@ describe('#deploy', ()=>{
1042
1028
  const studioHost = 'existing-studio';
1043
1029
  const studioAppId = 'studio-app-id';
1044
1030
  const deploymentId = 'deployment-id';
1045
- mockGetCliConfig.mockResolvedValue({
1046
- api: {
1047
- projectId
1048
- },
1049
- studioHost
1050
- });
1051
1031
  mockApi({
1052
1032
  apiVersion: USER_APPLICATIONS_API_VERSION,
1053
1033
  query: {
@@ -1078,6 +1058,14 @@ describe('#deploy', ()=>{
1078
1058
  const { error, stderr, stdout } = await testCommand(DeployCommand, [], {
1079
1059
  config: {
1080
1060
  root: cwd
1061
+ },
1062
+ mocks: {
1063
+ cliConfig: {
1064
+ api: {
1065
+ projectId
1066
+ },
1067
+ studioHost
1068
+ }
1081
1069
  }
1082
1070
  });
1083
1071
  expect(error).toBeUndefined();
@@ -1089,12 +1077,6 @@ describe('#deploy', ()=>{
1089
1077
  test('should create new studio hostname when studioHost is provided but does not exist', async ()=>{
1090
1078
  const cwd = await testExample('basic-studio');
1091
1079
  process.cwd = ()=>cwd;
1092
- mockGetCliConfig.mockResolvedValue({
1093
- api: {
1094
- projectId: 'test-project-id'
1095
- },
1096
- studioHost: 'new-studio-host'
1097
- });
1098
1080
  mockApi({
1099
1081
  apiVersion: USER_APPLICATIONS_API_VERSION,
1100
1082
  query: {
@@ -1135,6 +1117,14 @@ describe('#deploy', ()=>{
1135
1117
  const { error, stdout } = await testCommand(DeployCommand, [], {
1136
1118
  config: {
1137
1119
  root: cwd
1120
+ },
1121
+ mocks: {
1122
+ cliConfig: {
1123
+ api: {
1124
+ projectId: 'test-project-id'
1125
+ },
1126
+ studioHost: 'new-studio-host'
1127
+ }
1138
1128
  }
1139
1129
  });
1140
1130
  expect(error).toBeUndefined();
@@ -1147,12 +1137,6 @@ describe('#deploy', ()=>{
1147
1137
  process.cwd = ()=>cwd;
1148
1138
  const projectId = 'test-project-id';
1149
1139
  const studioHost = 'taken-studio-host';
1150
- mockGetCliConfig.mockResolvedValue({
1151
- api: {
1152
- projectId
1153
- },
1154
- studioHost
1155
- });
1156
1140
  mockApi({
1157
1141
  apiVersion: USER_APPLICATIONS_API_VERSION,
1158
1142
  query: {
@@ -1177,6 +1161,14 @@ describe('#deploy', ()=>{
1177
1161
  const { error } = await testCommand(DeployCommand, [], {
1178
1162
  config: {
1179
1163
  root: cwd
1164
+ },
1165
+ mocks: {
1166
+ cliConfig: {
1167
+ api: {
1168
+ projectId
1169
+ },
1170
+ studioHost
1171
+ }
1180
1172
  }
1181
1173
  });
1182
1174
  expect(error?.message).toContain('Studio hostname already taken');
@@ -1186,11 +1178,6 @@ describe('#deploy', ()=>{
1186
1178
  const cwd = await testExample('basic-studio');
1187
1179
  process.cwd = ()=>cwd;
1188
1180
  const projectId = 'test-project-id';
1189
- mockGetCliConfig.mockResolvedValue({
1190
- api: {
1191
- projectId
1192
- }
1193
- });
1194
1181
  const studioOneId = 'studio-one-id';
1195
1182
  const studioTwoId = 'studio-two-id';
1196
1183
  const deploymentId = 'deployment-id';
@@ -1237,6 +1224,13 @@ describe('#deploy', ()=>{
1237
1224
  const { error, stdout } = await testCommand(DeployCommand, [], {
1238
1225
  config: {
1239
1226
  root: cwd
1227
+ },
1228
+ mocks: {
1229
+ cliConfig: {
1230
+ api: {
1231
+ projectId
1232
+ }
1233
+ }
1240
1234
  }
1241
1235
  });
1242
1236
  expect(error).toBeUndefined();
@@ -1267,11 +1261,6 @@ describe('#deploy', ()=>{
1267
1261
  const existingStudioId = 'existing-studio-id';
1268
1262
  const newStudioFromMenuId = 'new-studio-from-menu-id';
1269
1263
  const deploymentId = 'deployment-id';
1270
- mockGetCliConfig.mockResolvedValue({
1271
- api: {
1272
- projectId
1273
- }
1274
- });
1275
1264
  mockApi({
1276
1265
  apiVersion: USER_APPLICATIONS_API_VERSION,
1277
1266
  query: {
@@ -1331,6 +1320,13 @@ describe('#deploy', ()=>{
1331
1320
  const { error, stdout } = await testCommand(DeployCommand, [], {
1332
1321
  config: {
1333
1322
  root: cwd
1323
+ },
1324
+ mocks: {
1325
+ cliConfig: {
1326
+ api: {
1327
+ projectId
1328
+ }
1329
+ }
1334
1330
  }
1335
1331
  });
1336
1332
  expect(error).toBeUndefined();
@@ -1361,11 +1357,6 @@ describe('#deploy', ()=>{
1361
1357
  promise.cancel = ()=>{};
1362
1358
  return promise;
1363
1359
  });
1364
- mockGetCliConfig.mockResolvedValue({
1365
- api: {
1366
- projectId
1367
- }
1368
- });
1369
1360
  mockApi({
1370
1361
  apiVersion: USER_APPLICATIONS_API_VERSION,
1371
1362
  query: {
@@ -1416,6 +1407,13 @@ describe('#deploy', ()=>{
1416
1407
  const { error, stdout } = await testCommand(DeployCommand, [], {
1417
1408
  config: {
1418
1409
  root: cwd
1410
+ },
1411
+ mocks: {
1412
+ cliConfig: {
1413
+ api: {
1414
+ projectId
1415
+ }
1416
+ }
1419
1417
  }
1420
1418
  });
1421
1419
  expect(error).toBeUndefined();
@@ -1440,11 +1438,6 @@ describe('#deploy', ()=>{
1440
1438
  promise.cancel = ()=>{};
1441
1439
  return promise;
1442
1440
  });
1443
- mockGetCliConfig.mockResolvedValue({
1444
- api: {
1445
- projectId
1446
- }
1447
- });
1448
1441
  mockApi({
1449
1442
  apiVersion: USER_APPLICATIONS_API_VERSION,
1450
1443
  query: {
@@ -1467,6 +1460,13 @@ describe('#deploy', ()=>{
1467
1460
  const { error } = await testCommand(DeployCommand, [], {
1468
1461
  config: {
1469
1462
  root: cwd
1463
+ },
1464
+ mocks: {
1465
+ cliConfig: {
1466
+ api: {
1467
+ projectId
1468
+ }
1469
+ }
1470
1470
  }
1471
1471
  });
1472
1472
  expect(error?.message).toContain('Error creating user application');
@@ -1475,13 +1475,15 @@ describe('#deploy', ()=>{
1475
1475
  test('should throw error when no projectId is configured', async ()=>{
1476
1476
  const cwd = await testExample('basic-studio');
1477
1477
  process.cwd = ()=>cwd;
1478
- mockGetCliConfig.mockResolvedValue({
1479
- api: {},
1480
- studioHost: 'some-studio'
1481
- });
1482
1478
  const { error } = await testCommand(DeployCommand, [], {
1483
1479
  config: {
1484
1480
  root: cwd
1481
+ },
1482
+ mocks: {
1483
+ cliConfig: {
1484
+ api: {},
1485
+ studioHost: 'some-studio'
1486
+ }
1485
1487
  }
1486
1488
  });
1487
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,11 +1492,21 @@ describe('#deploy', ()=>{
1490
1492
  test('should log a warning if the deprecated auto-updates flag is used', async ()=>{
1491
1493
  const cwd = await testExample('basic-studio');
1492
1494
  process.cwd = ()=>cwd;
1495
+ const projectId = 'test-project-id';
1496
+ const studioHost = 'test-studio';
1493
1497
  const { stderr } = await testCommand(DeployCommand, [
1494
1498
  '--auto-updates'
1495
1499
  ], {
1496
1500
  config: {
1497
1501
  root: cwd
1502
+ },
1503
+ mocks: {
1504
+ cliConfig: {
1505
+ api: {
1506
+ projectId
1507
+ },
1508
+ studioHost
1509
+ }
1498
1510
  }
1499
1511
  });
1500
1512
  expect(stderr).toContain('Warning: The --auto-updates flag is deprecated');
@@ -1502,15 +1514,17 @@ describe('#deploy', ()=>{
1502
1514
  test('should throw an error when both the current and deprecated autoUpdates config are used', async ()=>{
1503
1515
  const cwd = await testExample('basic-studio');
1504
1516
  process.cwd = ()=>cwd;
1505
- mockGetCliConfig.mockResolvedValue({
1506
- autoUpdates: true,
1507
- deployment: {
1508
- autoUpdates: true
1509
- }
1510
- });
1511
1517
  const { error } = await testCommand(DeployCommand, [], {
1512
1518
  config: {
1513
1519
  root: cwd
1520
+ },
1521
+ mocks: {
1522
+ cliConfig: {
1523
+ autoUpdates: true,
1524
+ deployment: {
1525
+ autoUpdates: true
1526
+ }
1527
+ }
1514
1528
  }
1515
1529
  });
1516
1530
  expect(error?.message).toContain('Found both `autoUpdates` (deprecated) and `deployment.autoUpdates` in sanity.cli.');
@@ -1521,12 +1535,6 @@ describe('#deploy', ()=>{
1521
1535
  process.cwd = ()=>cwd;
1522
1536
  const projectId = 'test-project-id';
1523
1537
  const studioHost = 'existing-studio';
1524
- mockGetCliConfig.mockResolvedValue({
1525
- api: {
1526
- projectId
1527
- },
1528
- studioHost
1529
- });
1530
1538
  mockApi({
1531
1539
  apiVersion: USER_APPLICATIONS_API_VERSION,
1532
1540
  query: {
@@ -1540,6 +1548,14 @@ describe('#deploy', ()=>{
1540
1548
  const { error } = await testCommand(DeployCommand, [], {
1541
1549
  config: {
1542
1550
  root: cwd
1551
+ },
1552
+ mocks: {
1553
+ cliConfig: {
1554
+ api: {
1555
+ projectId
1556
+ },
1557
+ studioHost
1558
+ }
1543
1559
  }
1544
1560
  });
1545
1561
  expect(error?.message).toContain('Error finding user application');
@@ -1551,12 +1567,6 @@ describe('#deploy', ()=>{
1551
1567
  const projectId = 'test-project-id';
1552
1568
  const studioHost = 'existing-studio';
1553
1569
  const studioAppId = 'studio-app-id';
1554
- mockGetCliConfig.mockResolvedValue({
1555
- api: {
1556
- projectId
1557
- },
1558
- studioHost
1559
- });
1560
1570
  mockApi({
1561
1571
  apiVersion: USER_APPLICATIONS_API_VERSION,
1562
1572
  query: {
@@ -1587,6 +1597,14 @@ describe('#deploy', ()=>{
1587
1597
  const { error } = await testCommand(DeployCommand, [], {
1588
1598
  config: {
1589
1599
  root: cwd
1600
+ },
1601
+ mocks: {
1602
+ cliConfig: {
1603
+ api: {
1604
+ projectId
1605
+ },
1606
+ studioHost
1607
+ }
1590
1608
  }
1591
1609
  });
1592
1610
  expect(error?.message).toContain('Error deploying studio');
@@ -1597,12 +1615,6 @@ describe('#deploy', ()=>{
1597
1615
  process.cwd = ()=>cwd;
1598
1616
  const projectId = 'test-project-id';
1599
1617
  const studioHost = 'new-studio-host';
1600
- mockGetCliConfig.mockResolvedValue({
1601
- api: {
1602
- projectId
1603
- },
1604
- studioHost
1605
- });
1606
1618
  mockApi({
1607
1619
  apiVersion: USER_APPLICATIONS_API_VERSION,
1608
1620
  query: {
@@ -1627,6 +1639,14 @@ describe('#deploy', ()=>{
1627
1639
  const { error } = await testCommand(DeployCommand, [], {
1628
1640
  config: {
1629
1641
  root: cwd
1642
+ },
1643
+ mocks: {
1644
+ cliConfig: {
1645
+ api: {
1646
+ projectId
1647
+ },
1648
+ studioHost
1649
+ }
1630
1650
  }
1631
1651
  });
1632
1652
  expect(error?.message).toContain('Error creating user application from config');
@@ -1648,11 +1668,6 @@ describe('#deploy', ()=>{
1648
1668
  promise.cancel = ()=>{};
1649
1669
  return promise;
1650
1670
  });
1651
- mockGetCliConfig.mockResolvedValue({
1652
- api: {
1653
- projectId
1654
- }
1655
- });
1656
1671
  mockApi({
1657
1672
  apiVersion: USER_APPLICATIONS_API_VERSION,
1658
1673
  query: {
@@ -1690,6 +1705,13 @@ describe('#deploy', ()=>{
1690
1705
  const { error, stdout } = await testCommand(DeployCommand, [], {
1691
1706
  config: {
1692
1707
  root: cwd
1708
+ },
1709
+ mocks: {
1710
+ cliConfig: {
1711
+ api: {
1712
+ projectId
1713
+ }
1714
+ }
1693
1715
  }
1694
1716
  });
1695
1717
  expect(error).toBeUndefined();
@@ -1706,12 +1728,6 @@ describe('#deploy', ()=>{
1706
1728
  const studioHost = 'existing-studio';
1707
1729
  const studioAppId = 'studio-app-id';
1708
1730
  const deploymentId = 'deployment-id';
1709
- mockGetCliConfig.mockResolvedValue({
1710
- api: {
1711
- projectId
1712
- },
1713
- studioHost
1714
- });
1715
1731
  mockApi({
1716
1732
  apiVersion: USER_APPLICATIONS_API_VERSION,
1717
1733
  query: {
@@ -1744,6 +1760,14 @@ describe('#deploy', ()=>{
1744
1760
  ], {
1745
1761
  config: {
1746
1762
  root: cwd
1763
+ },
1764
+ mocks: {
1765
+ cliConfig: {
1766
+ api: {
1767
+ projectId
1768
+ },
1769
+ studioHost
1770
+ }
1747
1771
  }
1748
1772
  });
1749
1773
  expect(error).toBeUndefined();
@@ -1757,14 +1781,6 @@ describe('#deploy', ()=>{
1757
1781
  const studioAppId = 'studio-app-id';
1758
1782
  const appHost = 'my-studio';
1759
1783
  const deploymentId = 'deployment-id';
1760
- mockGetCliConfig.mockResolvedValue({
1761
- api: {
1762
- projectId
1763
- },
1764
- deployment: {
1765
- appId: studioAppId
1766
- }
1767
- });
1768
1784
  mockApi({
1769
1785
  apiVersion: USER_APPLICATIONS_API_VERSION,
1770
1786
  uri: `/projects/${projectId}/user-applications/${studioAppId}`
@@ -1792,6 +1808,16 @@ describe('#deploy', ()=>{
1792
1808
  const { error, stdout } = await testCommand(DeployCommand, [], {
1793
1809
  config: {
1794
1810
  root: cwd
1811
+ },
1812
+ mocks: {
1813
+ cliConfig: {
1814
+ api: {
1815
+ projectId
1816
+ },
1817
+ deployment: {
1818
+ appId: studioAppId
1819
+ }
1820
+ }
1795
1821
  }
1796
1822
  });
1797
1823
  expect(error).toBeUndefined();
@@ -1804,15 +1830,6 @@ describe('#deploy', ()=>{
1804
1830
  const studioAppId = 'studio-app-id';
1805
1831
  const studioHost = 'my-studio-host';
1806
1832
  const deploymentId = 'deployment-id';
1807
- mockGetCliConfig.mockResolvedValue({
1808
- api: {
1809
- projectId
1810
- },
1811
- deployment: {
1812
- appId: studioAppId
1813
- },
1814
- studioHost
1815
- });
1816
1833
  // Should call by appId, NOT by appHost
1817
1834
  mockApi({
1818
1835
  apiVersion: USER_APPLICATIONS_API_VERSION,
@@ -1841,6 +1858,17 @@ describe('#deploy', ()=>{
1841
1858
  const { error, stdout } = await testCommand(DeployCommand, [], {
1842
1859
  config: {
1843
1860
  root: cwd
1861
+ },
1862
+ mocks: {
1863
+ cliConfig: {
1864
+ api: {
1865
+ projectId
1866
+ },
1867
+ deployment: {
1868
+ appId: studioAppId
1869
+ },
1870
+ studioHost
1871
+ }
1844
1872
  }
1845
1873
  });
1846
1874
  expect(error).toBeUndefined();
@@ -1851,14 +1879,6 @@ describe('#deploy', ()=>{
1851
1879
  process.cwd = ()=>cwd;
1852
1880
  const projectId = 'test-project-id';
1853
1881
  const studioAppId = 'non-existent-app-id';
1854
- mockGetCliConfig.mockResolvedValue({
1855
- api: {
1856
- projectId
1857
- },
1858
- deployment: {
1859
- appId: studioAppId
1860
- }
1861
- });
1862
1882
  mockApi({
1863
1883
  apiVersion: USER_APPLICATIONS_API_VERSION,
1864
1884
  uri: `/projects/${projectId}/user-applications/${studioAppId}`
@@ -1868,6 +1888,16 @@ describe('#deploy', ()=>{
1868
1888
  const { error } = await testCommand(DeployCommand, [], {
1869
1889
  config: {
1870
1890
  root: cwd
1891
+ },
1892
+ mocks: {
1893
+ cliConfig: {
1894
+ api: {
1895
+ projectId
1896
+ },
1897
+ deployment: {
1898
+ appId: studioAppId
1899
+ }
1900
+ }
1871
1901
  }
1872
1902
  });
1873
1903
  expect(error?.message).toContain('Error finding user application');
@@ -1880,15 +1910,6 @@ describe('#deploy', ()=>{
1880
1910
  const projectId = 'test-project-id';
1881
1911
  const studioAppId = 'non-existent-app-id';
1882
1912
  const studioHost = 'valid-studio-host';
1883
- mockGetCliConfig.mockResolvedValue({
1884
- api: {
1885
- projectId
1886
- },
1887
- deployment: {
1888
- appId: studioAppId
1889
- },
1890
- studioHost
1891
- });
1892
1913
  // appId lookup fails
1893
1914
  mockApi({
1894
1915
  apiVersion: USER_APPLICATIONS_API_VERSION,
@@ -1901,6 +1922,17 @@ describe('#deploy', ()=>{
1901
1922
  const { error } = await testCommand(DeployCommand, [], {
1902
1923
  config: {
1903
1924
  root: cwd
1925
+ },
1926
+ mocks: {
1927
+ cliConfig: {
1928
+ api: {
1929
+ projectId
1930
+ },
1931
+ deployment: {
1932
+ appId: studioAppId
1933
+ },
1934
+ studioHost
1935
+ }
1904
1936
  }
1905
1937
  });
1906
1938
  expect(error?.message).toContain('Error finding user application');