space, project, repo, })); }); describe('other', () => { const [host, project, repo] = ['bitbucket.other', 'foo', 'bar']; it('requires project', () => expect(() => parseRepoUrl(`${host}${queryString({ repo })}`, integrations), ).toThrow(/missing project/)); it('requires repo', () => expect(() => parseRepoUrl(`${host}${queryString({ project })}`, integrations), ).toThrow(/missing repo/)); it('happy path', () => expect( parseRepoUrl( `${host}${queryString({ project, repo })}`, integrations, ), ).toMatchObject({ host, project, repo, })); }); }); describe('azure', () => { beforeEach(() => byHost.mockReturnValue({ type: 'azure' })); const [host, project, repo] = ['az.ure', 'foo', 'bar']; it('requires project', () => expect(() => parseRepoUrl(`${host}${queryString({ repo })}`, integrations), ).toThrow(/missing project/)); it('requires repo', () => expect(() => parseRepoUrl(`${host}${queryString({ project })}`, integrations), ).toThrow(/missing repo/)); it('happy path', () => expect( parseRepoUrl( `${host}${queryString({ project, repo })}`, integrations, ), ).toMatchObject({ host, project, repo, })); }); describe('gitlab', () => { beforeEach(() => byHost.mockReturnValue({ type: 'gitlab' })); const [host, owner, repo, project] = ['gitl.ab', 'foo', 'bar', '123456']; it('requires owner', () => expect(() => parseRepoUrl(`${host}${queryString({ repo })}`, integrations), ).toThrow(/missing owner/)); it('requires repo', () => expect(() => parseRepoUrl(`${host}${queryString({ owner })}`, integrations), ).toThrow(/missing repo/)); it('unless project specified', () => expect( parseRepoUrl(`${host}${queryString({ project })}`, integrations), ).toMatchObject({ host, project })); it('happy path', () => expect( parseRepoUrl(`${host}${queryString({ owner, repo })}`, integrations), ).toMatchObject({ host, owner, repo, })); }); describe('gitea', () => { beforeEach(() => byHost.mockReturnValue({ type: 'gitea' })); const [host, repo] = ['git.ea', 'foo']; it('requires repo', () => expect(() => parseRepoUrl(host, integrations)).toThrow(/missing repo/)); it('happy path', () => expect( parseRepoUrl(`${host}${queryString({ repo })}`, integrations), ).toMatchObject({ host, repo })); }); describe('gerrit', () => { beforeEach(() => byHost.mockReturnValue({ type: 'gerrit' })); const [host, repo] = ['gerr.it', 'foo']; it('requires repo', () => expect(() => parseRepoUrl(host, integrations)).toThrow(/missing repo/)); it('happy path', () => expect( parseRepoUrl(`${host}${queryString({ repo })}`, integrations), ).toMatchObject({ host, repo, })); }); describe('generic type', () => { beforeEach(() => byHost.mockReturnValue({ type: 'generic' })); const [host, owner, repo] = ['oth.er', 'foo', 'bar']; it('requires owner', () => expect(() => parseRepoUrl(`${host}${queryString({ repo })}`, integrations), ).toThrow(/missing owner/)); it('requires repo', () => expect(() => parseRepoUrl(`${host}${queryString({ owner })}`, integrations), ).toThrow(/missing repo/)); it('happy path', () => expect( parseRepoUrl(`${host}${queryString({ owner, repo })}`, integrations), ).toMatchObject({ host, owner, repo, })); }); describe('facilitates naive URL construction', () => { beforeEach(() => byHost.mockReturnValue({ type: 'irrelevant' })); it('decodes encoded params', () => { const [host, owner, repo] = ['with_the_most', 'foo/bar/baz', 'blah']; expect( parseRepoUrl(`${host}${queryString({ owner, repo })}`, integrations), ).toMatchObject({ host, owner, repo }); }); it('trims leading and trailing / from params', () => { const [host, owner, organization, workspace, project, repo] = [ 'anywhere', 'anyone', 'anything', 'anyway', 'anyhow', 'any', ]; const junkedUp = mapValues( { owner, organization, workspace, project, repo }, v => `//${v}//`, ); return expect( parseRepoUrl(`${host}${queryString(junkedUp)}`, integrations), ).toMatchObject({ host, owner, organization, workspace, project, repo, }); }); }); }); }); W”8’ë@¿