fix(walkthrough): thread directory into GitLab diff client and fix tests
- Add directory parameter to getGitLabMergeRequestDiff for per-project API base URL override resolution - Mock getGitLabAuth/getEffectiveProviderApiBaseUrl in walkthrough tests - Update auth-check test to mock null auth instead of null client
This commit is contained in:
@@ -62,7 +62,7 @@ async function getGitHubPullRequestDiff(directory, number) {
|
|||||||
* dispatcher's `resolveGitLabRepoFromDirectory` call and is never re-resolved
|
* dispatcher's `resolveGitLabRepoFromDirectory` call and is never re-resolved
|
||||||
* here.
|
* here.
|
||||||
*/
|
*/
|
||||||
async function getGitLabMergeRequestDiff(repo, number) {
|
async function getGitLabMergeRequestDiff(directory, repo, number) {
|
||||||
// Resolve per-project API base override, mirroring getClient() in routes.js.
|
// Resolve per-project API base override, mirroring getClient() in routes.js.
|
||||||
const auth = getGitLabAuth();
|
const auth = getGitLabAuth();
|
||||||
if (!auth?.accessToken) {
|
if (!auth?.accessToken) {
|
||||||
@@ -132,7 +132,7 @@ async function getGitLabMergeRequestDiff(repo, number) {
|
|||||||
export async function getPullRequestDiff(directory, number) {
|
export async function getPullRequestDiff(directory, number) {
|
||||||
const { repo } = await resolveGitLabRepoFromDirectory(directory);
|
const { repo } = await resolveGitLabRepoFromDirectory(directory);
|
||||||
if (repo) {
|
if (repo) {
|
||||||
return getGitLabMergeRequestDiff(repo, number);
|
return getGitLabMergeRequestDiff(directory, repo, number);
|
||||||
}
|
}
|
||||||
return getGitHubPullRequestDiff(directory, number);
|
return getGitHubPullRequestDiff(directory, number);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,25 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|||||||
|
|
||||||
vi.mock('../github/octokit.js', () => ({ getOctokitOrNull: vi.fn() }));
|
vi.mock('../github/octokit.js', () => ({ getOctokitOrNull: vi.fn() }));
|
||||||
vi.mock('../github/repo/index.js', () => ({ resolveGitHubRepoFromDirectory: vi.fn() }));
|
vi.mock('../github/repo/index.js', () => ({ resolveGitHubRepoFromDirectory: vi.fn() }));
|
||||||
vi.mock('../gitlab/client.js', () => ({ getGitLabClientOrNull: vi.fn() }));
|
vi.mock('../gitlab/client.js', () => ({
|
||||||
|
getGitLabClientOrNull: vi.fn(),
|
||||||
|
createGitLabClient: vi.fn(),
|
||||||
|
}));
|
||||||
|
vi.mock('../gitlab/auth.js', () => ({
|
||||||
|
getGitLabAuth: vi.fn(),
|
||||||
|
getGitLabDefaultBaseUrl: vi.fn(() => 'https://gitlab.com'),
|
||||||
|
}));
|
||||||
|
vi.mock('../git-providers/project-config.js', () => ({
|
||||||
|
getEffectiveProviderApiBaseUrl: vi.fn(() => null),
|
||||||
|
}));
|
||||||
vi.mock('../gitlab/repo.js', () => ({ resolveGitLabRepoFromDirectory: vi.fn() }));
|
vi.mock('../gitlab/repo.js', () => ({ resolveGitLabRepoFromDirectory: vi.fn() }));
|
||||||
|
|
||||||
const { getPullRequestDiff } = await import('./pull-request.js');
|
const { getPullRequestDiff } = await import('./pull-request.js');
|
||||||
const { getOctokitOrNull } = await import('../github/octokit.js');
|
const { getOctokitOrNull } = await import('../github/octokit.js');
|
||||||
const { resolveGitHubRepoFromDirectory } = await import('../github/repo/index.js');
|
const { resolveGitHubRepoFromDirectory } = await import('../github/repo/index.js');
|
||||||
const { getGitLabClientOrNull } = await import('../gitlab/client.js');
|
const { getGitLabClientOrNull, createGitLabClient } = await import('../gitlab/client.js');
|
||||||
|
const { getGitLabAuth } = await import('../gitlab/auth.js');
|
||||||
|
const { getEffectiveProviderApiBaseUrl } = await import('../git-providers/project-config.js');
|
||||||
const { resolveGitLabRepoFromDirectory } = await import('../gitlab/repo.js');
|
const { resolveGitLabRepoFromDirectory } = await import('../gitlab/repo.js');
|
||||||
|
|
||||||
const PATCH = `diff --git a/src/a.ts b/src/a.ts
|
const PATCH = `diff --git a/src/a.ts b/src/a.ts
|
||||||
@@ -57,6 +69,7 @@ describe('getPullRequestDiff', () => {
|
|||||||
// the GitHub path.
|
// the GitHub path.
|
||||||
resolveGitLabRepoFromDirectory.mockResolvedValue({ repo: null, remoteUrl: null });
|
resolveGitLabRepoFromDirectory.mockResolvedValue({ repo: null, remoteUrl: null });
|
||||||
getGitLabClientOrNull.mockReturnValue(null);
|
getGitLabClientOrNull.mockReturnValue(null);
|
||||||
|
getGitLabAuth.mockReturnValue({ accessToken: 'test-token' });
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -146,6 +159,7 @@ describe('getPullRequestDiff', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('asks the user to connect GitLab before fetching diffs', async () => {
|
it('asks the user to connect GitLab before fetching diffs', async () => {
|
||||||
|
getGitLabAuth.mockReturnValue(null);
|
||||||
getGitLabClientOrNull.mockReturnValue(null);
|
getGitLabClientOrNull.mockReturnValue(null);
|
||||||
|
|
||||||
await expect(getPullRequestDiff('/repo', 7)).rejects.toMatchObject({
|
await expect(getPullRequestDiff('/repo', 7)).rejects.toMatchObject({
|
||||||
|
|||||||
Reference in New Issue
Block a user