summaryrefslogtreecommitdiff
path: root/qa/qa/resource/wiki/group_page.rb
blob: 27150ecf6c7255a30b22a19c938d5ce30f565220 (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
# frozen_string_literal: true

require 'securerandom'

module QA
  module Resource
    module Wiki
      class GroupPage < Base
        attribute :title
        attribute :content
        attribute :slug

        attribute :group do
          Group.fabricate_via_api! do |group|
            group.path = "group-with-wiki-#{SecureRandom.hex(8)}"
          end
        end

        def initialize
          @title = 'Home'
          @content = 'This wiki page is created via API'
        end

        def resource_web_url(resource)
          super
        rescue ResourceURLMissingError
          "#{group.web_url}/-/wikis/#{slug}"
        end

        def api_get_path
          "/groups/#{group.id}/wikis/#{slug}"
        end

        def api_post_path
          "/groups/#{group.id}/wikis"
        end

        def api_post_body
          {
            id: group.id,
            content: content,
            title: title
          }
        end
      end
    end
  end
end