|
| 1 | +import type { GlobalConfig } from '@n8n/config'; |
| 2 | +import { mock } from 'jest-mock-extended'; |
| 3 | + |
| 4 | +import config from '@/config'; |
| 5 | + |
| 6 | +import { UrlService } from '../url.service'; |
| 7 | + |
| 8 | +describe('UrlService', () => { |
| 9 | + beforeEach(() => { |
| 10 | + process.env.WEBHOOK_URL = undefined; |
| 11 | + config.load(config.default); |
| 12 | + }); |
| 13 | + |
| 14 | + describe('getInstanceBaseUrl', () => { |
| 15 | + it('should set URL from N8N_EDITOR_BASE_URL', () => { |
| 16 | + config.set('editorBaseUrl', 'https://example.com/'); |
| 17 | + process.env.WEBHOOK_URL = undefined; |
| 18 | + const urlService = new UrlService(mock<GlobalConfig>()); |
| 19 | + expect(urlService.getInstanceBaseUrl()).toBe('https://example.com'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should set URL from WEBHOOK_URL', () => { |
| 23 | + config.set('editorBaseUrl', ''); |
| 24 | + process.env.WEBHOOK_URL = 'https://example.com/'; |
| 25 | + const urlService = new UrlService(mock<GlobalConfig>()); |
| 26 | + expect(urlService.getInstanceBaseUrl()).toBe('https://example.com'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should trim quotes when setting URL from N8N_EDITOR_BASE_URL', () => { |
| 30 | + config.set('editorBaseUrl', '"https://example.com"'); |
| 31 | + process.env.WEBHOOK_URL = undefined; |
| 32 | + const urlService = new UrlService(mock<GlobalConfig>()); |
| 33 | + expect(urlService.getInstanceBaseUrl()).toBe('https://example.com'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should trim quotes when setting URL from WEBHOOK_URL', () => { |
| 37 | + config.set('editorBaseUrl', ''); |
| 38 | + process.env.WEBHOOK_URL = '"https://example.com/"'; |
| 39 | + const urlService = new UrlService(mock<GlobalConfig>()); |
| 40 | + expect(urlService.getInstanceBaseUrl()).toBe('https://example.com'); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments