summaryrefslogtreecommitdiff
path: root/qa/qa/factory/resource/personal_access_token.rb
blob: cfe845214f6cab25fc69694d766129506f39c407 (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
# Create a personal access token that can be used by the api
# set the environment variable PERSONAL_ACCESS_TOKEN to use a
# specific access token rather than create one from the UI
module QA
  module Factory
    module Resource
      class PersonalAccessToken < Factory::Base
        attr_accessor :name

        product :access_token do
          Page::Profile::PersonalAccessTokens.act { created_access_token }
        end

        def fabricate!(sign_in_address = :gitlab)
          access_token = Runtime::Env.personal_access_token
          return if access_token

          if sign_in_address
            Runtime::Browser.visit(sign_in_address, Page::Main::Login)
            Page::Main::Login.act { sign_in_using_credentials }
          end

          Page::Menu::Main.act { go_to_profile_settings }
          Page::Menu::Profile.act { click_access_tokens }

          Page::Profile::PersonalAccessTokens.perform do |page|
            page.fill_token_name(name || 'api-test-token')
            page.check_api
            page.create_token
          end
        end
      end
    end
  end
end