Welcome to mirror list, hosted at ThFree Co, Russian Federation.

graphql_add_design_spec.rb « file_uploads « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0b61c952b55e464ad5e8d71fedf1a159f683899f (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Upload a design through graphQL', :js, feature_category: :design_management do
  include_context 'file upload requests helpers'

  let_it_be(:query) do
    "
      mutation uploadDesign($files: [Upload!]!, $projectPath: ID!, $iid: ID!) {
        designManagementUpload(input: { projectPath: $projectPath, iid: $iid, files: $files}) {
          clientMutationId,
          errors
        }
      }
    "
  end

  let_it_be(:user) { create(:user, :admin) }
  let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
  let_it_be(:design) { create(:design) }
  let_it_be(:map) { { "1": ["variables.files.0"] }.to_json }
  let_it_be(:operations) do
    {
      "operationName": "uploadDesign",
      "variables": {
        "files": [nil],
        "projectPath": design.project.full_path,
        "iid": design.issue.iid
      },
      "query": query
    }.to_json
  end

  let(:url) { capybara_url("/api/graphql?private_token=#{personal_access_token.token}") }
  let(:file) { fixture_file_upload('spec/fixtures/dk.png') }

  subject do
    HTTParty.post(
      url,
      body: {
        operations: operations,
        map: map,
        "1": file
      }
    )
  end

  before do
    stub_lfs_setting(enabled: true)
  end

  RSpec.shared_examples 'for a design upload through graphQL' do
    it 'creates proper objects' do
      expect { subject }
        .to change { ::DesignManagement::Design.count }.by(1)
        .and change { ::LfsObject.count }.by(1)
    end

    it { expect(subject.code).to eq(200) }
  end

  it_behaves_like 'handling file uploads', 'for a design upload through graphQL'
end