|
1 | | -import {configExtensionsIdentifiersBreakdown, extensionsIdentifiersDeployBreakdown} from './breakdown-extensions.js' |
| 1 | +import { |
| 2 | + buildExtensionBreakdownInfo, |
| 3 | + configExtensionsIdentifiersBreakdown, |
| 4 | + ExtensionIdentifierBreakdownInfo, |
| 5 | + extensionsIdentifiersDeployBreakdown, |
| 6 | +} from './breakdown-extensions.js' |
2 | 7 | import {ensureDeploymentIdsPresence} from './identifiers.js' |
3 | 8 | import {deployConfirmed} from './identifiers-extensions.js' |
4 | 9 | import {deployOrReleaseConfirmationPrompt} from '../../prompts/deploy-release.js' |
@@ -34,6 +39,152 @@ describe('ensureDeploymentIdsPresence', () => { |
34 | 39 | await expect(ensureDeploymentIdsPresence(params)).rejects.toThrow(AbortSilentError) |
35 | 40 | }) |
36 | 41 |
|
| 42 | + test('when there are remote-only extensions and not forced, appInstallCount is called with remoteApp.id', async () => { |
| 43 | + // Given |
| 44 | + const breakdown = buildExtensionsBreakdown() |
| 45 | + breakdown.extensionIdentifiersBreakdown.onlyRemote = [buildExtensionBreakdownInfo('removed', 'uuid-1')] |
| 46 | + vi.mocked(extensionsIdentifiersDeployBreakdown).mockResolvedValue(breakdown) |
| 47 | + vi.mocked(configExtensionsIdentifiersBreakdown).mockResolvedValue(buildConfigBreakdown()) |
| 48 | + vi.mocked(deployOrReleaseConfirmationPrompt).mockResolvedValue(false) |
| 49 | + |
| 50 | + const remoteApp = testOrganizationApp({id: 'real-app-id', apiKey: 'api-key-different'}) |
| 51 | + const client = testDeveloperPlatformClient({ |
| 52 | + appInstallCount: vi.fn().mockResolvedValue(42), |
| 53 | + }) |
| 54 | + |
| 55 | + const params = { |
| 56 | + app: testApp(), |
| 57 | + developerPlatformClient: client, |
| 58 | + appId: 'api-key-different', |
| 59 | + appName: 'appName', |
| 60 | + remoteApp, |
| 61 | + envIdentifiers: {}, |
| 62 | + force: false, |
| 63 | + release: true, |
| 64 | + } |
| 65 | + |
| 66 | + // When |
| 67 | + await expect(ensureDeploymentIdsPresence(params)).rejects.toThrow() |
| 68 | + |
| 69 | + // Then |
| 70 | + expect(client.appInstallCount).toHaveBeenCalledWith({ |
| 71 | + id: 'real-app-id', |
| 72 | + apiKey: 'api-key-different', |
| 73 | + organizationId: remoteApp.organizationId, |
| 74 | + }) |
| 75 | + }) |
| 76 | + |
| 77 | + test('when force is true, appInstallCount is not called even with remote-only extensions', async () => { |
| 78 | + // Given |
| 79 | + const breakdown = buildExtensionsBreakdown() |
| 80 | + breakdown.extensionIdentifiersBreakdown.onlyRemote = [buildExtensionBreakdownInfo('removed', 'uuid-1')] |
| 81 | + vi.mocked(extensionsIdentifiersDeployBreakdown).mockResolvedValue(breakdown) |
| 82 | + vi.mocked(configExtensionsIdentifiersBreakdown).mockResolvedValue(buildConfigBreakdown()) |
| 83 | + vi.mocked(deployOrReleaseConfirmationPrompt).mockResolvedValue(true) |
| 84 | + vi.mocked(deployConfirmed).mockResolvedValue({ |
| 85 | + extensions: {}, |
| 86 | + extensionIds: {}, |
| 87 | + extensionsNonUuidManaged: {}, |
| 88 | + }) |
| 89 | + |
| 90 | + const client = testDeveloperPlatformClient({ |
| 91 | + appInstallCount: vi.fn().mockResolvedValue(42), |
| 92 | + }) |
| 93 | + |
| 94 | + const params = { |
| 95 | + app: testApp(), |
| 96 | + developerPlatformClient: client, |
| 97 | + appId: 'appId', |
| 98 | + appName: 'appName', |
| 99 | + remoteApp: testOrganizationApp(), |
| 100 | + envIdentifiers: {}, |
| 101 | + force: true, |
| 102 | + release: true, |
| 103 | + } |
| 104 | + |
| 105 | + // When |
| 106 | + await ensureDeploymentIdsPresence(params) |
| 107 | + |
| 108 | + // Then |
| 109 | + expect(client.appInstallCount).not.toHaveBeenCalled() |
| 110 | + }) |
| 111 | + |
| 112 | + test('when allowUpdates and allowDeletes are both true, appInstallCount is not called', async () => { |
| 113 | + // Given |
| 114 | + const breakdown = buildExtensionsBreakdown() |
| 115 | + breakdown.extensionIdentifiersBreakdown.onlyRemote = [buildExtensionBreakdownInfo('removed', 'uuid-1')] |
| 116 | + vi.mocked(extensionsIdentifiersDeployBreakdown).mockResolvedValue(breakdown) |
| 117 | + vi.mocked(configExtensionsIdentifiersBreakdown).mockResolvedValue(buildConfigBreakdown()) |
| 118 | + vi.mocked(deployOrReleaseConfirmationPrompt).mockResolvedValue(true) |
| 119 | + vi.mocked(deployConfirmed).mockResolvedValue({ |
| 120 | + extensions: {}, |
| 121 | + extensionIds: {}, |
| 122 | + extensionsNonUuidManaged: {}, |
| 123 | + }) |
| 124 | + |
| 125 | + const client = testDeveloperPlatformClient({ |
| 126 | + appInstallCount: vi.fn().mockResolvedValue(42), |
| 127 | + }) |
| 128 | + |
| 129 | + const params = { |
| 130 | + app: testApp(), |
| 131 | + developerPlatformClient: client, |
| 132 | + appId: 'appId', |
| 133 | + appName: 'appName', |
| 134 | + remoteApp: testOrganizationApp(), |
| 135 | + envIdentifiers: {}, |
| 136 | + force: false, |
| 137 | + allowUpdates: true, |
| 138 | + allowDeletes: true, |
| 139 | + release: true, |
| 140 | + } |
| 141 | + |
| 142 | + // When |
| 143 | + await ensureDeploymentIdsPresence(params) |
| 144 | + |
| 145 | + // Then |
| 146 | + expect(client.appInstallCount).not.toHaveBeenCalled() |
| 147 | + }) |
| 148 | + |
| 149 | + test('when appInstallCount throws, installCount is undefined and deploy proceeds', async () => { |
| 150 | + // Given |
| 151 | + const breakdown = buildExtensionsBreakdown() |
| 152 | + breakdown.extensionIdentifiersBreakdown.onlyRemote = [buildExtensionBreakdownInfo('removed', 'uuid-1')] |
| 153 | + vi.mocked(extensionsIdentifiersDeployBreakdown).mockResolvedValue(breakdown) |
| 154 | + vi.mocked(configExtensionsIdentifiersBreakdown).mockResolvedValue(buildConfigBreakdown()) |
| 155 | + vi.mocked(deployOrReleaseConfirmationPrompt).mockResolvedValue(true) |
| 156 | + vi.mocked(deployConfirmed).mockResolvedValue({ |
| 157 | + extensions: {}, |
| 158 | + extensionIds: {}, |
| 159 | + extensionsNonUuidManaged: {}, |
| 160 | + }) |
| 161 | + |
| 162 | + const client = testDeveloperPlatformClient({ |
| 163 | + appInstallCount: vi.fn().mockRejectedValue(new Error('API error')), |
| 164 | + }) |
| 165 | + |
| 166 | + const params = { |
| 167 | + app: testApp(), |
| 168 | + developerPlatformClient: client, |
| 169 | + appId: 'appId', |
| 170 | + appName: 'appName', |
| 171 | + remoteApp: testOrganizationApp(), |
| 172 | + envIdentifiers: {}, |
| 173 | + force: false, |
| 174 | + release: true, |
| 175 | + } |
| 176 | + |
| 177 | + // When |
| 178 | + await ensureDeploymentIdsPresence(params) |
| 179 | + |
| 180 | + // Then - installCount should be undefined in the prompt call |
| 181 | + expect(deployOrReleaseConfirmationPrompt).toHaveBeenCalledWith( |
| 182 | + expect.objectContaining({ |
| 183 | + installCount: undefined, |
| 184 | + }), |
| 185 | + ) |
| 186 | + }) |
| 187 | + |
37 | 188 | test('when the prompt is confirmed post-confirmation actions as run and the result is returned', async () => { |
38 | 189 | // Given |
39 | 190 | vi.mocked(extensionsIdentifiersDeployBreakdown).mockResolvedValue(buildExtensionsBreakdown()) |
@@ -75,7 +226,7 @@ describe('ensureDeploymentIdsPresence', () => { |
75 | 226 | function buildExtensionsBreakdown() { |
76 | 227 | return { |
77 | 228 | extensionIdentifiersBreakdown: { |
78 | | - onlyRemote: [], |
| 229 | + onlyRemote: [] as ExtensionIdentifierBreakdownInfo[], |
79 | 230 | toCreate: [], |
80 | 231 | toUpdate: [], |
81 | 232 | fromDashboard: [], |
|
0 commit comments