From cb1681f43ce4f25eca119768c9f0e5c668a1e986 Mon Sep 17 00:00:00 2001 From: Kavitha Kesavalu Date: Sat, 2 Nov 2024 19:09:31 -0400 Subject: [PATCH] fix(test): updated tests --- jest.config.cjs | 1 + jest.setup.ts | 3 +++ src/adapters/git.test.ts | 8 ++++++++ src/adapters/github.test.ts | 9 ++++++--- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 jest.setup.ts diff --git a/jest.config.cjs b/jest.config.cjs index 8f5c5b2c..59ffa5b3 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -3,6 +3,7 @@ module.exports = { testEnvironment: 'node', extensionsToTreatAsEsm: ['.ts', '.mts'], coveragePathIgnorePatterns: ['\\.mock\\.ts$'], + setupFilesAfterEnv: ['/jest.setup.ts'], moduleFileExtensions: ['ts', 'mts', 'tsx', 'js', 'mjs', 'jsx', 'json', 'node'], testRegex: '(/(__tests__|e2e)/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?|mts)$', transform: { diff --git a/jest.setup.ts b/jest.setup.ts new file mode 100644 index 00000000..d0198290 --- /dev/null +++ b/jest.setup.ts @@ -0,0 +1,3 @@ +beforeEach(() => { + process.env.SHEPHERD_GITHUB_ENTERPRISE_URL = 'https://api.github.com'; +}); diff --git a/src/adapters/git.test.ts b/src/adapters/git.test.ts index 164926bc..b039f2c9 100644 --- a/src/adapters/git.test.ts +++ b/src/adapters/git.test.ts @@ -7,6 +7,14 @@ jest.mock('simple-git'); jest.mock('fs-extra'); class TestGitAdapter extends GitAdapter { + // @ts-ignore + createIssue(repo: IRepo): Promise { + return Promise.resolve(''); + } + // @ts-ignore + updateIssue(repo: IRepo, issueNumber: number): Promise { + return Promise.resolve(); + } // @ts-ignore getCandidateRepos(onRetry: RetryMethod): Promise { return Promise.resolve([]); diff --git a/src/adapters/github.test.ts b/src/adapters/github.test.ts index 440df492..45a49be2 100644 --- a/src/adapters/github.test.ts +++ b/src/adapters/github.test.ts @@ -268,17 +268,20 @@ describe('GithubAdapter', () => { it('returns the SSH URL, when not given a protocol', () => { delete process.env.SHEPHERD_GITHUB_PROTOCOL; - expect(adapter['getRepositoryUrl'](repo)).toBe('git@github.com:NerdWallet/shepherd.git'); + process.env.SHEPHERD_GITHUB_ENTERPRISE_BASE_URL = 'https://api.github.com'; + expect(adapter['getRepositoryUrl'](repo)).toBe('git@api.github.com:NerdWallet/shepherd.git'); }); it('returns the SSH URL, when given protocol=ssh', () => { process.env.SHEPHERD_GITHUB_PROTOCOL = 'ssh'; - expect(adapter['getRepositoryUrl'](repo)).toBe('git@github.com:NerdWallet/shepherd.git'); + expect(adapter['getRepositoryUrl'](repo)).toBe('git@api.github.com:NerdWallet/shepherd.git'); }); it('returns the HTTPS URL when given protocol=https', () => { process.env.SHEPHERD_GITHUB_PROTOCOL = 'https'; - expect(adapter['getRepositoryUrl'](repo)).toBe('https://github.com/NerdWallet/shepherd.git'); + expect(adapter['getRepositoryUrl'](repo)).toBe( + 'https://api.github.com/NerdWallet/shepherd.git' + ); }); it('throws on unexpected protocols', () => {