summaryrefslogtreecommitdiff
path: root/qa/qa/resource/design.rb
blob: 4a3214f3c0e41cd28ea2af9234a8cd8344cb2122 (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
# frozen_string_literal: true

module QA
  module Resource
    class Design < Base
      attribute :issue do
        Issue.fabricate_via_api!
      end

      attributes :id,
                 :filename,
                 :full_path,
                 :image

      def initialize
        @update = false
        @filename = 'banana_sample.gif'
      end

      def fabricate!
        issue.visit!

        Page::Project::Issue::Show.perform do |issue|
          issue.add_design(filepath)
        end
      end

      def api_get_path
        '/graphql'
      end

      alias_method :api_post_path, :api_get_path

      # Fetch design
      #
      # @return [Hash]
      def api_get
        process_api_response(
          api_post_to(
            api_get_path,
            <<~GQL
                query {
                  issue(id: "gid://gitlab/Issue/#{issue.id}") {
                    designCollection {
                      design(filename: "#{filename}") {
                        id
                        fullPath
                        image
                        filename
                      }
                    }
                  }
                }
            GQL
          )
        )
      end

      # Graphql mutation for design creation
      #
      # @return [String]
      def api_post_body
        # TODO: design creation requires file upload via multipart/form-data request type with file passed in mutation
        # which currently isn't supported by our api implementation
        # https://gitlab.com/gitlab-org/gitlab/-/issues/366592
        raise NotImplementedError, "File uploads are not supported"
      end

      private

      def filepath
        ::File.absolute_path(::File.join('qa', 'fixtures', 'designs', filename))
      end
    end
  end
end