2020-11-24 15:15:51 +05:30
|
|
|
import { cloneDeep } from 'lodash';
|
2021-01-03 14:25:43 +05:30
|
|
|
import { getJSONFixture } from 'helpers/fixtures';
|
|
|
|
import {
|
|
|
|
convertGraphQLRelease,
|
|
|
|
convertAllReleasesGraphQLResponse,
|
|
|
|
convertOneReleaseGraphQLResponse,
|
|
|
|
} from '~/releases/util';
|
|
|
|
|
|
|
|
const originalAllReleasesQueryResponse = getJSONFixture(
|
2021-06-08 01:23:25 +05:30
|
|
|
'graphql/releases/graphql/queries/all_releases.query.graphql.json',
|
2021-01-03 14:25:43 +05:30
|
|
|
);
|
|
|
|
const originalOneReleaseQueryResponse = getJSONFixture(
|
2021-06-08 01:23:25 +05:30
|
|
|
'graphql/releases/graphql/queries/one_release.query.graphql.json',
|
|
|
|
);
|
|
|
|
const originalOneReleaseForEditingQueryResponse = getJSONFixture(
|
|
|
|
'graphql/releases/graphql/queries/one_release_for_editing.query.graphql.json',
|
2021-01-03 14:25:43 +05:30
|
|
|
);
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
describe('releases/util.js', () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
describe('convertGraphQLRelease', () => {
|
|
|
|
let releaseFromResponse;
|
|
|
|
let convertedRelease;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-03 14:25:43 +05:30
|
|
|
releaseFromResponse = cloneDeep(originalOneReleaseQueryResponse).data.project.release;
|
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('assets', () => {
|
|
|
|
it("handles asset links that don't have a linkType", () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(convertedRelease.assets.links[0].linkType).not.toBeUndefined();
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
delete releaseFromResponse.assets.links.nodes[0].linkType;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(convertedRelease.assets.links[0].linkType).toBeUndefined();
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
it('handles assets that have no links', () => {
|
|
|
|
expect(convertedRelease.assets.links[0]).not.toBeUndefined();
|
|
|
|
|
|
|
|
delete releaseFromResponse.assets.links;
|
|
|
|
|
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
|
|
|
|
|
|
|
expect(convertedRelease.assets.links).toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles assets that have no sources', () => {
|
|
|
|
expect(convertedRelease.assets.sources[0]).not.toBeUndefined();
|
|
|
|
|
|
|
|
delete releaseFromResponse.assets.sources;
|
|
|
|
|
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
|
|
|
|
|
|
|
expect(convertedRelease.assets.sources).toEqual([]);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('_links', () => {
|
|
|
|
it("handles releases that don't have any links", () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(convertedRelease._links.selfUrl).not.toBeUndefined();
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
delete releaseFromResponse.links;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(convertedRelease._links.selfUrl).toBeUndefined();
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('commit', () => {
|
|
|
|
it("handles releases that don't have any commit info", () => {
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(convertedRelease.commit).not.toBeUndefined();
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
delete releaseFromResponse.commit;
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect(convertedRelease.commit).toBeUndefined();
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe('milestones', () => {
|
|
|
|
it("handles releases that don't have any milestone stats", () => {
|
|
|
|
expect(convertedRelease.milestones[0].issueStats).not.toBeUndefined();
|
|
|
|
|
|
|
|
releaseFromResponse.milestones.nodes = releaseFromResponse.milestones.nodes.map((n) => ({
|
|
|
|
...n,
|
|
|
|
stats: undefined,
|
|
|
|
}));
|
|
|
|
|
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
|
|
|
|
|
|
|
expect(convertedRelease.milestones[0].issueStats).toEqual({});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('evidences', () => {
|
|
|
|
it("handles releases that don't have any evidences", () => {
|
|
|
|
expect(convertedRelease.evidences).not.toBeUndefined();
|
|
|
|
|
|
|
|
delete releaseFromResponse.evidences;
|
|
|
|
|
|
|
|
convertedRelease = convertGraphQLRelease(releaseFromResponse);
|
|
|
|
|
|
|
|
expect(convertedRelease.evidences).toEqual([]);
|
|
|
|
});
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe('convertAllReleasesGraphQLResponse', () => {
|
|
|
|
it('matches snapshot', () => {
|
|
|
|
expect(convertAllReleasesGraphQLResponse(originalAllReleasesQueryResponse)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertOneReleaseGraphQLResponse', () => {
|
|
|
|
it('matches snapshot', () => {
|
|
|
|
expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
describe('convertOneReleaseForEditingGraphQLResponse', () => {
|
|
|
|
it('matches snapshot', () => {
|
|
|
|
expect(
|
|
|
|
convertOneReleaseGraphQLResponse(originalOneReleaseForEditingQueryResponse),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2020-10-24 23:57:45 +05:30
|
|
|
});
|