Skip to content

Commit ec01855

Browse files
committed
test(chore): move module URL tests to the right place
1 parent 1fcf46e commit ec01855

3 files changed

Lines changed: 33 additions & 47 deletions

File tree

packages/@sanity/cli-build/src/actions/build/__tests__/getAutoUpdatesImportMap.test.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import {describe, expect, test} from 'vitest'
22

3-
import {getAutoUpdatesCssUrls, getAutoUpdatesImportMap} from '../getAutoUpdatesImportMap.js'
3+
import {
4+
getAutoUpdatesCssUrls,
5+
getAutoUpdatesImportMap,
6+
getModuleUrl,
7+
} from '../getAutoUpdatesImportMap.js'
48

59
describe('getAutoUpdateImportMap() without app id', () => {
610
test('works with sanity package', () => {
@@ -151,3 +155,24 @@ describe('getAutoUpdatesCssUrls() with app id', () => {
151155
])
152156
})
153157
})
158+
159+
describe('getModuleUrl', () => {
160+
test('should use the default module endpoint when no appId is provided', () => {
161+
const res = getModuleUrl({name: 'sanity', version: '3.40.0'})
162+
163+
expect(res).toContain('/v1/modules/sanity/default/')
164+
expect(res).not.toContain('/by-app/')
165+
})
166+
167+
test('should use the app-specific module endpoint when appId is provided', () => {
168+
const res = getModuleUrl(
169+
{name: 'sanity', version: '3.40.0'},
170+
{
171+
appId: 'my-app-id',
172+
},
173+
)
174+
175+
expect(res).toContain('/v1/modules/by-app/my-app-id/')
176+
expect(res).not.toContain('/default/')
177+
})
178+
})

packages/@sanity/cli/src/util/__tests__/compareDependencyVersions.test.ts

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import {compareDependencyVersions} from '../compareDependencyVersions'
55
const mockReadPackageJson = vi.hoisted(() => vi.fn())
66
const mockRequest = vi.hoisted(() => vi.fn())
77
const mockGetLocalPackageVersion = vi.hoisted(() => vi.fn())
8+
const mockGetModuleUrl = vi.hoisted(() => vi.fn())
89

910
vi.mock('@sanity/cli-core/util/getLocalPackageVersion', () => ({
1011
getLocalPackageVersion: mockGetLocalPackageVersion,
1112
}))
1213
vi.mock('@sanity/cli-core/util/readPackageJson', () => ({
1314
readPackageJson: mockReadPackageJson,
1415
}))
15-
// TODO: mock getModuleUrl
16+
vi.mock('@sanity/cli-build/_internal/actions/build/getAutoUpdatesImportMap', () => ({
17+
getAutoUpdatesCssUrls: vi.fn(),
18+
getAutoUpdatesImportMap: vi.fn(),
19+
getModuleUrl: mockGetModuleUrl,
20+
}))
1621

1722
const autoUpdatePackages = [
1823
{name: 'sanity', version: '1.0.0'},
@@ -465,50 +470,6 @@ describe('compareDependencyVersions', () => {
465470
})
466471
})
467472

468-
describe('module URL selection', () => {
469-
it('should use the default module endpoint when no appId is provided', async () => {
470-
mockRequest.mockResolvedValue({
471-
headers: {'x-resolved-version': '3.40.0'},
472-
statusCode: 302,
473-
})
474-
mockGetLocalPackageVersion.mockResolvedValue('3.40.0')
475-
mockReadPackageJson.mockResolvedValueOnce({
476-
dependencies: {sanity: '^3.40.0'},
477-
devDependencies: {},
478-
name: 'test-package',
479-
version: '0.0.0',
480-
})
481-
482-
await compare([{name: 'sanity', version: '3.40.0'}], '/test/workdir')
483-
484-
const url = mockRequest.mock.calls[0][0].url as string
485-
expect(url).toContain('/v1/modules/sanity/default/')
486-
expect(url).not.toContain('/by-app/')
487-
})
488-
489-
it('should use the app-specific module endpoint when appId is provided', async () => {
490-
mockRequest.mockResolvedValue({
491-
headers: {'x-resolved-version': '3.40.0'},
492-
statusCode: 302,
493-
})
494-
mockGetLocalPackageVersion.mockResolvedValue('3.40.0')
495-
mockReadPackageJson.mockResolvedValueOnce({
496-
dependencies: {sanity: '^3.40.0'},
497-
devDependencies: {},
498-
name: 'test-package',
499-
version: '0.0.0',
500-
})
501-
502-
await compare([{name: 'sanity', version: '3.40.0'}], '/test/workdir', {
503-
appId: 'my-app-id',
504-
})
505-
506-
const url = mockRequest.mock.calls[0][0].url as string
507-
expect(url).toContain('/v1/modules/by-app/my-app-id/')
508-
expect(url).not.toContain('/default/')
509-
})
510-
})
511-
512473
describe('prerelease version handling', () => {
513474
it('should return prerelease package in unresolvedPrerelease when remote returns 404', async () => {
514475
mockRequest.mockResolvedValue({

packages/@sanity/cli/src/util/compareDependencyVersions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22

3-
import {getModuleUrl} from '@sanity/cli-build/_internal/build'
3+
import {getModuleUrl} from '@sanity/cli-build/_internal/actions/build/getAutoUpdatesImportMap'
44
import {createRequester} from '@sanity/cli-core/request'
55
import {getLocalPackageVersion} from '@sanity/cli-core/util/getLocalPackageVersion'
66
import {readPackageJson} from '@sanity/cli-core/util/readPackageJson'

0 commit comments

Comments
 (0)