summaryrefslogtreecommitdiff
path: root/spec/frontend/fixtures/releases.rb
blob: 7ec155fcb103708981b01dae71c957c3557485c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Releases (JavaScript fixtures)' do
  include ApiHelpers
  include JavaScriptFixturesHelpers

  let_it_be(:admin) { create(:admin, username: 'administrator', email: 'admin@example.gitlab.com') }
  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
    create(:milestone,
           id: 123,
           project: project,
           title: '12.3',
           description: 'The 12.3 milestone',
           start_date: Time.zone.parse('2018-12-10'),
           due_date: Time.zone.parse('2019-01-10'))
  end

  let_it_be(:milestone_12_4) do
    create(:milestone,
           id: 124,
           project: project,
           title: '12.4',
           description: 'The 12.4 milestone',
           start_date: Time.zone.parse('2019-01-10'),
           due_date: Time.zone.parse('2019-02-10'))
  end

  let_it_be(:open_issues_12_3) do
    create_list(:issue, 2, milestone: milestone_12_3, project: project)
  end

  let_it_be(:closed_issues_12_3) do
    create_list(:issue, 3, :closed, milestone: milestone_12_3, project: project)
  end

  let_it_be(:open_issues_12_4) do
    create_list(:issue, 3, milestone: milestone_12_4, project: project)
  end

  let_it_be(:closed_issues_12_4) do
    create_list(:issue, 1, :closed, milestone: milestone_12_4, project: project)
  end

  let_it_be(:release) do
    create(:release,
           milestones: [milestone_12_3, milestone_12_4],
           project: project,
           tag: 'v1.1',
           name: 'The first release',
           author: admin,
           description: 'Best. Release. **Ever.** :rocket:',
           created_at: Time.zone.parse('2018-12-3'),
           released_at: Time.zone.parse('2018-12-10'))
  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
    create(:release_link,
           id: 10,
           release: release,
           name: 'linux-amd64 binaries',
           filepath: '/binaries/linux-amd64',
           url: 'https://downloads.example.com/bin/gitlab-linux-amd64')
  end

  let_it_be(:runbook_link) do
    create(:release_link,
           id: 11,
           release: release,
           name: 'Runbook',
           url: "#{release.project.web_url}/runbook",
           link_type: :runbook)
  end

  let_it_be(:package_link) do
    create(:release_link,
           id: 12,
           release: release,
           name: 'Package',
           url: 'https://example.com/package',
           link_type: :package)
  end

  let_it_be(:image_link) do
    create(:release_link,
           id: 13,
           release: release,
           name: 'Image',
           url: 'https://example.com/image',
           link_type: :image)
  end

  after(:all) do
    remove_repository(project)
  end

  describe API::Releases, type: :request do
    before(:all) do
      clean_frontend_fixtures('api/releases/')
    end

    it 'api/releases/release.json' do
      get api("/projects/#{project.id}/releases/#{release.tag}", admin)

      expect(response).to be_successful
    end
  end

  describe GraphQL::Query, type: :request do
    include GraphqlHelpers

    all_releases_query_path = 'releases/graphql/queries/all_releases.query.graphql'
    one_release_query_path = 'releases/graphql/queries/one_release.query.graphql'
    one_release_for_editing_query_path = 'releases/graphql/queries/one_release_for_editing.query.graphql'
    release_fragment_path = 'releases/graphql/fragments/release.fragment.graphql'
    release_for_editing_fragment_path = 'releases/graphql/fragments/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, [release_fragment_path])

      post_graphql(query, current_user: admin, variables: { fullPath: project.full_path })

      expect_graphql_errors_to_be_empty
    end

    it "graphql/#{one_release_query_path}.json" do
      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 })

      expect_graphql_errors_to_be_empty
    end
  end
end