Commit 21c3cbec authored by Nathan Friend's avatar Nathan Friend Committed by David O'Regan

All GraphQL query for release editing

This commit adds a new GraphQL query that only fetched the information
needed to edit a release. It also updates the conversion function in
`util.js` to account for these differences.
parent 5781efdb
#import "./release_for_editing.fragment.graphql"
query oneReleaseForEditing($fullPath: ID!, $tagName: String!) {
project(fullPath: $fullPath) {
release(tagName: $tagName) {
...ReleaseForEditing
}
}
}
fragment ReleaseForEditing on Release {
name
tagName
description
assets {
links {
nodes {
id
name
url
linkType
}
}
}
links {
selfUrl
}
milestones {
nodes {
title
}
}
}
......@@ -52,24 +52,37 @@ const convertScalarProperties = (graphQLRelease) =>
'name',
'tagName',
'tagPath',
'description',
'descriptionHtml',
'releasedAt',
'upcomingRelease',
]);
const convertAssets = (graphQLRelease) => ({
assets: {
count: graphQLRelease.assets.count,
sources: [...graphQLRelease.assets.sources.nodes],
links: graphQLRelease.assets.links.nodes.map((l) => ({
const convertAssets = (graphQLRelease) => {
let sources = [];
if (graphQLRelease.assets.sources?.nodes) {
sources = [...graphQLRelease.assets.sources.nodes];
}
let links = [];
if (graphQLRelease.assets.links?.nodes) {
links = graphQLRelease.assets.links.nodes.map((l) => ({
...l,
linkType: l.linkType?.toLowerCase(),
})),
},
});
}));
}
return {
assets: {
count: graphQLRelease.assets.count,
sources,
links,
},
};
};
const convertEvidences = (graphQLRelease) => ({
evidences: graphQLRelease.evidences.nodes.map((e) => e),
evidences: (graphQLRelease.evidences?.nodes ?? []).map((e) => ({ ...e })),
});
const convertLinks = (graphQLRelease) => ({
......@@ -100,10 +113,12 @@ const convertMilestones = (graphQLRelease) => ({
...m,
webUrl: m.webPath,
webPath: undefined,
issueStats: {
total: m.stats.totalIssuesCount,
closed: m.stats.closedIssuesCount,
},
issueStats: m.stats
? {
total: m.stats.totalIssuesCount,
closed: m.stats.closedIssuesCount,
}
: {},
stats: undefined,
})),
});
......
......@@ -121,14 +121,16 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
all_releases_query_path = 'releases/queries/all_releases.query.graphql'
one_release_query_path = 'releases/queries/one_release.query.graphql'
fragment_paths = ['releases/queries/release.fragment.graphql']
one_release_for_editing_query_path = 'releases/queries/one_release_for_editing.query.graphql'
release_fragment_path = 'releases/queries/release.fragment.graphql'
release_for_editing_fragment_path = 'releases/queries/release_for_editing.fragment.graphql'
before(:all) do
clean_frontend_fixtures('graphql/releases/')
end
it "graphql/#{all_releases_query_path}.json" do
query = get_graphql_query_as_string(all_releases_query_path, fragment_paths)
query = get_graphql_query_as_string(all_releases_query_path, [release_fragment_path])
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path })
......@@ -136,7 +138,15 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
end
it "graphql/#{one_release_query_path}.json" do
query = get_graphql_query_as_string(one_release_query_path, fragment_paths)
query = get_graphql_query_as_string(one_release_query_path, [release_fragment_path])
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag })
expect_graphql_errors_to_be_empty
end
it "graphql/#{one_release_for_editing_query_path}.json" do
query = get_graphql_query_as_string(one_release_for_editing_query_path, [release_for_editing_fragment_path])
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag })
......
......@@ -129,6 +129,68 @@ Object {
}
`;
exports[`releases/util.js convertOneReleaseForEditingGraphQLResponse matches snapshot 1`] = `
Object {
"data": Object {
"_links": Object {
"self": "http://localhost/releases-namespace/releases-project/-/releases/v1.1",
"selfUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1",
},
"assets": Object {
"count": undefined,
"links": Array [
Object {
"id": "gid://gitlab/Releases::Link/13",
"linkType": "image",
"name": "Image",
"url": "https://example.com/image",
},
Object {
"id": "gid://gitlab/Releases::Link/12",
"linkType": "package",
"name": "Package",
"url": "https://example.com/package",
},
Object {
"id": "gid://gitlab/Releases::Link/11",
"linkType": "runbook",
"name": "Runbook",
"url": "http://localhost/releases-namespace/releases-project/runbook",
},
Object {
"id": "gid://gitlab/Releases::Link/10",
"linkType": "other",
"name": "linux-amd64 binaries",
"url": "https://downloads.example.com/bin/gitlab-linux-amd64",
},
],
"sources": Array [],
},
"author": undefined,
"description": "Best. Release. **Ever.** :rocket:",
"evidences": Array [],
"milestones": Array [
Object {
"issueStats": Object {},
"stats": undefined,
"title": "12.3",
"webPath": undefined,
"webUrl": undefined,
},
Object {
"issueStats": Object {},
"stats": undefined,
"title": "12.4",
"webPath": undefined,
"webUrl": undefined,
},
],
"name": "The first release",
"tagName": "v1.1",
},
}
`;
exports[`releases/util.js convertOneReleaseGraphQLResponse matches snapshot 1`] = `
Object {
"data": Object {
......
......@@ -14,6 +14,9 @@ const originalAllReleasesQueryResponse = getJSONFixture(
const originalOneReleaseQueryResponse = getJSONFixture(
'graphql/releases/queries/one_release.query.graphql.json',
);
const originalOneReleaseForEditingQueryResponse = getJSONFixture(
'graphql/releases/queries/one_release_for_editing.query.graphql.json',
);
describe('releases/util.js', () => {
describe('releaseToApiJson', () => {
......@@ -135,6 +138,26 @@ describe('releases/util.js', () => {
expect(convertedRelease.assets.links[0].linkType).toBeUndefined();
});
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([]);
});
});
describe('_links', () => {
......@@ -160,6 +183,33 @@ describe('releases/util.js', () => {
expect(convertedRelease.commit).toBeUndefined();
});
});
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([]);
});
});
});
describe('convertAllReleasesGraphQLResponse', () => {
......@@ -173,4 +223,12 @@ describe('releases/util.js', () => {
expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot();
});
});
describe('convertOneReleaseForEditingGraphQLResponse', () => {
it('matches snapshot', () => {
expect(
convertOneReleaseGraphQLResponse(originalOneReleaseForEditingQueryResponse),
).toMatchSnapshot();
});
});
});
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