Commit ee4a7e56 authored by Stan Hu's avatar Stan Hu

Merge branch 'npm_api_event_tracking' into 'master'

Add event tracking to NPM package API

See merge request gitlab-org/gitlab!23117
parents 17edb2ba ba19b4c2
......@@ -144,6 +144,8 @@ module API
package_file = ::Packages::PackageFileFinder
.new(package, params[:file_name]).execute!
track_event('pull_package')
present_carrierwave_file!(package_file.file)
end
......@@ -158,6 +160,8 @@ module API
put ':id/packages/npm/:package_name', requirements: NPM_ENDPOINT_REQUIREMENTS do
authorize_create_package!(user_project)
track_event('push_package')
created_package = ::Packages::Npm::CreatePackageService
.new(user_project, current_user, params.merge(build: current_authenticated_job)).execute
......
......@@ -133,12 +133,16 @@ describe API::NpmPackages do
end
context 'a public project' do
subject { get_file(package_file) }
it 'returns the file with no token needed' do
get_file(package_file)
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
end
it_behaves_like 'a gitlab tracking event', described_class.name, 'pull_package'
end
context 'private project' do
......@@ -230,13 +234,19 @@ describe API::NpmPackages do
let(:package_name) { "@#{group.path}/my_package_name" }
let(:params) { upload_params(package_name) }
it 'creates npm package with file with access token' do
expect { upload_package_with_token(package_name, params) }
.to change { project.packages.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
.and change { Packages::Tag.count }.by(1)
context 'with access token' do
subject { upload_package_with_token(package_name, params) }
expect(response).to have_gitlab_http_status(200)
it_behaves_like 'a gitlab tracking event', described_class.name, 'push_package'
it 'creates npm package with file' do
expect { subject }
.to change { project.packages.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
.and change { Packages::Tag.count }.by(1)
expect(response).to have_gitlab_http_status(200)
end
end
it 'creates npm package with file with job token' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment