|
1 | | -import { collectXSecurityAuthTypes } from '../../utils/telemetry.js'; |
| 1 | +import { collectXSecurityAuthTypes, transformSpecVersionError } from '../../utils/telemetry.js'; |
2 | 2 |
|
3 | 3 | import type { ArazzoDefinition } from '@redocly/openapi-core'; |
4 | 4 |
|
@@ -87,3 +87,57 @@ describe('collectXSecurityAuthTypes', () => { |
87 | 87 | ]); |
88 | 88 | }); |
89 | 89 | }); |
| 90 | + |
| 91 | +describe('transformSpecVersionError', () => { |
| 92 | + it('should transform "Unsupported specification" error', () => { |
| 93 | + const result = transformSpecVersionError('Unsupported specification'); |
| 94 | + expect(result).toBe('unsupported'); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should transform AsyncAPI version errors', () => { |
| 98 | + const result1 = transformSpecVersionError('Unsupported AsyncAPI version: 2.1.1'); |
| 99 | + expect(result1).toBe('unsupported-async-2.1.1'); |
| 100 | + |
| 101 | + const result2 = transformSpecVersionError('Unsupported AsyncAPI version: 1.2.0'); |
| 102 | + expect(result2).toBe('unsupported-async-1.2.0'); |
| 103 | + }); |
| 104 | + |
| 105 | + it('should transform OpenAPI version errors', () => { |
| 106 | + const result1 = transformSpecVersionError('Unsupported OpenAPI version: 3.2.0'); |
| 107 | + expect(result1).toBe('unsupported-openapi-3.2.0'); |
| 108 | + |
| 109 | + const result2 = transformSpecVersionError('Unsupported OpenAPI version: 2.1'); |
| 110 | + expect(result2).toBe('unsupported-openapi-2.1'); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should handle generic unsupported version errors', () => { |
| 114 | + const result = transformSpecVersionError('Unsupported Some API version: 1.0'); |
| 115 | + expect(result).toBe('unsupported'); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should transform invalid document errors', () => { |
| 119 | + const result = transformSpecVersionError('Document must be JSON object, got string'); |
| 120 | + expect(result).toBe('unknown'); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should transform invalid OpenAPI version format errors', () => { |
| 124 | + const result = transformSpecVersionError( |
| 125 | + 'Invalid OpenAPI version: should be a string but got "number"' |
| 126 | + ); |
| 127 | + expect(result).toBe('invalid-openapi-version'); |
| 128 | + }); |
| 129 | + |
| 130 | + it('should return "unknown" for empty or invalid input', () => { |
| 131 | + expect(transformSpecVersionError('')).toBe('unknown'); |
| 132 | + expect(transformSpecVersionError(null as any)).toBe('unknown'); |
| 133 | + expect(transformSpecVersionError(undefined as any)).toBe('unknown'); |
| 134 | + }); |
| 135 | + |
| 136 | + it('should be case insensitive', () => { |
| 137 | + const result1 = transformSpecVersionError('UNSUPPORTED SPECIFICATION'); |
| 138 | + expect(result1).toBe('unsupported'); |
| 139 | + |
| 140 | + const result2 = transformSpecVersionError('unsupported asyncapi version: 2.1.1'); |
| 141 | + expect(result2).toBe('unsupported-async-2.1.1'); |
| 142 | + }); |
| 143 | +}); |
0 commit comments