Commit 70558e89 authored by Stan Hu's avatar Stan Hu

Add tests for passing nil values in epics and packages

In https://gitlab.com/gitlab-org/gitlab/-/issues/215936, we found that
upgrading to Grape v1.3.2 caused a regression in our QA suite because
passing a `nil` value for an Array type would be passed in as a `nil`
value instead of being coerced to an empty Array. We had to revert the
upgrade as a result. To ensure that `nil` values are handled properly on
the backend, add tests for this.
parent 1035dddc
...@@ -38,6 +38,17 @@ describe API::Dependencies do ...@@ -38,6 +38,17 @@ describe API::Dependencies do
expect(vulnerability['severity']).to eq('unknown') expect(vulnerability['severity']).to eq('unknown')
end end
context 'with nil package_manager' do
let(:params) { { package_manager: nil } }
it 'returns no dependencies' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/dependencies', dir: 'ee')
expect(json_response).to eq([])
end
end
context 'with filter options' do context 'with filter options' do
let(:params) { { package_manager: 'yarn' } } let(:params) { { package_manager: 'yarn' } }
......
...@@ -618,6 +618,17 @@ describe API::Epics do ...@@ -618,6 +618,17 @@ describe API::Epics do
expect(json_response['labels']).to include '&' expect(json_response['labels']).to include '&'
expect(json_response['labels']).to include '?' expect(json_response['labels']).to include '?'
end end
it 'creates a new epic with no labels' do
params[:labels] = nil
post api(url, user), params: params
expect(response).to have_gitlab_http_status(:created)
expect(json_response['title']).to include 'new epic'
expect(json_response['description']).to include 'epic description'
expect(json_response['labels']).to be_empty
end
end end
end end
...@@ -705,6 +716,25 @@ describe API::Epics do ...@@ -705,6 +716,25 @@ describe API::Epics do
end end
end end
it 'clears labels when labels param is nil' do
params[:labels] = 'label1'
put api(url, user), params: params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['title']).to include 'new title'
expect(json_response['description']).to include 'new description'
expect(json_response['labels']).to contain_exactly('label1')
params[:labels] = nil
put api(url, user), params: params
expect(response).to have_gitlab_http_status(:ok)
json_response = Gitlab::Json.parse(response.body)
expect(json_response['title']).to include 'new title'
expect(json_response['description']).to include 'new description'
expect(json_response['labels']).to be_empty
end
it 'updates the epic with labels param as array' do it 'updates the epic with labels param as array' do
stub_const("Gitlab::QueryLimiting::Transaction::THRESHOLD", 110) stub_const("Gitlab::QueryLimiting::Transaction::THRESHOLD", 110)
......
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