|
1 | | -import { REGION_IMAGE_LOGO_URL } from '@openops/shared'; |
| 1 | +import { ErrorCode, REGION_IMAGE_LOGO_URL } from '@openops/shared'; |
2 | 2 |
|
3 | 3 | import { resolveOptions } from '../../../../../src/app/benchmark/providers/azure/azure-option-resolver'; |
4 | 4 |
|
@@ -178,6 +178,61 @@ describe('resolveOptions (Azure)', () => { |
178 | 178 | expect(result).toEqual([{ id: 'sub-1', displayName: 'One' }]); |
179 | 179 | }); |
180 | 180 |
|
| 181 | + it('throws validation error when subscriptions list is empty', async () => { |
| 182 | + mockGetOneOrThrow.mockResolvedValue({ |
| 183 | + authProviderKey: 'Azure', |
| 184 | + value: { |
| 185 | + type: 'CUSTOM_AUTH', |
| 186 | + props: { |
| 187 | + clientId: 'client_id', |
| 188 | + clientSecret: 'client_secret', |
| 189 | + tenantId: 'tenant', |
| 190 | + }, |
| 191 | + }, |
| 192 | + }); |
| 193 | + mockAuthenticateUserWithAzure.mockResolvedValue({ access_token: 't' }); |
| 194 | + mockGetAzureSubscriptionsList.mockResolvedValue([]); |
| 195 | + |
| 196 | + const rejection = resolveOptions('getSubscriptionsList', { |
| 197 | + projectId, |
| 198 | + provider, |
| 199 | + benchmarkConfiguration: { connection: ['c1'] }, |
| 200 | + }); |
| 201 | + await expect(rejection).rejects.toMatchObject({ |
| 202 | + error: { code: ErrorCode.VALIDATION }, |
| 203 | + }); |
| 204 | + await expect(rejection).rejects.toThrow( |
| 205 | + /No Azure subscriptions were returned for this connection/, |
| 206 | + ); |
| 207 | + }); |
| 208 | + |
| 209 | + it('throws validation error when subscription listing fails', async () => { |
| 210 | + mockGetOneOrThrow.mockResolvedValue({ |
| 211 | + authProviderKey: 'Azure', |
| 212 | + value: { |
| 213 | + type: 'CUSTOM_AUTH', |
| 214 | + props: { |
| 215 | + clientId: 'client_id', |
| 216 | + clientSecret: 'client_secret', |
| 217 | + tenantId: 'tenant', |
| 218 | + }, |
| 219 | + }, |
| 220 | + }); |
| 221 | + mockAuthenticateUserWithAzure.mockRejectedValue(new Error('token failed')); |
| 222 | + |
| 223 | + const rejection = resolveOptions('getSubscriptionsList', { |
| 224 | + projectId, |
| 225 | + provider, |
| 226 | + benchmarkConfiguration: { connection: ['c1'] }, |
| 227 | + }); |
| 228 | + await expect(rejection).rejects.toMatchObject({ |
| 229 | + error: { code: ErrorCode.VALIDATION }, |
| 230 | + }); |
| 231 | + await expect(rejection).rejects.toThrow( |
| 232 | + /Unable to retrieve Azure subscriptions with the provided connection details/, |
| 233 | + ); |
| 234 | + }); |
| 235 | + |
181 | 236 | it('delegates to getAzureRegionsList and returns options with imageLogoUrl for getRegionsList', async () => { |
182 | 237 | const regionsList = [ |
183 | 238 | { id: 'eastus', displayName: 'East US' }, |
|
0 commit comments