|
| 1 | +import { buildFileUrl, buildTreeUrl } from './gitUrls'; |
| 2 | + |
| 3 | +describe('buildFileUrl', () => { |
| 4 | + it('addresses Azure DevOps files through the path query parameter', () => { |
| 5 | + expect( |
| 6 | + buildFileUrl( |
| 7 | + 'https://dev.azure.com/my-org/my-project/_git/my-repo', |
| 8 | + 'AGENTS.md', |
| 9 | + ), |
| 10 | + ).toBe( |
| 11 | + 'https://dev.azure.com/my-org/my-project/_git/my-repo?path=%2FAGENTS.md', |
| 12 | + ); |
| 13 | + }); |
| 14 | + |
| 15 | + it('keeps the Azure DevOps branch or tag the caller was given', () => { |
| 16 | + expect( |
| 17 | + buildFileUrl( |
| 18 | + 'https://dev.azure.com/my-org/my-project/_git/my-repo?path=%2F&version=GBmain', |
| 19 | + '.cursor/rules/my-rule.mdc', |
| 20 | + ), |
| 21 | + ).toBe( |
| 22 | + 'https://dev.azure.com/my-org/my-project/_git/my-repo?path=%2F.cursor%2Frules%2Fmy-rule.mdc&version=GBmain', |
| 23 | + ); |
| 24 | + }); |
| 25 | + |
| 26 | + it('supports the legacy visualstudio.com host', () => { |
| 27 | + expect( |
| 28 | + buildFileUrl( |
| 29 | + 'https://my-org.visualstudio.com/my-project/_git/my-repo?version=GBmaster', |
| 30 | + 'AGENTS.md', |
| 31 | + ), |
| 32 | + ).toBe( |
| 33 | + 'https://my-org.visualstudio.com/my-project/_git/my-repo?version=GBmaster&path=%2FAGENTS.md', |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + it('addresses other providers through path segments', () => { |
| 38 | + expect(buildFileUrl('https://github.com/my-org/my-repo', 'AGENTS.md')).toBe( |
| 39 | + 'https://github.com/my-org/my-repo/blob/HEAD/AGENTS.md', |
| 40 | + ); |
| 41 | + expect( |
| 42 | + buildFileUrl('https://gitlab.com/my-org/my-repo', 'CLAUDE.md'), |
| 43 | + ).toBe('https://gitlab.com/my-org/my-repo/blob/HEAD/CLAUDE.md'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('tolerates trailing slashes', () => { |
| 47 | + expect( |
| 48 | + buildFileUrl('https://github.com/my-org/my-repo//', 'AGENTS.md'), |
| 49 | + ).toBe('https://github.com/my-org/my-repo/blob/HEAD/AGENTS.md'); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +describe('buildTreeUrl', () => { |
| 54 | + it('addresses Azure DevOps directories through the path query parameter', () => { |
| 55 | + expect( |
| 56 | + buildTreeUrl( |
| 57 | + 'https://dev.azure.com/my-org/my-project/_git/my-repo?path=%2F&version=GBmain', |
| 58 | + '.agents/skills', |
| 59 | + ), |
| 60 | + ).toBe( |
| 61 | + 'https://dev.azure.com/my-org/my-project/_git/my-repo?path=%2F.agents%2Fskills&version=GBmain', |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + it('addresses other providers through path segments', () => { |
| 66 | + expect( |
| 67 | + buildTreeUrl('https://github.com/my-org/my-repo', '.cursor/rules'), |
| 68 | + ).toBe('https://github.com/my-org/my-repo/tree/HEAD/.cursor/rules'); |
| 69 | + }); |
| 70 | +}); |
0 commit comments