From 5b61398e30af089f8a69c2fcc9ee075e46f5289f Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 20 Oct 2023 15:47:00 +0800 Subject: [PATCH] add tests --- __test__/url-helper.test.ts | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 __test__/url-helper.test.ts diff --git a/__test__/url-helper.test.ts b/__test__/url-helper.test.ts new file mode 100644 index 0000000..4c7e59c --- /dev/null +++ b/__test__/url-helper.test.ts @@ -0,0 +1,46 @@ +import * as urlHelper from '../lib/url-helper' + +import { IGitSourceSettings } from '../lib/git-source-settings'; + +function getSettings(u: string): IGitSourceSettings { + return { + githubServerUrl: u, + repositoryPath: '', + repositoryOwner: 'some-owner', + repositoryName: 'some-name', + ref: '', commit: '', clean: false, filter: undefined, + sparseCheckout: [], sparseCheckoutConeMode: false, + fetchDepth: 0, fetchTags: false, showProgress: false, + lfs: false, submodules: false, nestedSubmodules: false, + authToken: '', sshKey: '', sshKnownHosts: '', sshStrict: false, + persistCredentials: false, workflowOrganizationId: undefined, + setSafeDirectory: false + } +} +describe('url-helper tests', () => { + it('getFetchUrl works on GitHub repos', async () => { + expect(urlHelper.getFetchUrl(getSettings('https://github.com'))).toBe( + "https://github.com/some-owner/some-name" + ) + }) + + it('getFetchUrl works on 3rd party repos with sub-path', async () => { + expect(urlHelper.getFetchUrl(getSettings('https://other.com/subpath'))).toBe( + 'https://other.com/subpath/some-owner/some-name' + ) + }) + + it('getFetchUrl works on 3rd party repos with ssh keys', async () => { + expect(urlHelper.getFetchUrl(getSettings('https://other.com/subpath'))).toBe( + 'https://other.com/subpath/some-owner/some-name' + ) + }) + + it('getFetchUrl works with ssh credentials', async () => { + let settings = getSettings('https://other.com/subpath'); + settings.sshKey = 'not-empty' + expect(urlHelper.getFetchUrl(settings)).toBe( + 'git@other.com:some-owner/some-name.git' + ) + }) +})