debian-mirror-gitlab/spec/frontend/releases/util_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

160 lines
4.8 KiB
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { cloneDeep } from 'lodash';
2021-11-18 22:05:49 +05:30
import originalAllReleasesQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/all_releases.query.graphql.json';
import originalOneReleaseQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release.query.graphql.json';
import originalOneReleaseForEditingQueryResponse from 'test_fixtures/graphql/releases/graphql/queries/one_release_for_editing.query.graphql.json';
2021-01-03 14:25:43 +05:30
import {
convertGraphQLRelease,
convertAllReleasesGraphQLResponse,
convertOneReleaseGraphQLResponse,
} from '~/releases/util';
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', () => {
2022-01-26 12:08:38 +05:30
expect(convertAllReleasesGraphQLResponse(originalAllReleasesQueryResponse)).toMatchSnapshot({
data: [
{
author: {
id: expect.any(String),
},
},
{
author: {
id: expect.any(String),
},
2022-11-25 23:54:43 +05:30
evidences: [
{
id: expect.any(String),
filepath: expect.any(String),
},
],
2022-01-26 12:08:38 +05:30
},
],
2022-11-25 23:54:43 +05:30
paginationInfo: {
startCursor: expect.any(String),
endCursor: expect.any(String),
},
2022-01-26 12:08:38 +05:30
});
2021-01-03 14:25:43 +05:30
});
});
describe('convertOneReleaseGraphQLResponse', () => {
it('matches snapshot', () => {
2022-01-26 12:08:38 +05:30
expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot({
data: {
author: {
id: expect.any(String),
},
2022-11-25 23:54:43 +05:30
evidences: [
{
id: expect.any(String),
filepath: expect.any(String),
},
],
2022-01-26 12:08:38 +05:30
},
});
2021-01-03 14:25:43 +05:30
});
});
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
});