2021-03-08 18:12:59 +05:30
|
|
|
import { getDerivedMergeRequestInformation } from '~/diffs/utils/merge_request';
|
|
|
|
import { diffMetadata } from '../mock_data/diff_metadata';
|
|
|
|
|
|
|
|
describe('Merge Request utilities', () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
const derivedBaseInfo = {
|
2021-03-08 18:12:59 +05:30
|
|
|
mrPath: '/gitlab-org/gitlab-test/-/merge_requests/4',
|
|
|
|
userOrGroup: 'gitlab-org',
|
|
|
|
project: 'gitlab-test',
|
|
|
|
id: '4',
|
|
|
|
};
|
2023-03-04 22:38:38 +05:30
|
|
|
const derivedVersionInfo = {
|
|
|
|
diffId: '4',
|
|
|
|
startSha: 'eb227b3e214624708c474bdab7bde7afc17cefcc',
|
|
|
|
};
|
|
|
|
const noVersion = {
|
|
|
|
diffId: undefined,
|
|
|
|
startSha: undefined,
|
|
|
|
};
|
2021-03-08 18:12:59 +05:30
|
|
|
const unparseableEndpoint = {
|
|
|
|
mrPath: undefined,
|
|
|
|
userOrGroup: undefined,
|
|
|
|
project: undefined,
|
|
|
|
id: undefined,
|
2023-03-04 22:38:38 +05:30
|
|
|
...noVersion,
|
2021-03-08 18:12:59 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
describe('getDerivedMergeRequestInformation', () => {
|
2023-03-04 22:38:38 +05:30
|
|
|
let endpoint = `${diffMetadata.latest_version_path}.json?searchParam=irrelevant`;
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
it.each`
|
|
|
|
argument | response
|
2023-03-04 22:38:38 +05:30
|
|
|
${{ endpoint }} | ${{ ...derivedBaseInfo, ...noVersion }}
|
2021-03-08 18:12:59 +05:30
|
|
|
${{}} | ${unparseableEndpoint}
|
|
|
|
${{ endpoint: undefined }} | ${unparseableEndpoint}
|
|
|
|
${{ endpoint: null }} | ${unparseableEndpoint}
|
|
|
|
`('generates the correct derived results based on $argument', ({ argument, response }) => {
|
|
|
|
expect(getDerivedMergeRequestInformation(argument)).toStrictEqual(response);
|
|
|
|
});
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
describe('version information', () => {
|
|
|
|
const bare = diffMetadata.latest_version_path;
|
|
|
|
endpoint = diffMetadata.merge_request_diffs[0].compare_path;
|
|
|
|
|
|
|
|
it('still gets the correct derived information', () => {
|
|
|
|
expect(getDerivedMergeRequestInformation({ endpoint })).toMatchObject(derivedBaseInfo);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each`
|
|
|
|
url | versionPart
|
|
|
|
${endpoint} | ${derivedVersionInfo}
|
|
|
|
${`${bare}?diff_id=${derivedVersionInfo.diffId}`} | ${{ ...derivedVersionInfo, startSha: undefined }}
|
|
|
|
${`${bare}?start_sha=${derivedVersionInfo.startSha}`} | ${{ ...derivedVersionInfo, diffId: undefined }}
|
|
|
|
`(
|
|
|
|
'generates the correct derived version information based on $url',
|
|
|
|
({ url, versionPart }) => {
|
|
|
|
expect(getDerivedMergeRequestInformation({ endpoint: url })).toMatchObject(versionPart);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it('extracts nothing if there is no available version-like information in the URL', () => {
|
|
|
|
expect(getDerivedMergeRequestInformation({ endpoint: bare })).toMatchObject(noVersion);
|
|
|
|
});
|
|
|
|
});
|
2021-03-08 18:12:59 +05:30
|
|
|
});
|
|
|
|
});
|