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

npm_registry_spec.rb « 5_package « browser_ui « features « specs « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 97df8fedf8772584e672641ca12e974060d13e12 (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
# frozen_string_literal: true

module QA
  RSpec.describe 'Package', :orchestrated, :packages do
    describe 'npm registry' do
      include Runtime::Fixtures

      let(:registry_scope) { project.group.sandbox.path }
      let(:package_name) { "@#{registry_scope}/#{project.name}" }
      let(:auth_token) do
        unless Page::Main::Menu.perform(&:signed_in?)
          Flow::Login.sign_in
        end

        Resource::PersonalAccessToken.fabricate!.token
      end

      let(:project) do
        Resource::Project.fabricate_via_api! do |project|
          project.name = 'npm-registry-project'
        end
      end

      it 'publishes an npm package and then deletes it', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/944' do
        uri = URI.parse(Runtime::Scenario.gitlab_address)
        gitlab_host_with_port = "#{uri.host}:#{uri.port}"
        gitlab_address_with_port = "#{uri.scheme}://#{uri.host}:#{uri.port}"
        package_json = {
          file_path: 'package.json',
          content: <<~JSON
            {
              "name": "#{package_name}",
              "version": "1.0.0",
              "description": "Example package for GitLab npm registry",
              "publishConfig": {
                "@#{registry_scope}:registry": "#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/npm/"
              }
            }
          JSON
        }
        npmrc = {
          file_path: '.npmrc',
          content: <<~NPMRC
            //#{gitlab_host_with_port}/api/v4/projects/#{project.id}/packages/npm/:_authToken=#{auth_token}
            //#{gitlab_host_with_port}/api/v4/packages/npm/:_authToken=#{auth_token}
            @#{registry_scope}:registry=#{gitlab_address_with_port}/api/v4/packages/npm/
          NPMRC
        }

        # Use a node docker container to publish the package
        with_fixtures([npmrc, package_json]) do |dir|
          Service::DockerRun::NodeJs.new(dir).publish!
        end

        project.visit!
        Page::Project::Menu.perform(&:click_packages_link)

        Page::Project::Packages::Index.perform do |index|
          expect(index).to have_package(package_name)

          index.click_package(package_name)
        end

        Page::Project::Packages::Show.perform do |show|
          expect(show).to have_package_info(package_name, "1.0.0")

          show.click_delete
        end

        Page::Project::Packages::Index.perform do |index|
          expect(index).to have_content("Package deleted successfully")
          expect(index).not_to have_package(package_name)
        end
      end
    end
  end
end