|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +import { describe, it, expect } from 'vitest'; |
| 20 | + |
| 21 | +import { validateEndpoint } from './endpoint'; |
| 22 | + |
| 23 | +describe('validateEndpoint', () => { |
| 24 | + it('accepts the InCloud shape with the /youtrack context path', () => { |
| 25 | + expect(validateEndpoint('https://example.myjetbrains.com/youtrack/api')).toBe(''); |
| 26 | + }); |
| 27 | + |
| 28 | + it('accepts the youtrack.cloud shape', () => { |
| 29 | + expect(validateEndpoint('https://example.youtrack.cloud/api')).toBe(''); |
| 30 | + }); |
| 31 | + |
| 32 | + it('accepts self-hosted shapes, with and without a context path', () => { |
| 33 | + expect(validateEndpoint('https://youtrack.example.com/api')).toBe(''); |
| 34 | + expect(validateEndpoint('https://www.example.com/youtrack/api')).toBe(''); |
| 35 | + }); |
| 36 | + |
| 37 | + it('accepts http for self-hosted', () => { |
| 38 | + expect(validateEndpoint('http://youtrack.internal:8080/api')).toBe(''); |
| 39 | + }); |
| 40 | + |
| 41 | + it('accepts a trailing slash (normalized like the backend)', () => { |
| 42 | + expect(validateEndpoint('https://example.myjetbrains.com/youtrack/api/')).toBe(''); |
| 43 | + expect(validateEndpoint('https://example.myjetbrains.com/youtrack/api//')).toBe(''); |
| 44 | + }); |
| 45 | + |
| 46 | + it('rejects an empty endpoint as required', () => { |
| 47 | + expect(validateEndpoint('')).toBe('endpoint is required'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('rejects a URL that does not end in /api, with the example in the message', () => { |
| 51 | + const message = validateEndpoint('https://example.myjetbrains.com/youtrack'); |
| 52 | + expect(message).toContain('/api'); |
| 53 | + expect(message).toContain('https://example.myjetbrains.com/youtrack/api'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('rejects the most common InCloud error — the missing /youtrack prefix surfaces as a non-/api path', () => { |
| 57 | + expect(validateEndpoint('https://example.myjetbrains.com')).not.toBe(''); |
| 58 | + }); |
| 59 | + |
| 60 | + it('rejects non-absolute URLs', () => { |
| 61 | + expect(validateEndpoint('example.myjetbrains.com/youtrack/api')).not.toBe(''); |
| 62 | + expect(validateEndpoint('/youtrack/api')).not.toBe(''); |
| 63 | + }); |
| 64 | + |
| 65 | + it('rejects non-http(s) schemes', () => { |
| 66 | + expect(validateEndpoint('ftp://example.com/api')).not.toBe(''); |
| 67 | + }); |
| 68 | +}); |
0 commit comments