summaryrefslogtreecommitdiff
path: root/qa/qa/factory/resource/project.rb
blob: f691ae5a342ab8ac7b3f33bae4f5d3b3d9c87949 (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
require 'securerandom'

module QA
  module Factory
    module Resource
      class Project < Factory::Base
        attribute :name
        attribute :description

        attribute :group do
          Factory::Resource::Group.fabricate!
        end

        attribute :repository_ssh_location do
          Page::Project::Show.perform do |page|
            page.choose_repository_clone_ssh
            page.repository_location
          end
        end

        attribute :repository_http_location do
          Page::Project::Show.perform do |page|
            page.choose_repository_clone_http
            page.repository_location
          end
        end

        def initialize
          @description = 'My awesome project'
        end

        def name=(raw_name)
          @name = "#{raw_name}-#{SecureRandom.hex(8)}"
        end

        def fabricate!
          group.visit!

          Page::Group::Show.perform(&:go_to_new_project)

          Page::Project::New.perform do |page|
            page.choose_test_namespace
            page.choose_name(@name)
            page.add_description(@description)
            page.set_visibility('Public')
            page.create_new_project
          end
        end

        def api_get_path
          "/projects/#{name}"
        end

        def api_post_path
          '/projects'
        end

        def api_post_body
          {
            namespace_id: group.id,
            path: name,
            name: name,
            description: description,
            visibility: 'public'
          }
        end

        private

        def transform_api_resource(resource)
          resource[:repository_ssh_location] = Git::Location.new(resource[:ssh_url_to_repo])
          resource[:repository_http_location] = Git::Location.new(resource[:http_url_to_repo])
          resource
        end
      end
    end
  end
end