Commit 681b20c7 authored by Nathan Friend's avatar Nathan Friend Committed by Jacques Erasmus

Update frontend tests to use GraphQL fixture

This commit updates all release-related frontend tests to use a GraphQL
fixture instead of hard-coded data in mock_data.js.
parent d1260af4
...@@ -6,11 +6,13 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -6,11 +6,13 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
include ApiHelpers include ApiHelpers
include JavaScriptFixturesHelpers include JavaScriptFixturesHelpers
let_it_be(:admin) { create(:admin) } let_it_be(:admin) { create(:admin, username: 'administrator', email: 'admin@example.gitlab.com') }
let_it_be(:project) { create(:project, :repository, path: 'releases-project') } let_it_be(:namespace) { create(:namespace, path: 'releases-namespace') }
let_it_be(:project) { create(:project, :repository, namespace: namespace, path: 'releases-project') }
let_it_be(:milestone_12_3) do let_it_be(:milestone_12_3) do
create(:milestone, create(:milestone,
id: 123,
project: project, project: project,
title: '12.3', title: '12.3',
description: 'The 12.3 milestone', description: 'The 12.3 milestone',
...@@ -20,6 +22,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -20,6 +22,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
let_it_be(:milestone_12_4) do let_it_be(:milestone_12_4) do
create(:milestone, create(:milestone,
id: 124,
project: project, project: project,
title: '12.4', title: '12.4',
description: 'The 12.4 milestone', description: 'The 12.4 milestone',
...@@ -45,18 +48,25 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -45,18 +48,25 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
let_it_be(:release) do let_it_be(:release) do
create(:release, create(:release,
:with_evidence,
milestones: [milestone_12_3, milestone_12_4], milestones: [milestone_12_3, milestone_12_4],
project: project, project: project,
tag: 'v1.1', tag: 'v1.1',
name: 'The first release', name: 'The first release',
author: admin,
description: 'Best. Release. **Ever.** :rocket:', description: 'Best. Release. **Ever.** :rocket:',
created_at: Time.zone.parse('2018-12-3'), created_at: Time.zone.parse('2018-12-3'),
released_at: Time.zone.parse('2018-12-10')) released_at: Time.zone.parse('2018-12-10'))
end end
let_it_be(:evidence) do
create(:evidence,
release: release,
collected_at: Time.zone.parse('2018-12-03'))
end
let_it_be(:other_link) do let_it_be(:other_link) do
create(:release_link, create(:release_link,
id: 10,
release: release, release: release,
name: 'linux-amd64 binaries', name: 'linux-amd64 binaries',
filepath: '/binaries/linux-amd64', filepath: '/binaries/linux-amd64',
...@@ -65,6 +75,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -65,6 +75,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
let_it_be(:runbook_link) do let_it_be(:runbook_link) do
create(:release_link, create(:release_link,
id: 11,
release: release, release: release,
name: 'Runbook', name: 'Runbook',
url: "#{release.project.web_url}/runbook", url: "#{release.project.web_url}/runbook",
...@@ -73,6 +84,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -73,6 +84,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
let_it_be(:package_link) do let_it_be(:package_link) do
create(:release_link, create(:release_link,
id: 12,
release: release, release: release,
name: 'Package', name: 'Package',
url: 'https://example.com/package', url: 'https://example.com/package',
...@@ -81,6 +93,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -81,6 +93,7 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
let_it_be(:image_link) do let_it_be(:image_link) do
create(:release_link, create(:release_link,
id: 13,
release: release, release: release,
name: 'Image', name: 'Image',
url: 'https://example.com/image', url: 'https://example.com/image',
......
...@@ -5,115 +5,123 @@ Object { ...@@ -5,115 +5,123 @@ Object {
"data": Array [ "data": Array [
Object { Object {
"_links": Object { "_links": Object {
"editUrl": "http://0.0.0.0:3000/root/release-test/-/releases/v5.10/edit", "editUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1/edit",
"issuesUrl": null, "issuesUrl": "http://localhost/releases-namespace/releases-project/-/issues?release_tag=v1.1&scope=all&state=opened",
"mergeRequestsUrl": null, "mergeRequestsUrl": "http://localhost/releases-namespace/releases-project/-/merge_requests?release_tag=v1.1&scope=all&state=opened",
"self": "http://0.0.0.0:3000/root/release-test/-/releases/v5.10", "self": "http://localhost/releases-namespace/releases-project/-/releases/v1.1",
"selfUrl": "http://0.0.0.0:3000/root/release-test/-/releases/v5.10", "selfUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1",
}, },
"assets": Object { "assets": Object {
"count": 7, "count": 8,
"links": Array [ "links": Array [
Object { Object {
"directAssetUrl": "http://0.0.0.0:3000/root/release-test/-/releases/v5.32/permanent/path/to/runbook", "directAssetUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1/binaries/awesome-app-3",
"external": true, "external": true,
"id": "gid://gitlab/Releases::Link/69", "id": "gid://gitlab/Releases::Link/13",
"linkType": "other", "linkType": "image",
"name": "An example link", "name": "Image",
"url": "https://example.com/link", "url": "https://example.com/image",
}, },
Object { Object {
"directAssetUrl": "https://example.com/package", "directAssetUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1/binaries/awesome-app-2",
"external": true, "external": true,
"id": "gid://gitlab/Releases::Link/68", "id": "gid://gitlab/Releases::Link/12",
"linkType": "package", "linkType": "package",
"name": "An example package link", "name": "Package",
"url": "https://example.com/package", "url": "https://example.com/package",
}, },
Object { Object {
"directAssetUrl": "https://example.com/image", "directAssetUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1/binaries/awesome-app-1",
"external": false,
"id": "gid://gitlab/Releases::Link/11",
"linkType": "runbook",
"name": "Runbook",
"url": "http://localhost/releases-namespace/releases-project/runbook",
},
Object {
"directAssetUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1/binaries/linux-amd64",
"external": true, "external": true,
"id": "gid://gitlab/Releases::Link/67", "id": "gid://gitlab/Releases::Link/10",
"linkType": "image", "linkType": "other",
"name": "An example image", "name": "linux-amd64 binaries",
"url": "https://example.com/image", "url": "https://downloads.example.com/bin/gitlab-linux-amd64",
}, },
], ],
"sources": Array [ "sources": Array [
Object { Object {
"format": "zip", "format": "zip",
"url": "http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.zip", "url": "http://localhost/releases-namespace/releases-project/-/archive/v1.1/releases-project-v1.1.zip",
}, },
Object { Object {
"format": "tar.gz", "format": "tar.gz",
"url": "http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.tar.gz", "url": "http://localhost/releases-namespace/releases-project/-/archive/v1.1/releases-project-v1.1.tar.gz",
}, },
Object { Object {
"format": "tar.bz2", "format": "tar.bz2",
"url": "http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.tar.bz2", "url": "http://localhost/releases-namespace/releases-project/-/archive/v1.1/releases-project-v1.1.tar.bz2",
}, },
Object { Object {
"format": "tar", "format": "tar",
"url": "http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.tar", "url": "http://localhost/releases-namespace/releases-project/-/archive/v1.1/releases-project-v1.1.tar",
}, },
], ],
}, },
"author": Object { "author": Object {
"avatarUrl": "/uploads/-/system/user/avatar/1/avatar.png", "avatarUrl": "https://www.gravatar.com/avatar/16f8e2050ce10180ca571c2eb19cfce2?s=80&d=identicon",
"username": "root", "username": "administrator",
"webUrl": "http://0.0.0.0:3000/root", "webUrl": "http://localhost/administrator",
}, },
"commit": Object { "commit": Object {
"shortId": "92e7ea2e", "shortId": "b83d6e39",
"title": "Testing a change.", "title": "Merge branch 'branch-merged' into 'master'",
}, },
"commitPath": "http://0.0.0.0:3000/root/release-test/-/commit/92e7ea2ee4496fe0d00ff69830ba0564d3d1e5a7", "commitPath": "http://localhost/releases-namespace/releases-project/-/commit/b83d6e391c22777fca1ed3012fce84f633d7fed0",
"descriptionHtml": "<p data-sourcepos=\\"1:1-1:24\\" dir=\\"auto\\">This is version <strong>1.0</strong>!</p>", "descriptionHtml": "<p data-sourcepos=\\"1:1-1:33\\" dir=\\"auto\\">Best. Release. <strong>Ever.</strong> <gl-emoji title=\\"rocket\\" data-name=\\"rocket\\" data-unicode-version=\\"6.0\\">🚀</gl-emoji></p>",
"evidences": Array [ "evidences": Array [
Object { Object {
"collectedAt": "2020-08-21T20:15:19Z", "collectedAt": "2018-12-03T00:00:00Z",
"filepath": "http://0.0.0.0:3000/root/release-test/-/releases/v5.10/evidences/34.json", "filepath": "http://localhost/releases-namespace/releases-project/-/releases/v1.1/evidences/1.json",
"sha": "22bde8e8b93d870a29ddc339287a1fbb598f45d1396d", "sha": "760d6cdfb0879c3ffedec13af470e0f71cf52c6cde4d",
}, },
], ],
"milestones": Array [ "milestones": Array [
Object { Object {
"description": "", "description": "The 12.4 milestone",
"id": "gid://gitlab/Milestone/60", "id": "gid://gitlab/Milestone/124",
"issueStats": Object { "issueStats": Object {
"closed": 0, "closed": 1,
"total": 0, "total": 4,
}, },
"stats": undefined, "stats": undefined,
"title": "12.4", "title": "12.4",
"webPath": undefined, "webPath": undefined,
"webUrl": "/root/release-test/-/milestones/2", "webUrl": "/releases-namespace/releases-project/-/milestones/2",
}, },
Object { Object {
"description": "Milestone 12.3", "description": "The 12.3 milestone",
"id": "gid://gitlab/Milestone/59", "id": "gid://gitlab/Milestone/123",
"issueStats": Object { "issueStats": Object {
"closed": 1, "closed": 3,
"total": 2, "total": 5,
}, },
"stats": undefined, "stats": undefined,
"title": "12.3", "title": "12.3",
"webPath": undefined, "webPath": undefined,
"webUrl": "/root/release-test/-/milestones/1", "webUrl": "/releases-namespace/releases-project/-/milestones/1",
}, },
], ],
"name": "Release 1.0", "name": "The first release",
"releasedAt": "2020-08-21T20:15:18Z", "releasedAt": "2018-12-10T00:00:00Z",
"tagName": "v5.10", "tagName": "v1.1",
"tagPath": "/root/release-test/-/tags/v5.10", "tagPath": "/releases-namespace/releases-project/-/tags/v1.1",
"upcomingRelease": false, "upcomingRelease": true,
}, },
], ],
"paginationInfo": Object { "paginationInfo": Object {
"endCursor": "eyJpZCI6IjMiLCJyZWxlYXNlZF9hdCI6IjIwMjAtMDctMDkgMjA6MTE6MzMuODA0OTYxMDAwIFVUQyJ9", "endCursor": "eyJpZCI6IjEiLCJyZWxlYXNlZF9hdCI6IjIwMTgtMTItMTAgMDA6MDA6MDAuMDAwMDAwMDAwIFVUQyJ9",
"hasNextPage": true, "hasNextPage": false,
"hasPreviousPage": false, "hasPreviousPage": false,
"startCursor": "eyJpZCI6IjQ0IiwicmVsZWFzZWRfYXQiOiIyMDMwLTAzLTE1IDA4OjAwOjAwLjAwMDAwMDAwMCBVVEMifQ", "startCursor": "eyJpZCI6IjEiLCJyZWxlYXNlZF9hdCI6IjIwMTgtMTItMTAgMDA6MDA6MDAuMDAwMDAwMDAwIFVUQyJ9",
}, },
} }
`; `;
...@@ -15,139 +15,3 @@ export const pageInfoHeadersWithPagination = { ...@@ -15,139 +15,3 @@ export const pageInfoHeadersWithPagination = {
'X-TOTAL': '21', 'X-TOTAL': '21',
'X-TOTAL-PAGES': '2', 'X-TOTAL-PAGES': '2',
}; };
export const graphqlReleasesResponse = {
data: {
project: {
releases: {
count: 39,
nodes: [
{
name: 'Release 1.0',
tagName: 'v5.10',
tagPath: '/root/release-test/-/tags/v5.10',
descriptionHtml:
'<p data-sourcepos="1:1-1:24" dir="auto">This is version <strong>1.0</strong>!</p>',
releasedAt: '2020-08-21T20:15:18Z',
upcomingRelease: false,
assets: {
count: 7,
sources: {
nodes: [
{
format: 'zip',
url:
'http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.zip',
},
{
format: 'tar.gz',
url:
'http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.tar.gz',
},
{
format: 'tar.bz2',
url:
'http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.tar.bz2',
},
{
format: 'tar',
url:
'http://0.0.0.0:3000/root/release-test/-/archive/v5.10/release-test-v5.10.tar',
},
],
},
links: {
nodes: [
{
id: 'gid://gitlab/Releases::Link/69',
name: 'An example link',
url: 'https://example.com/link',
directAssetUrl:
'http://0.0.0.0:3000/root/release-test/-/releases/v5.32/permanent/path/to/runbook',
linkType: 'OTHER',
external: true,
},
{
id: 'gid://gitlab/Releases::Link/68',
name: 'An example package link',
url: 'https://example.com/package',
directAssetUrl: 'https://example.com/package',
linkType: 'PACKAGE',
external: true,
},
{
id: 'gid://gitlab/Releases::Link/67',
name: 'An example image',
url: 'https://example.com/image',
directAssetUrl: 'https://example.com/image',
linkType: 'IMAGE',
external: true,
},
],
},
},
evidences: {
nodes: [
{
filepath:
'http://0.0.0.0:3000/root/release-test/-/releases/v5.10/evidences/34.json',
collectedAt: '2020-08-21T20:15:19Z',
sha: '22bde8e8b93d870a29ddc339287a1fbb598f45d1396d',
},
],
},
links: {
editUrl: 'http://0.0.0.0:3000/root/release-test/-/releases/v5.10/edit',
issuesUrl: null,
mergeRequestsUrl: null,
selfUrl: 'http://0.0.0.0:3000/root/release-test/-/releases/v5.10',
},
commit: {
sha: '92e7ea2ee4496fe0d00ff69830ba0564d3d1e5a7',
webUrl:
'http://0.0.0.0:3000/root/release-test/-/commit/92e7ea2ee4496fe0d00ff69830ba0564d3d1e5a7',
title: 'Testing a change.',
},
author: {
webUrl: 'http://0.0.0.0:3000/root',
avatarUrl: '/uploads/-/system/user/avatar/1/avatar.png',
username: 'root',
},
milestones: {
nodes: [
{
id: 'gid://gitlab/Milestone/60',
title: '12.4',
description: '',
webPath: '/root/release-test/-/milestones/2',
stats: {
totalIssuesCount: 0,
closedIssuesCount: 0,
},
},
{
id: 'gid://gitlab/Milestone/59',
title: '12.3',
description: 'Milestone 12.3',
webPath: '/root/release-test/-/milestones/1',
stats: {
totalIssuesCount: 2,
closedIssuesCount: 1,
},
},
],
},
},
],
pageInfo: {
startCursor:
'eyJpZCI6IjQ0IiwicmVsZWFzZWRfYXQiOiIyMDMwLTAzLTE1IDA4OjAwOjAwLjAwMDAwMDAwMCBVVEMifQ',
hasPreviousPage: false,
hasNextPage: true,
endCursor:
'eyJpZCI6IjMiLCJyZWxlYXNlZF9hdCI6IjIwMjAtMDctMDkgMjA6MTE6MzMuODA0OTYxMDAwIFVUQyJ9',
},
},
},
},
};
...@@ -16,16 +16,17 @@ import { ...@@ -16,16 +16,17 @@ import {
parseIntPagination, parseIntPagination,
convertObjectPropsToCamelCase, convertObjectPropsToCamelCase,
} from '~/lib/utils/common_utils'; } from '~/lib/utils/common_utils';
import { import { pageInfoHeadersWithoutPagination } from '../../../mock_data';
pageInfoHeadersWithoutPagination,
graphqlReleasesResponse as originalGraphqlReleasesResponse,
} from '../../../mock_data';
import allReleasesQuery from '~/releases/queries/all_releases.query.graphql'; import allReleasesQuery from '~/releases/queries/all_releases.query.graphql';
import { PAGE_SIZE } from '~/releases/constants'; import { PAGE_SIZE } from '~/releases/constants';
const originalRelease = getJSONFixture('api/releases/release.json'); const originalRelease = getJSONFixture('api/releases/release.json');
const originalReleases = [originalRelease]; const originalReleases = [originalRelease];
const originalGraphqlReleasesResponse = getJSONFixture(
'graphql/releases/queries/all_releases.query.graphql.json',
);
describe('Releases State actions', () => { describe('Releases State actions', () => {
let mockedState; let mockedState;
let releases; let releases;
......
...@@ -3,12 +3,16 @@ import createState from '~/releases/stores/modules/list/state'; ...@@ -3,12 +3,16 @@ import createState from '~/releases/stores/modules/list/state';
import mutations from '~/releases/stores/modules/list/mutations'; import mutations from '~/releases/stores/modules/list/mutations';
import * as types from '~/releases/stores/modules/list/mutation_types'; import * as types from '~/releases/stores/modules/list/mutation_types';
import { parseIntPagination, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { parseIntPagination, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { pageInfoHeadersWithoutPagination, graphqlReleasesResponse } from '../../../mock_data'; import { pageInfoHeadersWithoutPagination } from '../../../mock_data';
import { convertGraphQLResponse } from '~/releases/util'; import { convertGraphQLResponse } from '~/releases/util';
const originalRelease = getJSONFixture('api/releases/release.json'); const originalRelease = getJSONFixture('api/releases/release.json');
const originalReleases = [originalRelease]; const originalReleases = [originalRelease];
const graphqlReleasesResponse = getJSONFixture(
'graphql/releases/queries/all_releases.query.graphql.json',
);
describe('Releases Store Mutations', () => { describe('Releases Store Mutations', () => {
let stateCopy; let stateCopy;
let restPageInfo; let restPageInfo;
......
import { cloneDeep } from 'lodash'; import { cloneDeep } from 'lodash';
import { getJSONFixture } from 'helpers/fixtures';
import { releaseToApiJson, apiJsonToRelease, convertGraphQLResponse } from '~/releases/util'; import { releaseToApiJson, apiJsonToRelease, convertGraphQLResponse } from '~/releases/util';
import { graphqlReleasesResponse as originalGraphqlReleasesResponse } from './mock_data';
const originalGraphqlReleasesResponse = getJSONFixture(
'graphql/releases/queries/all_releases.query.graphql.json',
);
describe('releases/util.js', () => { describe('releases/util.js', () => {
describe('releaseToApiJson', () => { describe('releaseToApiJson', () => {
......
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