Commit f8d175ef authored by Stan Hu's avatar Stan Hu

Fix filePath not being stored in GraphQL log tree cache

This was discovered when trying to paginate the tree entries and use the
log tree cache: we were not storing `filePath` even though it was being
generated. As a result, the log entries could not be matched with
newly-inserted data.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/334140

Changelog: fixed
parent 6f70084c
......@@ -5,5 +5,6 @@ fragment TreeEntryCommit on LogTreeCommit {
committedDate
commitPath
fileName
filePath
type
}
......@@ -5,6 +5,7 @@ fragment TreeEntryCommit on LogTreeCommit {
committedDate
commitPath
fileName
filePath
type
lockLabel
}
import MockAdapter from 'axios-mock-adapter';
import { createMockClient } from 'helpers/mock_apollo_helper';
import axios from '~/lib/utils/axios_utils';
import { resolveCommit, fetchLogsTree } from '~/repository/log_tree';
import commitsQuery from '~/repository/queries/commits.query.graphql';
import projectPathQuery from '~/repository/queries/project_path.query.graphql';
import refQuery from '~/repository/queries/ref.query.graphql';
const mockData = [
{
......@@ -10,6 +14,7 @@ const mockData = [
committed_date: '2019-01-01',
},
commit_path: `https://test.com`,
commit_title_html: 'commit title',
file_name: 'index.js',
type: 'blob',
},
......@@ -50,19 +55,15 @@ describe('fetchLogsTree', () => {
global.gon = { relative_url_root: '' };
client = {
readQuery: () => ({
projectPath: 'gitlab-org/gitlab-foss',
escapedRef: 'main',
commits: [],
}),
writeQuery: jest.fn(),
};
resolver = {
entry: { name: 'index.js', type: 'blob' },
resolve: jest.fn(),
};
client = createMockClient();
client.writeQuery({ query: projectPathQuery, data: { projectPath: 'gitlab-org/gitlab-foss' } });
client.writeQuery({ query: refQuery, data: { ref: 'main', escapedRef: 'main' } });
client.writeQuery({ query: commitsQuery, data: { commits: [] } });
});
afterEach(() => {
......@@ -125,25 +126,19 @@ describe('fetchLogsTree', () => {
it('writes query to client', async () => {
await fetchLogsTree(client, '', '0', resolver);
expect(client.writeQuery).toHaveBeenCalledWith({
query: expect.anything(),
data: {
projectPath: 'gitlab-org/gitlab-foss',
escapedRef: 'main',
expect(client.readQuery({ query: commitsQuery })).toEqual({
commits: [
expect.objectContaining({
__typename: 'LogTreeCommit',
commitPath: 'https://test.com',
committedDate: '2019-01-01',
fileName: 'index.js',
filePath: '/index.js',
message: 'testing message',
sha: '123',
titleHtml: undefined,
titleHtml: 'commit title',
type: 'blob',
}),
],
},
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment